Subversion Repositories basico

Rev

Rev 262 | Rev 266 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 t00mlabs 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
264 t00m 3
"""
251 t00m 4
# File: srv_cb.py
4 t00mlabs 5
# Author: Tomás Vírseda
6
# License: GPL v3
7
# Description: UI and related callbacks service
264 t00m 8
"""
4 t00mlabs 9
 
10
import os
11
import json
74 t00mlabs 12
import time
243 t00m 13
from concurrent.futures import ThreadPoolExecutor as Executor
4 t00mlabs 14
 
15
import gi
16
gi.require_version('Gtk', '3.0')
17
from gi.repository import Gtk
18
 
243 t00m 19
from basico.core.mod_srv import Service
20
from basico.core.mod_env import FILE, LPATH
254 t00m 21
from basico.widgets.wdg_visor_sapnotes import SAPNotesVisor
22
from basico.widgets.wdg_visor_toolbar import VisorToolbar
243 t00m 23
from basico.widgets.wdg_cols import CollectionsMgtView
24
from basico.widgets.wdg_settingsview import SettingsView
150 t00m 25
 
74 t00mlabs 26
# PROPKEYS = CSV headers. SAP Note metadata
27
PROPKEYS = ['id', 'title', 'type', 'componentkey',
28
            'componenttxt', 'category', 'priority', 'releaseon',
29
            'language', 'version']
30
 
31
# Extend PROPKEYS with custom basico metadata
149 t00m 32
PROPKEYS.extend (['Bookmark'])
74 t00mlabs 33
 
4 t00mlabs 34
class Callback(Service):
35
    def initialize(self):
36
        self.get_services()
37
 
38
    def get_services(self):
247 t00m 39
        self.srvstg = self.app.get_service('Settings')
40
        self.srvdtb = self.app.get_service('DB')
41
        self.srvgui = self.app.get_service('GUI')
42
        self.srvuif = self.app.get_service("UIF")
43
        self.srvsap = self.app.get_service('SAP')
44
        self.srvicm = self.app.get_service('IM')
45
        self.srvutl = self.app.get_service('Utils')
46
        self.srvant = self.app.get_service('Annotation')
47
        self.srvbnr = self.get_service('BNR')
4 t00mlabs 48
 
174 t00m 49
 
255 t00m 50
    def gui_visor_switch_page(self, notebook, page, page_num):
51
        # 0|1 -> SAP Notes Visor | Annotations Visor
264 t00m 52
        button = self.srvgui.get_widget('gtk_toogletoolbutton_menu_view')
255 t00m 53
        self.srvgui.set_key_value('current_visor_tab', page_num)
54
 
264 t00m 55
        if page_num == 0:
56
            button.set_active(True)
57
            self.srvuif.set_widget_visibility('gtk_label_total_notes', True)
58
        elif page_num == 1:
59
            button.set_active(False)
60
            self.srvuif.set_widget_visibility('gtk_label_total_notes', False)
255 t00m 61
 
62
 
264 t00m 63
    def gui_show_visor_sapnotes(self):
64
        notebook = self.srvgui.get_widget('gtk_notebook_visor')
65
        notebook.set_current_page(0)
66
 
67
 
201 t00m 68
    def action_search(self, entry):
255 t00m 69
        visor_sapnotes = self.srvgui.get_widget('visor_sapnotes')
70
        visor_annotations = self.srvgui.get_widget('visor_annotations')
234 t00m 71
        term = entry.get_text()
255 t00m 72
        page = self.srvgui.get_key_value('current_visor_tab')
264 t00m 73
        completion = self.srvgui.get_widget('gtk_entrycompletion_visor')
74
        completion_model = completion.get_model()
75
        completion_model.clear()
223 t00m 76
 
255 t00m 77
        if page == 0:
247 t00m 78
            bag = self.srvdtb.search(term)
255 t00m 79
            visor_sapnotes.populate_sapnotes(bag)
80
        elif page == 1:
247 t00m 81
            annotations = self.srvant.search_term(term)
255 t00m 82
            visor_annotations.populate_annotations(annotations)
201 t00m 83
 
234 t00m 84
        ebuffer = entry.get_buffer()
85
        ebuffer.delete_text(0, -1)
201 t00m 86
 
234 t00m 87
 
188 t00m 88
    def sapnote_browse(self, button, sid):
171 t00m 89
        self.debug("Browsing SAP Note %d" % int(sid))
247 t00m 90
        SAP_NOTE_URL = self.srvstg.get('SAP', 'SAP_NOTE_URL')
174 t00m 91
        url = SAP_NOTE_URL % sid
247 t00m 92
        self.srvutl.browse(url)
93
        # ~ popover = self.srvgui.get_widget('poprowsid')
225 t00m 94
        # ~ popover.hide()
171 t00m 95
 
174 t00m 96
 
212 t00m 97
    def sapnote_delete(self, button, lsid):
264 t00m 98
        visor = self.srvgui.get_widget('visor_sapnotes')
99
        viewmenu = self.srvgui.get_widget('viewmenu')
100
        model = visor.get_sorted_model()
101
        bag = []
174 t00m 102
 
264 t00m 103
        def get_selected_sapnotes(model, path, itr):
104
            checked = model.get(itr, 2)[0]
105
            if checked:
106
                sid = model.get(itr, 0)[0]
107
                bag.append(sid)
174 t00m 108
 
264 t00m 109
        model.foreach(get_selected_sapnotes)
110
        bag.sort()
111
        if len(bag) > 0:
112
            answer = self.srvuif.warning_message(button, 'Deleting SAP Notes', 'Are you sure?', bag)
113
            if answer is True:
114
                for sid in bag:
115
                    self.srvdtb.delete(sid)
116
                visor.reload()
117
            else:
118
                self.debug("Nothing deleted")
119
 
120
 
188 t00m 121
    def gui_hide_popover(self, popover):
206 t00m 122
        popover.hide()
150 t00m 123
 
187 t00m 124
 
240 t00m 125
    def gui_show_filechooser_restore(self, *args):
247 t00m 126
        window = self.srvgui.get_window()
240 t00m 127
        dialog = Gtk.FileChooserDialog("Please choose a backup file", window,
128
            Gtk.FileChooserAction.OPEN,
129
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
130
            Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
131
        dialog.set_current_folder(LPATH['BACKUP'])
241 t00m 132
        # ~ extra_widget = dialog.get_extra_widget()
240 t00m 133
        filter_zip = Gtk.FileFilter()
134
        filter_zip.set_name("Basico backup files")
135
        filter_zip.add_pattern("*.zip")
136
        dialog.add_filter(filter_zip)
241 t00m 137
        # ~ extra_widget.grab_focus()
240 t00m 138
 
139
        response = dialog.run()
140
        if response == Gtk.ResponseType.OK:
241 t00m 141
            backup = dialog.get_filename()
247 t00m 142
            sncount, ancount = self.srvbnr.test(backup)
241 t00m 143
            question = "Restoring backup %s" % os.path.basename(backup)
144
            message = "%s contains:\n\n%6d SAP Notes\n%6d annotations\n\n" % (os.path.basename(backup), sncount, ancount)
145
            message += "Do you still want to restore this backup?\n"
146
            message += "Previous database will be deleted (merge operation is not supported yet)"
247 t00m 147
            wdialog = self.srvuif.warning_message_default(question, message)
241 t00m 148
            response = wdialog.run()
149
            if response == Gtk.ResponseType.YES:
150
                answer = True
151
            elif response == Gtk.ResponseType.NO:
247 t00m 152
                self.srvbnr.restore(backup)
241 t00m 153
            self.debug("Answer: %s" % answer)
154
            wdialog.destroy()
240 t00m 155
        elif response == Gtk.ResponseType.CANCEL:
241 t00m 156
            self.debug("Aborting restore.")
240 t00m 157
 
158
        dialog.destroy()
159
 
160
 
188 t00m 161
    def gui_show_about(self, *args):
247 t00m 162
        about = self.srvgui.get_widget('widget_about')
163
        stack = self.srvgui.get_widget('gtk_stack_main')
215 t00m 164
        stack.set_visible_child_name('about')
237 t00m 165
        about.grab_focus()
230 t00m 166
        self.gui_toggle_menu_view(False)
247 t00m 167
        self.gui_hide_popover(self.srvgui.get_widget('gtk_popover_button_menu_system'))
250 t00m 168
        self.srvuif.set_widget_visibility('gtk_label_total_notes', False)
247 t00m 169
        self.srvuif.set_widget_visibility('gtk_button_dashboard', True)
133 t00mlabs 170
 
150 t00m 171
 
216 t00m 172
    def gui_show_log(self, *args):
247 t00m 173
        logviewer = self.srvgui.get_widget('widget_logviewer')
174
        stack = self.srvgui.get_widget('gtk_stack_main')
250 t00m 175
        # ~ button_total_notes = self.srvgui.get_widget('gtk_button_total_notes')
231 t00m 176
 
177
 
216 t00m 178
        logviewer.update()
247 t00m 179
        self.gui_hide_popover(self.srvgui.get_widget('gtk_popover_button_menu_system'))
216 t00m 180
        stack.set_visible_child_name('log')
247 t00m 181
        self.srvuif.set_widget_visibility('gtk_button_dashboard', True)
182
        # ~ self.srvuif.set_widget_visibility(button_total_notes, False)
216 t00m 183
 
184
 
188 t00m 185
    def gui_show_settings(self, button):
247 t00m 186
        stack = self.srvgui.get_widget('gtk_stack_main')
215 t00m 187
        stack.set_visible_child_name('settings')
247 t00m 188
        view_settings = self.srvgui.get_widget('widget_settings')
180 t00m 189
        view_settings.update()
247 t00m 190
        self.gui_hide_popover(self.srvgui.get_widget('gtk_popover_button_menu_system'))
250 t00m 191
        self.srvuif.set_widget_visibility('gtk_label_total_notes', False)
247 t00m 192
        self.srvuif.set_widget_visibility('gtk_button_dashboard', True)
79 t00mlabs 193
 
218 t00m 194
 
217 t00m 195
    def gui_show_dashboard(self, *args):
247 t00m 196
        stack = self.srvgui.get_widget('gtk_stack_main')
197
        viewmenu = self.srvgui.get_widget('viewmenu')
234 t00m 198
        current_view = viewmenu.get_view()
199
 
217 t00m 200
        stack.set_visible_child_name('visor')
247 t00m 201
        self.gui_hide_popover(self.srvgui.get_widget('gtk_popover_button_menu_system'))
202
        self.srvuif.set_widget_visibility('gtk_button_dashboard', False)
234 t00m 203
 
233 t00m 204
        if current_view == 'annotation':
250 t00m 205
            self.srvuif.set_widget_visibility('gtk_label_total_notes', False)
233 t00m 206
        else:
250 t00m 207
            self.srvuif.set_widget_visibility('gtk_label_total_notes', True)
216 t00m 208
 
217 t00m 209
 
257 t00m 210
    def gui_toggle_help_visor(self, *args):
211
        button = self.srvgui.get_widget('gtk_togglebutton_help')
212
        notebook = self.srvgui.get_widget('gtk_notebook_visor')
213
 
214
        if button.get_active():
215
            self.srvuif.set_widget_visibility('gtk_notebook_help_page', True)
216
            notebook.set_current_page(2)
217
        else:
218
            self.srvuif.set_widget_visibility('gtk_notebook_help_page', False)
219
            notebook.set_current_page(0)
220
 
262 t00m 221
    def gui_lauch_help_visor(self, *args):
222
        self.srvutl.browse("file://%s" % FILE['HELP_INDEX'])
257 t00m 223
 
224 t00m 224
    def gui_annotation_widget_show(self, widget, sid='0000000000', action='create'):
247 t00m 225
        widget_annotation = self.srvgui.get_widget('widget_annotation')
226
        widget = self.srvgui.get_widget('gtk_label_annotation_sid')
224 t00m 227
 
228 t00m 228
 
222 t00m 229
        if action == 'create':
230
            self.gui_annotation_widget_clear()
247 t00m 231
            aid = self.srvant.gen_aid(sid)
224 t00m 232
        elif action == 'edit':
233
            aid = sid
235 t00m 234
 
233 t00m 235
        widget_annotation.set_metadata_to_widget(aid, action)
247 t00m 236
        self.srvuif.set_widget_visibility('gtk_vbox_container_annotations', True)
228 t00m 237
        widget.grab_focus()
207 t00m 238
 
239
 
188 t00m 240
    def gui_show_popover(self, button, popover):
110 t00mlabs 241
        if popover.get_visible():
242
            popover.hide()
243
        else:
244
            popover.show_all()
79 t00mlabs 245
 
122 t00mlabs 246
 
212 t00m 247
    def switch_bookmark_current_set(self, button, popover):
254 t00m 248
        visor = self.srvgui.get_widget('visor_sapnotes')
212 t00m 249
        bag = visor.get_bag()
250
        try:
251
            for sid in bag:
247 t00m 252
                metadata = self.srvdtb.get_sapnote_metadata(sid)
212 t00m 253
                bookmark = metadata['bookmark']
254
                if bookmark:
255
                    self.sapnote_unbookmark([sid])
256
                else:
257
                    self.sapnote_bookmark([sid])
258
            popover.hide()
259
        except:
218 t00m 260
            self.debug("Could not bookmark SAP Note %s" % sid)
237 t00m 261
        visor.populate_sapnotes()
198 t00m 262
 
212 t00m 263
 
264
    def switch_bookmark(self, button, lsid, popover):
254 t00m 265
        visor = self.srvgui.get_widget('visor_sapnotes')
212 t00m 266
        try:
267
            for sid in lsid:
247 t00m 268
                metadata = self.srvdtb.get_sapnote_metadata(sid)
212 t00m 269
                bookmark = metadata['bookmark']
270
                if bookmark:
271
                    self.sapnote_unbookmark([sid])
272
                else:
273
                    self.sapnote_bookmark([sid])
274
            popover.hide()
275
        except:
218 t00m 276
            self.debug("Could not bookmark SAP Note %s" % sid)
237 t00m 277
        visor.populate_sapnotes()
212 t00m 278
 
188 t00m 279
    def sapnote_bookmark(self, lsid):
247 t00m 280
        self.srvdtb.set_bookmark(lsid)
112 t00mlabs 281
 
187 t00m 282
 
188 t00m 283
    def sapnote_unbookmark(self, lsid):
247 t00m 284
        self.srvdtb.set_no_bookmark(lsid)
112 t00mlabs 285
 
118 t00mlabs 286
 
188 t00m 287
    def sapnote_import_from_launchpad(self, *args):
74 t00mlabs 288
        db = self.get_service('DB')
171 t00m 289
        webdriver = self.get_service('Driver')
247 t00m 290
        textview = self.srvgui.get_widget('gtk_textview_download_launchpad')
254 t00m 291
        visor = self.srvgui.get_widget('visor_sapnotes')
180 t00m 292
 
213 t00m 293
        bag = []
294
        all_notes = []
180 t00m 295
        sapnotes = []
296
 
297
        dlbuffer = textview.get_buffer()
298
        istart, iend = dlbuffer.get_bounds()
299
        text = dlbuffer.get_text(istart, iend, False)
300
        lines = text.replace(' ', ',')
301
        lines = lines.replace('\n', ',')
302
        sapnotes.extend(lines.split(','))
303
        for sapnote in sapnotes:
213 t00m 304
            sid = sapnote.strip()
247 t00m 305
            is_valid = self.srvdtb.is_valid(sid)
306
            is_saved = self.srvdtb.get_sapnote_metadata(sid)
213 t00m 307
            if is_valid and not is_saved:
308
                bag.append(sid)
309
            if is_valid:
310
                all_notes.append(sid)
180 t00m 311
        lbag = list(bag)
312
        lbag.sort()
313
 
213 t00m 314
        if len(bag)> 0:
315
            driver = webdriver.open()
316
 
247 t00m 317
        winroot = self.srvgui.get_widget('gtk_app_window_main')
133 t00mlabs 318
        self.debug("%d SAP Notes to be downloaded: %s" % (len(bag), ', '.join(list(bag))))
4 t00mlabs 319
 
144 t00mlabs 320
        result = {}
4 t00mlabs 321
 
247 t00m 322
        self.srvsap.start_fetching(len(bag))
142 t00mlabs 323
        dlbag = []
74 t00mlabs 324
 
325
        # FIXME: max_workers = 1 = Threads disabled
180 t00m 326
        # Indeed, I think this is the best option right now.
130 t00mlabs 327
        with Executor(max_workers=1) as exe:
74 t00mlabs 328
            jobs = []
180 t00m 329
            for sapnote in lbag:
247 t00m 330
                job = exe.submit(self.srvsap.fetch, driver, sapnote)
74 t00mlabs 331
                jobs.append(job)
332
 
333
            for job in jobs:
334
                rc, sapnote = job.result()
133 t00mlabs 335
                self.debug("\tRC SAP Note %s: %s" % (sapnote, rc))
144 t00mlabs 336
                result[sapnote] = rc
142 t00mlabs 337
                if rc:
338
                    sid = "0"*(10 - len(sapnote)) + sapnote
339
                    dlbag.append(sid)
127 t00mlabs 340
                time.sleep(0.2)
74 t00mlabs 341
 
180 t00m 342
        dlbuffer.set_text('')
247 t00m 343
        popover = self.srvgui.get_widget('gtk_popover_toolbutton_import')
188 t00m 344
        self.gui_hide_popover(popover)
213 t00m 345
        if len(bag) > 0:
346
            webdriver.close(driver)
347
 
247 t00m 348
        self.srvsap.stop_fetching()
74 t00mlabs 349
        db.save_notes()
350
        db.build_stats()
229 t00m 351
        self.debug("Collection completed.")
213 t00m 352
        # ~ self.gui_display_visor
256 t00m 353
        # ~ viewmenu = self.srvgui.get_widget('viewmenu')
354
        # ~ viewmenu.row_changed(None)
237 t00m 355
        visor.populate_sapnotes(all_notes)
144 t00mlabs 356
        return result
357
 
74 t00mlabs 358
 
175 t00m 359
    def expand_menuview(self):
247 t00m 360
        viewmenu = self.srvgui.get_widget('viewmenu')
175 t00m 361
        viewmenu.expand_all()
362
 
363
 
222 t00m 364
    def gui_viewmenu_filter(self, *args):
247 t00m 365
        entry = self.srvgui.get_widget('gtk_entry_filter_view')
159 t00m 366
        filter = entry.get_text()
247 t00m 367
        viewmenu = self.srvgui.get_widget('viewmenu')
164 t00m 368
        selection = viewmenu.get_selection()
74 t00mlabs 369
 
188 t00m 370
        def gui_iterate_over_data(model, path, itr):
165 t00m 371
            rowkey = model.get(itr, 0)[0]
372
            rowtype, rowval = rowkey.split('@')
161 t00m 373
            dsc = model.get(itr, 3)[0]
159 t00m 374
            contents = model.get(itr, 3)[0]
375
            cleanstr = contents.replace('<b>', '')
376
            cleanstr = cleanstr.replace('</b>', '')
377
            model.set(itr, 3, '%s' % cleanstr)
378
            viewmenu.collapse_row(path)
379
 
380
            if len(filter) > 0:
165 t00m 381
                if filter.upper() in rowval.upper() or filter.upper() in dsc.upper():
159 t00m 382
                    viewmenu.expand_to_path (path)
164 t00m 383
                    selection.select_path(path)
159 t00m 384
                    model.set(itr, 3, '<b>%s</b>' % contents)
385
            else:
386
                return
387
 
388
        model = viewmenu.get_model()
188 t00m 389
        model.foreach(gui_iterate_over_data)
159 t00m 390
 
391
 
188 t00m 392
    def gui_filter_visor(self, entry):
255 t00m 393
        page = self.srvgui.get_key_value('current_visor_tab')
394
        if page == 0:
395
            visor = self.srvgui.get_widget('visor_sapnotes')
396
            visible_filter = visor.get_visible_filter()
397
            visible_filter.refilter()
398
            visor.update_total_sapnotes_count(len(visible_filter))
399
        elif page == 1:
400
            visor = self.srvgui.get_widget('visor_annotations')
401
            visible_filter = visor.get_visible_filter()
402
            visible_filter.refilter()
403
            # ~ visor.update_total_sapnotes_count(len(visible_filter))
404
 
405
 
406
    def gui_filter_visor_annotations(self, entry):
407
        visor = self.srvgui.get_widget('visor_annotations')
254 t00m 408
        self.debug(visor)
199 t00m 409
        visible_filter = visor.get_visible_filter()
410
        visible_filter.refilter()
202 t00m 411
        visor.update_total_sapnotes_count(len(visible_filter))
159 t00m 412
 
203 t00m 413
 
188 t00m 414
    def gui_refresh_view(self, button, view=None):
247 t00m 415
        window = self.srvgui.get_widget('gtk_app_window_main')
416
        viewmenu = self.srvgui.get_widget('viewmenu')
203 t00m 417
        if view is None:
418
            view = viewmenu.get_view()
74 t00mlabs 419
 
4 t00mlabs 420
        if view is not None:
247 t00m 421
            viewlabel = self.srvgui.get_widget('gtk_label_current_view')
91 t00mlabs 422
            name = "<b>%-10s</b>" % view.capitalize()
4 t00mlabs 423
            viewlabel.set_markup(name)
116 t00mlabs 424
        viewmenu.set_view(view)
247 t00m 425
        popover = self.srvgui.get_widget('gtk_popover_button_menu_views')
157 t00m 426
        popover.hide()
4 t00mlabs 427
 
428
 
188 t00m 429
    def gui_toggle_menu_view(self, obj):
247 t00m 430
        paned = self.srvgui.get_widget('gtk_vbox_container_menu_view')
431
        button = self.srvgui.get_widget('gtk_toogletoolbutton_menu_view')
180 t00m 432
 
203 t00m 433
        if isinstance(obj, Gtk.ToggleToolButton):
180 t00m 434
            if button.get_active():
435
                paned.show_all()
436
            else:
437
                paned.hide()
438
        elif isinstance(obj, bool):
439
            if obj == True:
440
                # ~ paned.show_all()
441
                button.set_active(True)
442
            else:
443
                # ~ paned.hide()
444
                button.set_active(False)
201 t00m 445
 
446
 
203 t00m 447
    def gui_toggle_fullscreen(self, button):
247 t00m 448
        icon_container = self.srvgui.get_widget('gtk_box_container_icon_fullscreen')
449
        icon_fullscreen = self.srvicm.get_new_image_icon('basico-fullscreen', 24, 24)
450
        icon_unfullscreen = self.srvicm.get_new_image_icon('basico-unfullscreen', 24, 24)
203 t00m 451
        active = button.get_active()
247 t00m 452
        ui = self.srvgui.get_window()
203 t00m 453
        window = ui.get_window()
454
        if active:
247 t00m 455
            self.srvgui.swap_widget(icon_container, icon_unfullscreen)
203 t00m 456
            window.fullscreen()
457
        else:
247 t00m 458
            self.srvgui.swap_widget(icon_container, icon_fullscreen)
203 t00m 459
            window.unfullscreen()
460
 
461
 
222 t00m 462
    def action_annotation_edit(self, aid):
463
        self.gui_annotation_widget_show(None, aid, 'edit')
217 t00m 464
 
465
 
226 t00m 466
    def action_annotation_duplicate(self, *args):
467
        self.debug("ACTION-DUPLICATE: %s" % args)
468
 
469
 
225 t00m 470
    def action_annotation_delete(self, *args):
247 t00m 471
        statusbar = self.srvgui.get_widget('widget_statusbar')
254 t00m 472
        visor = self.srvgui.get_widget('visor_annotations')
247 t00m 473
        widget_annotation = self.srvgui.get_widget('widget_annotation')
233 t00m 474
        aid = widget_annotation.get_aid_from_widget()
247 t00m 475
        self.srvant.delete(aid)
225 t00m 476
        self.gui_annotation_widget_clear()
247 t00m 477
        self.srvuif.set_widget_visibility('gtk_vbox_container_annotations', False)
226 t00m 478
        visor.populate_annotations()
225 t00m 479
 
480
 
222 t00m 481
    def action_annotation_accept(self, button, sid):
247 t00m 482
        statusbar = self.srvgui.get_widget('widget_statusbar')
483
        widget_annotation = self.srvgui.get_widget('widget_annotation')
254 t00m 484
        visor = self.srvgui.get_widget('visor_annotations')
247 t00m 485
        viewmenu = self.srvgui.get_widget('viewmenu')
221 t00m 486
 
233 t00m 487
        aid = widget_annotation.get_aid_from_widget()
221 t00m 488
 
247 t00m 489
        annotation = widget_annotation.get_metadata_from_widget()
226 t00m 490
 
247 t00m 491
        if self.srvant.is_valid(aid):
492
            self.srvant.update(annotation)
243 t00m 493
            # ~ self.info("Updated annotation: %s" % aid)
223 t00m 494
        else:
247 t00m 495
            self.srvant.create(annotation)
243 t00m 496
            # ~ self.info('New annotation created (%s) and linked to SAP Note %010d' % (aid, int(sid)))
226 t00m 497
 
222 t00m 498
        self.gui_annotation_widget_clear()
264 t00m 499
        visor.reload()
500
        self.srvuif.set_widget_visibility('gtk_vbox_container_annotations', False)
223 t00m 501
 
205 t00m 502
 
222 t00m 503
    def action_annotation_cancel(self, *args):
247 t00m 504
        statusbar = self.srvgui.get_widget('widget_statusbar')
222 t00m 505
        self.gui_annotation_widget_clear()
247 t00m 506
        self.srvuif.set_widget_visibility('gtk_vbox_container_annotations', False)
236 t00m 507
        self.info('Annotation canceled')
205 t00m 508
 
509
 
227 t00m 510
 
222 t00m 511
    def gui_annotation_widget_clear(self):
247 t00m 512
        a_wdg_timestamp = self.srvgui.get_widget('gtk_label_human_timestamp')
513
        a_wdg_title = self.srvgui.get_widget('gtk_entry_annotation_title')
514
        a_wdg_type = self.srvgui.get_widget('gtk_combobox_annotation_type')
515
        a_wdg_text = self.srvgui.get_widget('gtk_textview_annotation_text')
516
        a_wdg_link = self.srvgui.get_widget('gtk_entry_annotation_link')
517
        a_wdg_link_button = self.srvgui.get_widget('gtk_link_button_annotation_link')
518
        a_wdg_link_type = self.srvgui.get_widget('gtk_combobox_annotation_link_type')
221 t00m 519
 
233 t00m 520
        a_wdg_timestamp.set_text('')
221 t00m 521
        a_wdg_title.set_text('')
522
        textbuffer = a_wdg_text.get_buffer()
523
        textbuffer.set_text('')
524
        a_wdg_link.set_text('')
240 t00m 525
        a_wdg_link_button.set_uri('')
247 t00m 526
        self.srvuif.set_widget_visibility('gtk_vbox_container_annotations', False)