Subversion Repositories basico

Rev

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

Rev Author Line No. Line
254 t00m 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
264 t00m 3
"""
254 t00m 4
# File: wdg_visor_annotations.py
5
# Author: Tomás Vírseda
6
# License: GPL v3
7
# Description: SAPNoteViewVisor widgets
264 t00m 8
"""
254 t00m 9
 
10
import os
11
from os.path import sep as SEP
12
from cgi import escape
13
import glob
14
import json
274 t00m 15
import html
254 t00m 16
 
17
import gi
18
gi.require_version('Gdk', '3.0')
19
gi.require_version('Gtk', '3.0')
20
from gi.repository import Gdk
21
from gi.repository import Gio
22
from gi.repository import Gtk
23
from gi.repository.GdkPixbuf import Pixbuf
24
from gi.repository import Pango
25
 
287 t00m 26
from basico.core.mod_env import LPATH, ATYPES
264 t00m 27
from basico.core.mod_srv import Service
254 t00m 28
from basico.widgets.wdg_cols import CollectionsMgtView
29
from basico.widgets.wdg_import import ImportWidget
30
 
31
 
268 t00m 32
class AnnotationsVisor(Gtk.HBox, Service):
254 t00m 33
    def __init__(self, app):
268 t00m 34
        Gtk.HBox.__init__(self, app)
35
        self.set_homogeneous(False)
264 t00m 36
        Service.__init__(self)
283 t00m 37
        self.get_logger(__class__.__name__)
264 t00m 38
        self.config = None
254 t00m 39
        self.app = app
40
        self.bag = []
41
        self.get_services()
268 t00m 42
        self.setup_left_panel()
270 t00m 43
        self.set_initial_panel_button_status()
268 t00m 44
        self.setup_visor()
264 t00m 45
        self.config = self.get_config()
271 t00m 46
        self.icons = {}
47
        self.icons['type'] = {}
287 t00m 48
        for atype in ATYPES:
284 t00m 49
            self.icons['type'][atype.lower()] = self.srvicm.get_pixbuf_icon('basico-annotation-type-%s' % atype.lower())
254 t00m 50
 
271 t00m 51
 
254 t00m 52
    def get_services(self):
53
        self.srvgui = self.app.get_service("GUI")
54
        self.srvclb = self.app.get_service('Callbacks')
55
        self.srvsap = self.app.get_service('SAP')
56
        self.srvicm = self.app.get_service('IM')
57
        self.srvstg = self.app.get_service('Settings')
58
        self.srvdtb = self.app.get_service('DB')
59
        self.srvuif = self.app.get_service("UIF")
60
        self.srvutl = self.app.get_service("Utils")
61
        self.srvant = self.app.get_service('Annotation')
62
 
264 t00m 63
 
270 t00m 64
    def set_initial_panel_button_status(self):
65
        # Categories
66
        self.srvgui.set_key_value('ANNOTATIONS_CATEGORY_INBOX_VISIBLE', True)
67
        self.srvgui.set_key_value('ANNOTATIONS_CATEGORY_DRAFTS_VISIBLE', False)
68
        self.srvgui.set_key_value('ANNOTATIONS_CATEGORY_ARCHIVED_VISIBLE', False)
69
 
70
        # Types
287 t00m 71
        for atype in ATYPES:
72
            self.srvgui.set_key_value('ANNOTATIONS_TYPE_%s_VISIBLE' % atype.upper(), True)
270 t00m 73
 
74
 
254 t00m 75
    def get_treeview(self):
76
        return self.treeview
77
 
78
 
79
    def sort_by_timestamp(self):
80
        self.sorted_model.set_sort_column_id(11, Gtk.SortType.DESCENDING)
81
 
82
 
272 t00m 83
    def setup_left_panel(self):
84
        pass
85
 
86
 
270 t00m 87
    def set_visible_categories(self, togglebutton):
88
        types = self.srvgui.get_widget('gtk_togglebutton_types')
89
        revealer = self.srvgui.get_widget('gtk_revealer_annotations_categories')
90
 
268 t00m 91
        active = togglebutton.get_active()
270 t00m 92
        if active:
93
            types.set_active(False)
94
        revealer.set_reveal_child(active)
268 t00m 95
 
96
 
270 t00m 97
    def set_visible_types(self, togglebutton):
98
        categories = self.srvgui.get_widget('gtk_togglebutton_categories')
99
        revealer = self.srvgui.get_widget('gtk_revealer_annotations_types')
100
 
268 t00m 101
        active = togglebutton.get_active()
270 t00m 102
        if active:
103
            categories.set_active(False)
104
        revealer.set_reveal_child(active)
105
 
272 t00m 106
 
270 t00m 107
    def set_visible_category(self, togglebutton, title):
108
        active = togglebutton.get_active()
109
        self.srvgui.set_key_value('ANNOTATIONS_CATEGORY_%s_VISIBLE' % title.upper(), active)
268 t00m 110
        self.populate_annotations()
111
 
112
 
270 t00m 113
    def set_visible_annotation_type(self, togglebutton, atype):
268 t00m 114
        active = togglebutton.get_active()
270 t00m 115
        self.srvgui.set_key_value('ANNOTATIONS_TYPE_%s_VISIBLE' % atype.upper(), active)
268 t00m 116
        self.populate_annotations()
117
 
118
 
119
    def setup_visor(self):
254 t00m 120
        scr = Gtk.ScrolledWindow()
270 t00m 121
        scr.set_hexpand(True)
254 t00m 122
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
270 t00m 123
        scr.set_shadow_type(Gtk.ShadowType.NONE)
254 t00m 124
        self.treeview = Gtk.TreeView()
275 t00m 125
        scr.add(self.treeview)
268 t00m 126
        scr.set_hexpand(True)
255 t00m 127
        self.pack_start(scr, True, True, 0)
254 t00m 128
 
129
        # Setup model
130
        self.model = Gtk.TreeStore(
131
            int,        # key
284 t00m 132
            Pixbuf,        # Icon
254 t00m 133
            int,        # checkbox
134
            str,        # sid
135
            str,        # title
136
            str,        # component
137
            str,        # category
138
            str,        # type
139
            str,        # priority
140
            str,        # last update
141
            str,        # Annotation Id (extra key)
142
            str,        # Timestamp
143
        )
144
 
145
        # Setup columns
146
        def get_column_header_widget(title, icon_name=None, width=24, height=24):
147
            hbox = Gtk.HBox()
148
            icon = self.srvicm.get_new_image_icon(icon_name, width, height)
149
            label = Gtk.Label()
150
            label.set_markup("<b>%s</b>" % title)
151
            label.modify_font(Pango.FontDescription('Monospace 10'))
152
            hbox.pack_start(icon, False, False, 3)
153
            hbox.pack_start(label, True, True, 3)
154
            hbox.show_all()
155
            return hbox
156
 
157
        # SAP Note key
158
        self.renderer_key = Gtk.CellRendererText()
271 t00m 159
        # ~ self.renderer_key.set_property('height', 32)
254 t00m 160
        self.column_key = Gtk.TreeViewColumn('Key', self.renderer_key, text=0)
161
        self.column_key.set_visible(False)
162
        self.column_key.set_expand(False)
163
        self.column_key.set_clickable(False)
164
        self.column_key.set_sort_indicator(False)
165
        self.treeview.append_column(self.column_key)
166
 
167
        # Icon
284 t00m 168
        self.renderer_icon = Gtk.CellRendererPixbuf()
169
        self.renderer_icon.set_alignment(0.0, 0.5)
170
        self.column_icon = Gtk.TreeViewColumn('', self.renderer_icon, pixbuf=1)
269 t00m 171
        widget = get_column_header_widget('', 'basico-empty')
254 t00m 172
        self.column_icon.set_widget(widget)
173
        self.column_icon.set_visible(True)
174
        self.column_icon.set_expand(False)
175
        self.column_icon.set_clickable(False)
176
        self.column_icon.set_sort_indicator(False)
177
        self.treeview.append_column(self.column_icon)
178
 
179
        # SAP Note Checkbox
180
        self.renderer_checkbox = Gtk.CellRendererToggle()
181
        self.renderer_checkbox.connect("toggled", self.toggle_checkbox)
182
        self.column_checkbox = Gtk.TreeViewColumn('', self.renderer_checkbox, active=2)
287 t00m 183
        self.column_checkbox.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
254 t00m 184
        self.column_checkbox.set_visible(False)
185
        self.column_checkbox.set_expand(False)
186
        self.column_checkbox.set_clickable(True)
187
        self.column_checkbox.set_sort_indicator(False)
188
        self.column_checkbox.set_property('spacing', 50)
189
        self.treeview.append_column(self.column_checkbox)
190
 
191
        # SAP Note Id
192
        self.renderer_sid = Gtk.CellRendererText()
193
        self.renderer_sid.set_property('xalign', 1.0)
194
        self.renderer_sid.set_property('height', 36)
195
        self.renderer_sid.set_property('background', '#F0E3E3')
196
        self.column_sid = Gtk.TreeViewColumn('SAP Note Id', self.renderer_sid, markup=3)
197
        widget = get_column_header_widget('SAP Note Id', 'basico-sid')
198
        self.column_sid.set_widget(widget)
199
        self.column_sid.set_visible(True)
287 t00m 200
        self.column_sid.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
254 t00m 201
        self.column_sid.set_expand(False)
202
        self.column_sid.set_clickable(True)
203
        self.column_sid.set_sort_indicator(True)
204
        self.column_sid.set_sort_column_id(0)
205
        self.column_sid.set_sort_order(Gtk.SortType.ASCENDING)
206
        self.model.set_sort_column_id(0, Gtk.SortType.ASCENDING)
207
        self.treeview.append_column(self.column_sid)
208
 
209
        # SAP Note title
210
        self.renderer_title = Gtk.CellRendererText()
211
        self.renderer_title.set_property('background', '#FFFEEA')
275 t00m 212
        self.renderer_title.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
254 t00m 213
        self.column_title = Gtk.TreeViewColumn('Title', self.renderer_title, markup=4)
214
        widget = get_column_header_widget('Title', 'basico-tag')
215
        self.column_title.set_widget(widget)
216
        self.column_title.set_visible(True)
275 t00m 217
        self.column_title.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
254 t00m 218
        self.column_title.set_expand(True)
219
        self.column_title.set_clickable(True)
220
        self.column_title.set_sort_indicator(True)
221
        self.column_title.set_sort_column_id(4)
222
        self.treeview.append_column(self.column_title)
223
 
224
        # SAP Note Component
225
        self.renderer_component = Gtk.CellRendererText()
226
        self.renderer_component.set_property('background', '#E3E3F0')
227
        self.column_component = Gtk.TreeViewColumn('Component', self.renderer_component, markup=5)
228
        widget = get_column_header_widget('Component', 'basico-component')
229
        self.column_component.set_widget(widget)
230
        self.column_component.set_visible(True)
275 t00m 231
        self.column_component.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
254 t00m 232
        self.column_component.set_expand(False)
233
        self.column_component.set_clickable(True)
234
        self.column_component.set_sort_indicator(True)
235
        self.column_component.set_sort_column_id(5)
236
        self.treeview.append_column(self.column_component)
237
 
238
        # SAP Note Category
239
        self.renderer_category = Gtk.CellRendererText()
240
        self.renderer_category.set_property('background', '#E3F1E3')
241
        self.column_category = Gtk.TreeViewColumn('Category', self.renderer_category, markup=6)
242
        widget = get_column_header_widget('Category', 'basico-category')
243
        self.column_category.set_widget(widget)
244
        self.column_category.set_visible(False)
287 t00m 245
        self.column_category.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
254 t00m 246
        self.column_category.set_expand(False)
247
        self.column_category.set_clickable(True)
248
        self.column_category.set_sort_indicator(True)
249
        self.column_category.set_sort_column_id(6)
250
        self.treeview.append_column(self.column_category)
251
 
252
        # SAP Note Type
253
        self.renderer_type = Gtk.CellRendererText()
254
        self.renderer_type.set_property('background', '#e4f1f1')
255
        self.column_type = Gtk.TreeViewColumn('Type', self.renderer_type, markup=7)
256
        self.column_type.set_visible(True)
257
        self.column_type.set_expand(False)
287 t00m 258
        self.column_type.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
254 t00m 259
        self.column_type.set_clickable(True)
260
        self.column_type.set_sort_indicator(True)
261
        self.column_type.set_sort_column_id(7)
262
        self.treeview.append_column(self.column_type)
263
 
264
        # SAP Note Priority
265
        self.renderer_priority = Gtk.CellRendererText()
266
        self.column_priority = Gtk.TreeViewColumn('Priority', self.renderer_priority, markup=8)
267
        self.column_priority.set_visible(False)
268
        self.column_priority.set_expand(True)
269
        self.column_priority.set_clickable(True)
270
        self.column_priority.set_sort_indicator(True)
271
        self.column_priority.set_sort_column_id(8)
272
        self.treeview.append_column(self.column_priority)
273
 
274
        # SAP Note UpdatedOn
275
        self.renderer_updated = Gtk.CellRendererText()
276
        self.renderer_updated.set_property('background', '#FFE6D1')
277
        self.column_updated = Gtk.TreeViewColumn('Updated On', self.renderer_updated, markup=9)
278
        self.column_updated.set_visible(True)
279
        self.column_updated.set_expand(False)
287 t00m 280
        self.column_updated.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
254 t00m 281
        self.column_updated.set_clickable(True)
282
        self.column_updated.set_sort_indicator(True)
283
        self.column_updated.set_sort_column_id(11)
284
        self.treeview.append_column(self.column_updated)
285
 
286
        # Annotation Id
287
        self.renderer_annotation = Gtk.CellRendererText()
288
        self.column_annotation = Gtk.TreeViewColumn('Annotation Id', self.renderer_annotation, markup=10)
289
        self.column_annotation.set_visible(False)
290
        self.column_annotation.set_expand(False)
291
        self.column_annotation.set_clickable(False)
292
        self.column_annotation.set_sort_indicator(False)
293
        self.treeview.append_column(self.column_annotation)
294
 
295
        # Timestamp
296
        self.renderer_timestamp = Gtk.CellRendererText()
271 t00m 297
        self.column_timestamp = Gtk.TreeViewColumn('Timestamp', self.renderer_timestamp, text=11)
254 t00m 298
        self.column_timestamp.set_visible(False)
299
        self.column_timestamp.set_expand(False)
300
        self.column_timestamp.set_clickable(False)
301
        self.column_timestamp.set_sort_indicator(False)
302
        self.treeview.append_column(self.column_timestamp)
303
 
304
        # Treeview properties
305
        self.treeview.set_can_focus(False)
306
        self.treeview.set_enable_tree_lines(True)
307
        self.treeview.set_headers_visible(True)
308
        self.treeview.set_enable_search(True)
309
        self.treeview.set_hover_selection(False)
310
        self.treeview.set_grid_lines(Gtk.TreeViewGridLines.NONE)
311
        self.treeview.set_enable_tree_lines(True)
312
        self.treeview.set_level_indentation(10)
271 t00m 313
        # ~ self.treeview.modify_font(Pango.FontDescription('Monospace 10'))
254 t00m 314
        self.treeview.connect('button_press_event', self.right_click)
269 t00m 315
        # ~ self.treeview.set_row_separator_func(self.separator_func)
254 t00m 316
 
317
        # DOC: In order to have a Gtk.Widged with sorting and filtering
318
        # capabilities, you have to filter the model first, and use this
319
        # new model to create the sorted model. Then, attach the sorted
320
        # model to the treeview...
321
 
322
        # Treeview filtering:
323
        self.visible_filter = self.model.filter_new()
274 t00m 324
        self.visible_filter.set_visible_func(self.visible_function)
254 t00m 325
 
326
        # TreeView sorting
327
        self.sorted_model = Gtk.TreeModelSort(model=self.visible_filter)
328
        self.sorted_model.set_sort_func(0, self.sort_function, None)
329
 
330
        # Selection
331
        self.selection = self.treeview.get_selection()
332
        self.selection.set_mode(Gtk.SelectionMode.SINGLE)
333
        self.selection.connect('changed', self.row_changed)
334
 
335
        # Set model (filtered and sorted)
336
        self.treeview.set_model(self.sorted_model)
337
 
338
        self.show_all()
339
 
340
 
341
    def sort_function(self, model, row1, row2, user_data):
342
        sort_column = 0
343
 
344
        value1 = model.get_value(row1, sort_column)
345
        value2 = model.get_value(row2, sort_column)
346
 
347
        if value1 < value2:
348
            return -1
349
        elif value1 == value2:
350
            return 0
351
        else:
352
            return 1
353
 
287 t00m 354
 
254 t00m 355
    def always_visible(self, model, itr, data):
356
        return False
357
 
268 t00m 358
 
254 t00m 359
    def visible_function(self, model, itr, data):
360
        entry = self.srvgui.get_widget('gtk_entry_filter_visor')
361
        text = entry.get_text()
271 t00m 362
        if len(text) == 0:
363
            return True
254 t00m 364
        sid = str(model.get(itr, 3)[0])
365
        if sid.startswith('<'):
366
            sid = sid[3:-4]
367
        title = model.get(itr, 4)[0]
368
        component = str(model.get(itr, 5)[0])
369
        category = model.get(itr, 6)[0]
370
        rtype = model.get(itr, 7)[0]
281 t00m 371
        # ~ string = ' '.join(['SAP Note %s' % sid, title, component, category, rtype])
372
        # ~ match = text.upper() in string.upper()
373
        match = text.upper() in title.upper()
374
        # ~ self.log.debug("%s in %s? %s" % (html.escape(text), string, match))
254 t00m 375
 
376
        return match
377
 
378
 
267 t00m 379
    def update_total_annotations_count(self):
254 t00m 380
        statusbar = self.srvgui.get_widget('widget_statusbar')
381
        lblnotescount = self.srvgui.get_widget('gtk_label_total_notes')
267 t00m 382
        total = self.srvant.get_total()
254 t00m 383
 
268 t00m 384
        count = len(self.visible_filter)
385
        lblnotescount.set_markup("<b>%d/<big>%d annotations</big></b>" % (count, total))
254 t00m 386
        # ~ self.info('View populated with %d SAP Notes' % count)
387
 
388
 
389
    def get_visible_filter(self):
390
        return self.visible_filter
275 t00m 391
        # ~ return self.model
254 t00m 392
 
393
    def row_changed(self, selection):
394
        try:
395
            model, treeiter = selection.get_selected()
396
            if treeiter is not None:
397
                component = model[treeiter][5]
398
                if component == 'Annotation':
399
                    aid = model[treeiter][10]
400
                    is_valid = self.srvant.is_valid(aid)
401
                    if is_valid:
402
                        self.srvclb.action_annotation_edit(aid)
403
                else:
404
                    aid = None
405
                    self.srvuif.set_widget_visibility('gtk_vbox_container_annotations', False)
406
        except Exception as error:
279 t00m 407
            self.log.debug(error)
254 t00m 408
            self.print_traceback()
409
 
410
 
411
    def toggle_checkbox(self, cell, path):
412
        path = self.sorted_model.convert_path_to_child_path(Gtk.TreePath(path))
413
        self.model[path][2] = not self.model[path][2]
414
 
415
 
416
    def get_node(self, key, icon, checkbox, sid, title, component, category='', sntype='', priority='', updated='', aid='', timestamp=''):
417
        # Add completion entries
418
        completion = self.srvgui.get_widget('gtk_entrycompletion_visor')
419
        completion_model = completion.get_model()
420
        completion_model.append([title])
421
 
422
        node = []
423
        node.append(key)
424
        node.append(icon)
425
        node.append(checkbox)
426
        node.append(sid)
427
        node.append(title)
428
        node.append(component)
429
        node.append(category)
430
        node.append(sntype)
431
        node.append(priority)
432
        node.append(updated)
433
        node.append(aid) # Extra key for annotations id (aid)
434
        node.append(timestamp)
435
        return node
436
 
437
 
264 t00m 438
    def set_bag(self, annotations):
439
        self.bag = annotations
440
 
270 t00m 441
 
254 t00m 442
    def get_bag(self):
443
        return self.bag
444
 
270 t00m 445
 
264 t00m 446
    def reload(self):
447
        bag = self.get_bag()
448
        self.populate_annotations(bag)
254 t00m 449
 
264 t00m 450
 
254 t00m 451
    def populate_annotations(self, annotations=None):
271 t00m 452
        self.treeview.freeze_child_notify()
254 t00m 453
        self.column_sid.set_visible(False)
264 t00m 454
        self.column_checkbox.set_visible(False)
254 t00m 455
        self.column_category.set_visible(True)
456
        self.column_component.set_visible(False)
268 t00m 457
        completion = self.srvgui.get_widget('gtk_entrycompletion_visor')
458
        completion_model = completion.get_model()
459
        completion_model.clear()
254 t00m 460
 
275 t00m 461
        self.treeview.set_model(None)
254 t00m 462
        self.model.clear()
463
 
464
        if annotations is None:
465
            annotations = self.srvant.get_all()
264 t00m 466
        else:
467
            self.set_bag(annotations)
254 t00m 468
 
264 t00m 469
        dcats = {}
254 t00m 470
        snpids = {}
271 t00m 471
        nodes = []
254 t00m 472
        for fname in annotations:
264 t00m 473
            try:
474
                with open(fname, 'r') as fa:
475
                    annotation = json.load(fa)
476
                    category = annotation['category']
269 t00m 477
                    atype = annotation['type']
270 t00m 478
                    cat_key = 'ANNOTATIONS_CATEGORY_%s_VISIBLE' % category.upper()
479
                    type_key = 'ANNOTATIONS_TYPE_%s_VISIBLE' % atype.upper()
480
                    category_active = self.srvgui.get_key_value(cat_key)
481
                    try:
482
                        type_active = self.srvgui.get_key_value(type_key)
287 t00m 483
                        # ~ self.log.debug("%s -> %s", type_key, type_active)
484
                    except Exception as error:
485
                        self.log.error(error)
270 t00m 486
                        type_active = True
268 t00m 487
                    if category_active:
270 t00m 488
                        if type_active:
489
                            ppid = None
490
                            sid = self.srvant.get_sid(annotation['aid'])
271 t00m 491
                            try:
492
                                icon = self.icons['type']['%s' % atype.lower()]
493
                            except:
284 t00m 494
                                icon = None
271 t00m 495
                            if sid != '0000000000':
496
                                title = "<b>[SAP Note %d]</b> %s" % (int(sid), annotation['title'])
497
                            else:
498
                                title = annotation['title']
270 t00m 499
                            node = self.get_node(   0,
284 t00m 500
                                                    icon,
270 t00m 501
                                                    False,
502
                                                    str(int(sid)),
271 t00m 503
                                                    title,
270 t00m 504
                                                    annotation['component'],
505
                                                    annotation['category'],
506
                                                    annotation['type'],
507
                                                    '',
508
                                                    self.srvutl.fuzzy_date_from_timestamp(annotation['timestamp']),
509
                                                    annotation['aid'],
510
                                                    annotation['timestamp']
511
                                                )
271 t00m 512
                            nodes.append(node)
264 t00m 513
            except:
514
                # Whenever an annotation is deleted, after reloading
515
                # the view, it fails. Then, skip it
516
                raise
271 t00m 517
 
518
        for node in nodes:
519
            self.model.append(ppid, node)
275 t00m 520
        self.treeview.set_model(self.model)
271 t00m 521
 
254 t00m 522
        self.sort_by_timestamp()
267 t00m 523
        self.update_total_annotations_count()
271 t00m 524
        self.treeview.thaw_child_notify()
254 t00m 525
 
526
 
527
    def show_widgets(self):
528
        self.srvuif.set_widget_visibility('gtk_label_total_notes', True)
529
 
530
 
531
    def right_click(self, treeview, event, data=None):
532
        if event.button == 3:
533
            rect = Gdk.Rectangle()
534
            rect.x = x = int(event.x)
535
            rect.y = y = int(event.y)
536
            pthinfo = self.treeview.get_path_at_pos(x,y)
537
            if pthinfo is not None:
538
                path,col,cellx,celly = pthinfo
539
                model = treeview.get_model()
540
                treeiter = model.get_iter(path)
541
                component = model[treeiter][5]
283 t00m 542
                aid = model[treeiter][10]
254 t00m 543
                toolbar = self.srvgui.get_widget('visortoolbar')
544
                popover = self.srvgui.add_widget('gtk_popover_visor_row', Gtk.Popover.new(treeview))
545
                popover.set_position(Gtk.PositionType.TOP)
546
                popover.set_pointing_to(rect)
283 t00m 547
                box = self.build_popover(aid, popover, component)
264 t00m 548
                if box is not None:
549
                    popover.add(box)
550
                    self.srvclb.gui_show_popover(None, popover)
254 t00m 551
 
552
 
283 t00m 553
    def build_popover(self, aid, popover, component):
554
        sid = self.srvant.get_sid(aid)
254 t00m 555
 
556
        def get_popover_button(text, icon_name):
557
            button = Gtk.Button()
558
            button.set_relief(Gtk.ReliefStyle.NONE)
559
            hbox = Gtk.HBox()
560
            icon = self.srvicm.get_new_image_icon(icon_name, 24, 24)
561
            lbltext = Gtk.Label()
562
            lbltext.set_xalign(0.0)
563
            lbltext.set_markup('%s' % text)
564
            hbox.pack_start(icon, False, False, 3)
565
            hbox.pack_start(lbltext, True, True, 3)
566
            button.add(hbox)
567
            return button
568
 
569
        if component == 'Annotation':
264 t00m 570
            box = Gtk.Box(spacing = 3, orientation="vertical")
571
 
254 t00m 572
            # Popover button "Delete annotation"
573
            button = get_popover_button("Delete annotation", 'basico-delete')
574
            button.show_all()
575
            button.connect('clicked', self.srvclb.action_annotation_delete)
576
            box.pack_start(button, False, False, 0)
577
 
578
            # Popover button "Duplicate annotation"
579
            button = get_popover_button("Duplicate annotation", 'basico-duplicate')
580
            button.show_all()
581
            button.connect('clicked', self.srvclb.action_annotation_duplicate)
582
            box.pack_start(button, False, False, 0)
583
 
283 t00m 584
            # Popover button "Duplicate annotation"
585
            if sid != '0000000000':
586
                button = get_popover_button("Jump to SAP Note %d" % int(sid), 'basico-jump-sapnote')
587
                button.show_all()
588
                button.connect('clicked', self.srvclb.gui_jump_to_sapnote, sid)
589
                box.pack_start(button, False, False, 0)
590
 
264 t00m 591
            return box
254 t00m 592
 
287 t00m 593
 
272 t00m 594
    def connect_menuview_signals(self):
595
        button = self.srvgui.get_widget('gtk_togglebutton_categories')
596
        button.connect('toggled', self.set_visible_categories)
254 t00m 597
 
272 t00m 598
        for name in ['inbox', 'drafts', 'archived']:
599
            button = self.srvgui.get_widget('gtk_button_category_%s' % name)
600
            button.connect('toggled', self.set_visible_category, name)
269 t00m 601
 
272 t00m 602
        button = self.srvgui.get_widget('gtk_togglebutton_types')
603
        button.connect('toggled', self.set_visible_types)
604
 
287 t00m 605
        for name in ATYPES:
272 t00m 606
            button = self.srvgui.get_widget('gtk_button_type_%s' % name.lower())
607
            button.connect('toggled', self.set_visible_annotation_type, name)
608
 
609
 
610
    def set_active_categories(self):
611
        category = self.srvgui.get_widget('gtk_togglebutton_inbox')
612
        category.set_active(True)