Subversion Repositories basico

Rev

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