Subversion Repositories basico

Rev

Rev 402 | Rev 406 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 402 Rev 405
Line 10... Line 10...
10
import os
10
import os
11
from os.path import sep as SEP
11
from os.path import sep as SEP
12
from cgi import escape
12
from cgi import escape
13
import glob
13
import glob
14
import json
14
import json
-
 
15
from enum import IntEnum
15
16
16
import gi
17
import gi
17
gi.require_version('Gdk', '3.0')
18
gi.require_version('Gdk', '3.0')
18
gi.require_version('Gtk', '3.0')
19
gi.require_version('Gtk', '3.0')
19
from gi.repository import Gdk
20
from gi.repository import Gdk
Line 28... Line 29...
28
from basico.services.srv_collections import COL_DOWNLOADED
29
from basico.services.srv_collections import COL_DOWNLOADED
29
from basico.widgets.wdg_cols import CollectionsMgtView
30
from basico.widgets.wdg_cols import CollectionsMgtView
30
from basico.widgets.wdg_import import ImportWidget
31
from basico.widgets.wdg_import import ImportWidget
31
from basico.core.mod_log import get_logger
32
from basico.core.mod_log import get_logger
32
from basico.widgets.wdg_menuview import MenuView
33
from basico.widgets.wdg_menuview import MenuView
-
 
34
-
 
35
-
 
36
class COLUMN(IntEnum):
-
 
37
    KEY = 0
-
 
38
    ICON = 1
-
 
39
    CHECKBOX = 2
-
 
40
    SID = 3
-
 
41
    TITLE = 4
-
 
42
    COMPONENT = 5
-
 
43
    CATEGORY = 6
-
 
44
    TYPE = 7
-
 
45
    PRIORITY = 8
-
 
46
    UPDATED = 9
-
 
47
    TS_UPDATED = 10
33
48
34
49
35
class SAPNotesVisor(BasicoWidget, Gtk.Box):
50
class SAPNotesVisor(BasicoWidget, Gtk.Box):
36
    def __init__(self, app):
51
    def __init__(self, app):
37
        super().__init__(app, __class__.__name__)
52
        super().__init__(app, __class__.__name__)
Line 60... Line 75...
60
        self.srvdtb = self.get_service('DB')
75
        self.srvdtb = self.get_service('DB')
61
        self.srvuif = self.get_service("UIF")
76
        self.srvuif = self.get_service("UIF")
62
        self.srvutl = self.get_service("Utils")
77
        self.srvutl = self.get_service("Utils")
63
        self.srvant = self.get_service('Annotation')
78
        self.srvant = self.get_service('Annotation')
64
        self.srvatc = self.get_service('Attachment')
79
        self.srvatc = self.get_service('Attachment')
65
-
 
66
-
 
67
    def get_treeview(self):
-
 
68
        return self.treeview
-
 
69
80
70
81
71
    def sort_by_timestamp(self):
82
    def sort_by_timestamp(self):
72
        sorted_model = self.srvgui.get_widget('visor_sapnotes_sorted_model')
83
        sorted_model = self.srvgui.get_widget('visor_sapnotes_sorted_model')
73
        sorted_model.set_sort_column_id(11, Gtk.SortType.DESCENDING)
-
 
-
 
84
        sorted_model.set_sort_column_id(COLUMN.TS_UPDATED, Gtk.SortType.DESCENDING)
74
85
75
86
76
    def setup_panel(self):
87
    def setup_panel(self):
77
        ## Left view - SAP Notes Menu view
88
        ## Left view - SAP Notes Menu view
78
        box = self.srvgui.add_widget('gtk_vbox_container_menu_view', Gtk.VBox())
89
        box = self.srvgui.add_widget('gtk_vbox_container_menu_view', Gtk.VBox())
Line 122... Line 133...
122
        #### Filter entry tool
133
        #### Filter entry tool
123
        tool = Gtk.ToolItem.new()
134
        tool = Gtk.ToolItem.new()
124
135
125
        hbox = Gtk.HBox()
136
        hbox = Gtk.HBox()
126
        viewfilter = self.srvgui.add_widget('gtk_entry_filter_view', Gtk.Entry())
137
        viewfilter = self.srvgui.add_widget('gtk_entry_filter_view', Gtk.Entry())
-
 
138
        viewmenu = self.srvgui.add_widget('viewmenu', MenuView(self.app))
-
 
139
        viewmenu.set_vexpand(True)
127
        completion = self.srvgui.get_widget('gtk_entrycompletion_viewmenu')
140
        completion = self.srvgui.get_widget('gtk_entrycompletion_viewmenu')
128
        viewfilter.set_completion(completion)
141
        viewfilter.set_completion(completion)
129
        viewfilter.connect('activate', self.srvclb.gui_viewmenu_filter)
142
        viewfilter.connect('activate', self.srvclb.gui_viewmenu_filter)
130
143
131
        icon = self.srvicm.get_pixbuf_icon('basico-refresh')
144
        icon = self.srvicm.get_pixbuf_icon('basico-refresh')
Line 166... Line 179...
166
        scr.set_shadow_type(Gtk.ShadowType.IN)
179
        scr.set_shadow_type(Gtk.ShadowType.IN)
167
        vwp = Gtk.Viewport()
180
        vwp = Gtk.Viewport()
168
        vwp.set_hexpand(True)
181
        vwp.set_hexpand(True)
169
        viewsbox = self.srvgui.add_widget('gtk_box_container_views', Gtk.Box())
182
        viewsbox = self.srvgui.add_widget('gtk_box_container_views', Gtk.Box())
170
        # ~ viewsbox.set_hexpand(True)
183
        # ~ viewsbox.set_hexpand(True)
171
        viewmenu = self.srvgui.add_widget('viewmenu', MenuView(self.app))
-
 
172
        # ~ viewmenu.set_hexpand(True)
-
 
173
        viewmenu.set_vexpand(True)
-
 
174
        viewsbox.pack_start(viewmenu, True, True, 0)
184
        viewsbox.pack_start(viewmenu, True, True, 0)
175
        vwp.add(viewsbox)
185
        vwp.add(viewsbox)
176
        scr.add(vwp)
186
        scr.add(vwp)
177
        box_trv.pack_start(scr, True, True, 0)
187
        box_trv.pack_start(scr, True, True, 0)
178
        box.pack_start(box_trv, True, True, 0)
188
        box.pack_start(box_trv, True, True, 0)
Line 185... Line 195...
185
    def setup_visor(self):
195
    def setup_visor(self):
186
        visor = Gtk.VBox()
196
        visor = Gtk.VBox()
187
        scr = Gtk.ScrolledWindow()
197
        scr = Gtk.ScrolledWindow()
188
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
198
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
189
        scr.set_shadow_type(Gtk.ShadowType.IN)
199
        scr.set_shadow_type(Gtk.ShadowType.IN)
190
        self.treeview = Gtk.TreeView()
-
 
191
        scr.add(self.treeview)
-
 
-
 
200
        treeview = self.srvgui.add_widget('visor_sapnotes_treeview', Gtk.TreeView())
-
 
201
        scr.add(treeview)
192
        visor.pack_start(scr, True, True, 0)
202
        visor.pack_start(scr, True, True, 0)
193
        visor.show_all()
203
        visor.show_all()
194
204
195
        # Setup model
205
        # Setup model
196
        self.model = Gtk.ListStore(
-
 
-
 
206
        model = Gtk.ListStore(
197
            int,        # key
207
            int,        # key
198
            Pixbuf,     # Icon
208
            Pixbuf,     # Icon
199
            int,        # checkbox
209
            int,        # checkbox
200
            str,        # sid
210
            str,        # sid
201
            str,        # title
211
            str,        # title
202
            str,        # component
212
            str,        # component
203
            str,        # category
213
            str,        # category
204
            str,        # type
214
            str,        # type
205
            str,        # priority
215
            str,        # priority
206
            str,        # last update
216
            str,        # last update
207
            str,        # Annotation Id (extra key)
-
 
208
            str,        # Timestamp
217
            str,        # Timestamp
209
        )
218
        )
-
 
219
        self.srvgui.add_widget('gtk_model_sapnotes', model)
210
220
211
        # Setup columns
221
        # Setup columns
212
        def get_column_header_widget(title, icon_name=None, width=28, height=28):
222
        def get_column_header_widget(title, icon_name=None, width=28, height=28):
213
            hbox = Gtk.HBox()
223
            hbox = Gtk.HBox()
214
            icon = self.srvicm.get_new_image_icon(icon_name, width, height)
224
            icon = self.srvicm.get_new_image_icon(icon_name, width, height)
Line 221... Line 231...
221
            return hbox
231
            return hbox
222
232
223
        # SAP Note key
233
        # SAP Note key
224
        self.renderer_key = Gtk.CellRendererText()
234
        self.renderer_key = Gtk.CellRendererText()
225
        self.renderer_key.set_property('height', 32)
235
        self.renderer_key.set_property('height', 32)
226
        self.column_key = Gtk.TreeViewColumn('Key', self.renderer_key, text=0)
-
 
-
 
236
        self.column_key = Gtk.TreeViewColumn('Key', self.renderer_key, text=COLUMN.KEY)
227
        self.column_key.set_visible(False)
237
        self.column_key.set_visible(False)
228
        self.column_key.set_expand(False)
238
        self.column_key.set_expand(False)
229
        self.column_key.set_clickable(False)
239
        self.column_key.set_clickable(False)
230
        self.column_key.set_sort_indicator(False)
240
        self.column_key.set_sort_indicator(False)
231
        self.treeview.append_column(self.column_key)
-
 
-
 
241
        treeview.append_column(self.column_key)
232
242
233
        # Icon
243
        # Icon
234
        self.renderer_icon = Gtk.CellRendererPixbuf()
244
        self.renderer_icon = Gtk.CellRendererPixbuf()
235
        self.renderer_icon.set_alignment(0.0, 0.5)
245
        self.renderer_icon.set_alignment(0.0, 0.5)
236
        self.column_icon = Gtk.TreeViewColumn('', self.renderer_icon, pixbuf=1)
-
 
-
 
246
        self.column_icon = Gtk.TreeViewColumn('', self.renderer_icon, pixbuf=COLUMN.ICON)
237
        # ~ widget = get_column_header_widget('', '')
247
        # ~ widget = get_column_header_widget('', '')
238
        # ~ self.column_icon.set_widget(widget)
248
        # ~ self.column_icon.set_widget(widget)
239
        self.column_icon.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
249
        self.column_icon.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
240
        self.column_icon.set_visible(True)
250
        self.column_icon.set_visible(True)
241
        self.column_icon.set_expand(False)
251
        self.column_icon.set_expand(False)
242
        self.column_icon.set_clickable(False)
-
 
243
        self.column_icon.set_sort_indicator(False)
-
 
244
        self.treeview.append_column(self.column_icon)
-
 
-
 
252
        self.column_icon.set_clickable(True)
-
 
253
        self.column_icon.set_sort_indicator(True)
-
 
254
        self.column_icon.set_sort_column_id(COLUMN.TYPE)
-
 
255
        self.column_icon.set_sort_order(Gtk.SortType.ASCENDING)
-
 
256
        treeview.append_column(self.column_icon)
245
257
246
        # SAP Note Checkbox
258
        # SAP Note Checkbox
247
        self.renderer_checkbox = Gtk.CellRendererToggle()
259
        self.renderer_checkbox = Gtk.CellRendererToggle()
248
        self.renderer_checkbox.connect("toggled", self.__clb_row_toggled)
260
        self.renderer_checkbox.connect("toggled", self.__clb_row_toggled)
249
        self.column_checkbox = Gtk.TreeViewColumn('', self.renderer_checkbox, active=2)
-
 
-
 
261
        self.column_checkbox = Gtk.TreeViewColumn('', self.renderer_checkbox, active=COLUMN.CHECKBOX)
250
        widget = get_column_header_widget('', 'basico-check-accept')
262
        widget = get_column_header_widget('', 'basico-check-accept')
251
        self.column_checkbox.set_widget(widget)
263
        self.column_checkbox.set_widget(widget)
252
        self.column_checkbox.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
264
        self.column_checkbox.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
253
        self.column_checkbox.set_visible(True)
265
        self.column_checkbox.set_visible(True)
254
        self.column_checkbox.set_expand(False)
266
        self.column_checkbox.set_expand(False)
255
        self.column_checkbox.set_clickable(True)
267
        self.column_checkbox.set_clickable(True)
256
        self.column_checkbox.set_sort_indicator(False)
268
        self.column_checkbox.set_sort_indicator(False)
257
        self.column_checkbox.set_property('spacing', 50)
269
        self.column_checkbox.set_property('spacing', 50)
258
        self.treeview.append_column(self.column_checkbox)
-
 
-
 
270
        treeview.append_column(self.column_checkbox)
259
271
260
        # SAP Note Id
272
        # SAP Note Id
261
        self.renderer_sid = Gtk.CellRendererText()
273
        self.renderer_sid = Gtk.CellRendererText()
262
        self.renderer_sid.set_property('xalign', 1.0)
274
        self.renderer_sid.set_property('xalign', 1.0)
263
        self.renderer_sid.set_property('height', 36)
275
        self.renderer_sid.set_property('height', 36)
264
        self.renderer_sid.set_property('background', '#F0E3E3')
276
        self.renderer_sid.set_property('background', '#F0E3E3')
265
        self.column_sid = Gtk.TreeViewColumn('SAP Note', self.renderer_sid, markup=3)
-
 
-
 
277
        self.column_sid = Gtk.TreeViewColumn('SAP Note', self.renderer_sid, markup=COLUMN.SID)
266
        # ~ widget = get_column_header_widget('SAP Note', 'basico-sapnote')
278
        # ~ widget = get_column_header_widget('SAP Note', 'basico-sapnote')
267
        # ~ self.column_sid.set_widget(widget)
279
        # ~ self.column_sid.set_widget(widget)
268
        self.column_sid.set_visible(True)
280
        self.column_sid.set_visible(True)
269
        self.column_sid.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
281
        self.column_sid.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
270
        self.column_sid.set_expand(False)
282
        self.column_sid.set_expand(False)
271
        self.column_sid.set_clickable(True)
283
        self.column_sid.set_clickable(True)
272
        self.column_sid.set_sort_indicator(True)
284
        self.column_sid.set_sort_indicator(True)
273
        self.column_sid.set_sort_column_id(0)
-
 
-
 
285
        self.column_sid.set_sort_column_id(COLUMN.SID)
274
        self.column_sid.set_sort_order(Gtk.SortType.ASCENDING)
286
        self.column_sid.set_sort_order(Gtk.SortType.ASCENDING)
275
        self.model.set_sort_column_id(0, Gtk.SortType.ASCENDING)
-
 
276
        self.treeview.append_column(self.column_sid)
-
 
-
 
287
        # ~ model.set_sort_column_id(0, Gtk.SortType.ASCENDING)
-
 
288
        treeview.append_column(self.column_sid)
277
289
278
        # SAP Note title
290
        # SAP Note title
279
        self.renderer_title = Gtk.CellRendererText()
291
        self.renderer_title = Gtk.CellRendererText()
280
        self.renderer_title.set_property('background', '#FFFEEA')
292
        self.renderer_title.set_property('background', '#FFFEEA')
281
        self.renderer_title.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
293
        self.renderer_title.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
282
        self.column_title = Gtk.TreeViewColumn('Title', self.renderer_title, markup=4)
-
 
-
 
294
        self.column_title = Gtk.TreeViewColumn('Title', self.renderer_title, markup=COLUMN.TITLE)
283
        widget = get_column_header_widget('Title', 'basico-tag')
295
        widget = get_column_header_widget('Title', 'basico-tag')
284
        self.column_title.set_widget(widget)
296
        self.column_title.set_widget(widget)
285
        self.column_title.set_visible(True)
297
        self.column_title.set_visible(True)
286
        self.column_title.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
298
        self.column_title.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
287
        self.column_title.set_expand(True)
299
        self.column_title.set_expand(True)
288
        self.column_title.set_clickable(True)
300
        self.column_title.set_clickable(True)
289
        self.column_title.set_sort_indicator(True)
301
        self.column_title.set_sort_indicator(True)
290
        self.column_title.set_sort_column_id(4)
-
 
291
        self.treeview.append_column(self.column_title)
-
 
-
 
302
        self.column_title.set_sort_column_id(COLUMN.TITLE)
-
 
303
        treeview.append_column(self.column_title)
292
304
293
        # SAP Note Component
305
        # SAP Note Component
294
        self.renderer_component = Gtk.CellRendererText()
306
        self.renderer_component = Gtk.CellRendererText()
295
        self.renderer_component.set_property('background', '#E3E3F0')
307
        self.renderer_component.set_property('background', '#E3E3F0')
296
        self.column_component = Gtk.TreeViewColumn('Component', self.renderer_component, markup=5)
-
 
-
 
308
        self.column_component = Gtk.TreeViewColumn('Component', self.renderer_component, markup=COLUMN.COMPONENT)
297
        widget = get_column_header_widget('Component', 'basico-component')
309
        widget = get_column_header_widget('Component', 'basico-component')
298
        self.column_component.set_widget(widget)
310
        self.column_component.set_widget(widget)
299
        self.column_component.set_visible(True)
311
        self.column_component.set_visible(True)
300
        self.column_component.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
312
        self.column_component.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
301
        self.column_component.set_expand(False)
313
        self.column_component.set_expand(False)
302
        self.column_component.set_clickable(True)
314
        self.column_component.set_clickable(True)
303
        self.column_component.set_sort_indicator(True)
315
        self.column_component.set_sort_indicator(True)
304
        self.column_component.set_sort_column_id(5)
-
 
305
        self.treeview.append_column(self.column_component)
-
 
-
 
316
        self.column_component.set_sort_column_id(COLUMN.COMPONENT)
-
 
317
        treeview.append_column(self.column_component)
306
318
307
        # SAP Note Category
319
        # SAP Note Category
308
        self.renderer_category = Gtk.CellRendererText()
320
        self.renderer_category = Gtk.CellRendererText()
309
        self.renderer_category.set_property('background', '#E3F1E3')
321
        self.renderer_category.set_property('background', '#E3F1E3')
310
        self.column_category = Gtk.TreeViewColumn('Category', self.renderer_category, markup=6)
-
 
-
 
322
        self.column_category = Gtk.TreeViewColumn('Category', self.renderer_category, markup=COLUMN.CATEGORY)
311
        widget = get_column_header_widget('Category', 'basico-category')
323
        widget = get_column_header_widget('Category', 'basico-category')
312
        self.column_category.set_widget(widget)
324
        self.column_category.set_widget(widget)
313
        self.column_category.set_visible(False)
325
        self.column_category.set_visible(False)
314
        self.column_category.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
326
        self.column_category.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
315
        self.column_category.set_expand(False)
327
        self.column_category.set_expand(False)
316
        self.column_category.set_clickable(True)
328
        self.column_category.set_clickable(True)
317
        self.column_category.set_sort_indicator(True)
329
        self.column_category.set_sort_indicator(True)
318
        self.column_category.set_sort_column_id(6)
-
 
319
        self.treeview.append_column(self.column_category)
-
 
-
 
330
        self.column_category.set_sort_column_id(COLUMN.CATEGORY)
-
 
331
        treeview.append_column(self.column_category)
320
332
321
        # SAP Note Type
333
        # SAP Note Type
322
        self.renderer_type = Gtk.CellRendererText()
334
        self.renderer_type = Gtk.CellRendererText()
323
        self.renderer_type.set_property('background', '#e4f1f1')
335
        self.renderer_type.set_property('background', '#e4f1f1')
324
        self.column_type = Gtk.TreeViewColumn('Type', self.renderer_type, markup=7)
-
 
-
 
336
        self.column_type = Gtk.TreeViewColumn('Type', self.renderer_type, markup=COLUMN.TYPE)
325
        widget = get_column_header_widget('Type', 'basico-type')
337
        widget = get_column_header_widget('Type', 'basico-type')
326
        self.column_type.set_widget(widget)
338
        self.column_type.set_widget(widget)
327
        self.column_type.set_visible(True)
339
        self.column_type.set_visible(True)
328
        self.column_type.set_expand(False)
340
        self.column_type.set_expand(False)
329
        self.column_type.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
341
        self.column_type.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
330
        self.column_type.set_clickable(True)
342
        self.column_type.set_clickable(True)
331
        self.column_type.set_sort_indicator(True)
343
        self.column_type.set_sort_indicator(True)
332
        self.column_type.set_sort_column_id(7)
-
 
333
        self.treeview.append_column(self.column_type)
-
 
-
 
344
        self.column_type.set_sort_column_id(COLUMN.TYPE)
-
 
345
        treeview.append_column(self.column_type)
334
346
335
        # SAP Note Priority
347
        # SAP Note Priority
336
        self.renderer_priority = Gtk.CellRendererText()
348
        self.renderer_priority = Gtk.CellRendererText()
337
        self.column_priority = Gtk.TreeViewColumn('Priority', self.renderer_priority, markup=8)
-
 
-
 
349
        self.column_priority = Gtk.TreeViewColumn('Priority', self.renderer_priority, markup=COLUMN.PRIORITY)
338
        widget = get_column_header_widget('Type', 'basico-priority')
350
        widget = get_column_header_widget('Type', 'basico-priority')
339
        self.column_priority.set_widget(widget)
351
        self.column_priority.set_widget(widget)
340
        self.column_priority.set_visible(False)
352
        self.column_priority.set_visible(False)
341
        self.column_priority.set_expand(True)
353
        self.column_priority.set_expand(True)
342
        self.column_priority.set_clickable(True)
354
        self.column_priority.set_clickable(True)
343
        self.column_priority.set_sort_indicator(True)
355
        self.column_priority.set_sort_indicator(True)
344
        self.column_priority.set_sort_column_id(8)
-
 
345
        self.treeview.append_column(self.column_priority)
-
 
-
 
356
        self.column_priority.set_sort_column_id(COLUMN.PRIORITY)
-
 
357
        treeview.append_column(self.column_priority)
346
358
347
        # SAP Note UpdatedOn
359
        # SAP Note UpdatedOn
348
        self.renderer_updated = Gtk.CellRendererText()
360
        self.renderer_updated = Gtk.CellRendererText()
349
        self.renderer_updated.set_property('background', '#FFE6D1')
361
        self.renderer_updated.set_property('background', '#FFE6D1')
350
        self.column_updated = Gtk.TreeViewColumn('Updated', self.renderer_updated, markup=9)
-
 
-
 
362
        self.column_updated = Gtk.TreeViewColumn('Updated', self.renderer_updated, markup=COLUMN.UPDATED)
351
        widget = get_column_header_widget('Updated', 'basico-chronologic')
363
        widget = get_column_header_widget('Updated', 'basico-chronologic')
352
        self.column_updated.set_widget(widget)
364
        self.column_updated.set_widget(widget)
353
        self.column_updated.set_visible(True)
365
        self.column_updated.set_visible(True)
354
        self.column_updated.set_expand(False)
366
        self.column_updated.set_expand(False)
355
        self.column_updated.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
367
        self.column_updated.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
356
        self.column_updated.set_clickable(True)
368
        self.column_updated.set_clickable(True)
357
        self.column_updated.set_sort_indicator(True)
369
        self.column_updated.set_sort_indicator(True)
358
        self.column_updated.set_sort_column_id(11)
-
 
359
        self.treeview.append_column(self.column_updated)
-
 
360
-
 
361
        # Annotation Id
-
 
362
        self.renderer_annotation = Gtk.CellRendererText()
-
 
363
        self.column_annotation = Gtk.TreeViewColumn('Annotation Id', self.renderer_annotation, markup=10)
-
 
364
        self.column_annotation.set_visible(False)
-
 
365
        self.column_annotation.set_expand(False)
-
 
366
        self.column_annotation.set_clickable(False)
-
 
367
        self.column_annotation.set_sort_indicator(False)
-
 
368
        self.treeview.append_column(self.column_annotation)
-
 
-
 
370
        self.column_updated.set_sort_column_id(COLUMN.TS_UPDATED)
-
 
371
        treeview.append_column(self.column_updated)
369
372
370
        # Timestamp
373
        # Timestamp
371
        self.renderer_timestamp = Gtk.CellRendererText()
374
        self.renderer_timestamp = Gtk.CellRendererText()
372
        self.column_timestamp = Gtk.TreeViewColumn('Annotation Id', self.renderer_timestamp, text=11)
-
 
-
 
375
        self.column_timestamp = Gtk.TreeViewColumn('Annotation Id', self.renderer_timestamp, text=COLUMN.TS_UPDATED)
373
        self.column_timestamp.set_visible(False)
376
        self.column_timestamp.set_visible(False)
374
        self.column_timestamp.set_expand(False)
377
        self.column_timestamp.set_expand(False)
375
        self.column_timestamp.set_clickable(False)
378
        self.column_timestamp.set_clickable(False)
376
        self.column_timestamp.set_sort_indicator(False)
379
        self.column_timestamp.set_sort_indicator(False)
377
        self.treeview.append_column(self.column_timestamp)
-
 
-
 
380
        treeview.append_column(self.column_timestamp)
378
381
379
        # Treeview properties
382
        # Treeview properties
380
        self.treeview.set_can_focus(False)
-
 
381
        self.treeview.set_enable_tree_lines(True)
-
 
382
        self.treeview.set_headers_visible(True)
-
 
383
        self.treeview.set_enable_search(True)
-
 
384
        self.treeview.set_hover_selection(False)
-
 
385
        self.treeview.set_grid_lines(Gtk.TreeViewGridLines.HORIZONTAL)
-
 
386
        self.treeview.set_enable_tree_lines(True)
-
 
387
        self.treeview.set_level_indentation(10)
-
 
388
        # ~ self.treeview.modify_font(Pango.FontDescription('Monospace 10'))
-
 
389
        self.treeview.connect('button_press_event', self.right_click)
-
 
-
 
383
        treeview.set_can_focus(False)
-
 
384
        treeview.set_enable_tree_lines(True)
-
 
385
        treeview.set_headers_visible(True)
-
 
386
        treeview.set_enable_search(True)
-
 
387
        treeview.set_hover_selection(False)
-
 
388
        treeview.set_grid_lines(Gtk.TreeViewGridLines.HORIZONTAL)
-
 
389
        treeview.set_enable_tree_lines(True)
-
 
390
        treeview.set_level_indentation(10)
-
 
391
        # ~ treeview.modify_font(Pango.FontDescription('Monospace 10'))
-
 
392
        treeview.connect('button_press_event', self.right_click)
390
393
391
        # DOC: In order to have a Gtk.Widged with sorting and filtering
394
        # DOC: In order to have a Gtk.Widged with sorting and filtering
392
        # capabilities, you have to filter the model first, and use this
395
        # capabilities, you have to filter the model first, and use this
393
        # new model to create the sorted model. Then, attach the sorted
396
        # new model to create the sorted model. Then, attach the sorted
394
        # model to the treeview...
397
        # model to the treeview...
395
398
396
        # Treeview filtering:
399
        # Treeview filtering:
397
        self.visible_filter = self.model.filter_new()
-
 
-
 
400
        self.visible_filter = model.filter_new()
398
        self.visible_filter.set_visible_func(self.visible_function)
401
        self.visible_filter.set_visible_func(self.visible_function)
399
        # https://stackoverflow.com/questions/23355866/user-search-collapsed-rows-in-a-gtk-treeview
402
        # https://stackoverflow.com/questions/23355866/user-search-collapsed-rows-in-a-gtk-treeview
400
403
401
        # TreeView sorting
404
        # TreeView sorting
402
        sorted_model = Gtk.TreeModelSort(model=self.visible_filter)
405
        sorted_model = Gtk.TreeModelSort(model=self.visible_filter)
403
        self.srvgui.add_widget('visor_sapnotes_sorted_model', sorted_model)
406
        self.srvgui.add_widget('visor_sapnotes_sorted_model', sorted_model)
404
        sorted_model.set_sort_func(0, self.sort_function, None)
407
        sorted_model.set_sort_func(0, self.sort_function, None)
405
408
406
        # Selection
409
        # Selection
407
        self.selection = self.treeview.get_selection()
-
 
-
 
410
        self.selection = treeview.get_selection()
408
        self.selection.set_mode(Gtk.SelectionMode.SINGLE)
411
        self.selection.set_mode(Gtk.SelectionMode.SINGLE)
409
        self.selection.connect('changed', self.row_changed)
412
        self.selection.connect('changed', self.row_changed)
410
413
411
        # Set model (filtered and sorted)
414
        # Set model (filtered and sorted)
412
        self.treeview.set_model(sorted_model)
-
 
-
 
415
        treeview.set_model(sorted_model)
413
416
414
        self.show_all()
417
        self.show_all()
415
        return visor
418
        return visor
416
419
417
420
Line 434... Line 437...
434
437
435
438
436
    def visible_function(self, model, itr, data):
439
    def visible_function(self, model, itr, data):
437
        entry = self.srvgui.get_widget('gtk_entry_filter_visor')
440
        entry = self.srvgui.get_widget('gtk_entry_filter_visor')
438
        text = self.srvutl.clean_html(entry.get_text())
441
        text = self.srvutl.clean_html(entry.get_text())
439
        title = model.get(itr, 4)[0]
-
 
440
        component = model.get(itr, 5)[0]
-
 
-
 
442
        title = model.get(itr, COLUMN.TITLE)[0]
-
 
443
        component = model.get(itr, COLUMN.COMPONENT)[0]
441
        fields = title + ' ' + component
444
        fields = title + ' ' + component
442
        match = text.upper() in fields.upper()
445
        match = text.upper() in fields.upper()
443
446
444
        return match
447
        return match
445
448
Line 447... Line 450...
447
    def update_total_sapnotes_count(self):
450
    def update_total_sapnotes_count(self):
448
        statusbar = self.srvgui.get_widget('widget_statusbar')
451
        statusbar = self.srvgui.get_widget('widget_statusbar')
449
        lblnotescount = self.srvgui.get_widget('gtk_label_total_notes')
452
        lblnotescount = self.srvgui.get_widget('gtk_label_total_notes')
450
        total = self.srvdtb.get_total()
453
        total = self.srvdtb.get_total()
451
        count = len(self.visible_filter)
454
        count = len(self.visible_filter)
452
        lblnotescount.set_markup("<b>%d/<big>%d SAP Notes</big></b>" % (count, total))
-
 
-
 
455
        lblnotescount.set_markup("<b>%d/<big>%d</big></b>" % (count, total))
453
        msg = 'View populated with %d SAP Notes' % count
456
        msg = 'View populated with %d SAP Notes' % count
454
        self.srvuif.statusbar_msg(msg)
457
        self.srvuif.statusbar_msg(msg)
455
458
456
459
457
    def get_visible_filter(self):
460
    def get_visible_filter(self):
458
        return self.visible_filter
461
        return self.visible_filter
459
462
460
463
461
    def row_changed(self, selection):
464
    def row_changed(self, selection):
462
        try:
-
 
463
            model, treeiter = selection.get_selected()
-
 
464
            if treeiter is not None:
-
 
465
                component = model[treeiter][5]
-
 
466
                if component == 'Annotation':
-
 
467
                    aid = model[treeiter][10]
-
 
468
                    is_valid = self.srvant.is_valid(aid)
-
 
469
                    if is_valid:
-
 
470
                        self.srvclb.action_annotation_edit(aid)
-
 
471
                else:
-
 
472
                    aid = None
-
 
473
                    # ~ self.srvuif.set_widget_visibility('gtk_vbox_container_annotations', False)
-
 
474
        except Exception as error:
-
 
475
            self.log.debug(error)
-
 
-
 
465
        pass
-
 
466
        # ~ try:
-
 
467
            # ~ model, treeiter = selection.get_selected()
-
 
468
            # ~ if treeiter is not None:
-
 
469
                # ~ component = model[treeiter][5]
-
 
470
                # ~ if component == 'Annotation':
-
 
471
                    # ~ aid = model[treeiter][10]
-
 
472
                    # ~ is_valid = self.srvant.is_valid(aid)
-
 
473
                    # ~ if is_valid:
-
 
474
                        # ~ self.srvclb.action_annotation_edit(aid)
-
 
475
                # ~ else:
-
 
476
                    # ~ aid = None
-
 
477
        # ~ except Exception as error:
-
 
478
            # ~ self.log.debug(error)
476
479
477
480
478
    def __clb_row_toggled(self, cell, path):
481
    def __clb_row_toggled(self, cell, path):
479
        sorted_model = self.srvgui.get_widget('visor_sapnotes_sorted_model')
482
        sorted_model = self.srvgui.get_widget('visor_sapnotes_sorted_model')
480
        model = sorted_model.get_model()
483
        model = sorted_model.get_model()
481
        rpath = sorted_model.convert_path_to_child_path(Gtk.TreePath(path))
484
        rpath = sorted_model.convert_path_to_child_path(Gtk.TreePath(path))
482
        model[rpath][2] = not model[rpath][2]
-
 
-
 
485
        model[rpath][COLUMN.CHECKBOX] = not model[rpath][COLUMN.CHECKBOX]
483
486
484
487
485
    def get_node(self, key, icon, checkbox, sid, title, component, category='', sntype='', priority='', updated='', aid='', timestamp=''):
488
    def get_node(self, key, icon, checkbox, sid, title, component, category='', sntype='', priority='', updated='', aid='', timestamp=''):
486
        # Add completion entries
489
        # Add completion entries
487
        completion = self.srvgui.get_widget('gtk_entrycompletion_visor')
490
        completion = self.srvgui.get_widget('gtk_entrycompletion_visor')
Line 498... Line 501...
498
        node.append(component)
501
        node.append(component)
499
        node.append(category)
502
        node.append(category)
500
        node.append(sntype)
503
        node.append(sntype)
501
        node.append(priority)
504
        node.append(priority)
502
        node.append(updated)
505
        node.append(updated)
503
        node.append(aid) # Extra key for annotations id (aid)
-
 
504
        node.append(timestamp)
506
        node.append(timestamp)
505
        return node
507
        return node
506
-
 
507
-
 
508
    def get_model(self):
-
 
509
        return self.model
-
 
510
-
 
511
-
 
512
    def get_sorted_model(self):
-
 
513
        return self.sorted_model
-
 
514
508
515
509
516
    def get_bag(self):
510
    def get_bag(self):
517
        return self.bag
511
        return self.bag
518
512
Line 520... Line 514...
520
    def reload(self):
514
    def reload(self):
521
        self.populate(self.bag)
515
        self.populate(self.bag)
522
516
523
517
524
    def populate(self, bag=None, cid=None):
518
    def populate(self, bag=None, cid=None):
-
 
519
        self.log.debug("Hello")
-
 
520
        model = self.srvgui.get_widget('gtk_model_sapnotes')
525
        sorted_model = self.srvgui.get_widget('visor_sapnotes_sorted_model')
521
        sorted_model = self.srvgui.get_widget('visor_sapnotes_sorted_model')
526
        icon_sapnote = self.srvicm.get_pixbuf_icon('basico-sapnote', 32, 32)
522
        icon_sapnote = self.srvicm.get_pixbuf_icon('basico-sapnote', 32, 32)
527
        # ~ icon_sap_note = self.srvicm.get_pixbuf_icon('basico-sap-note', 32, 32)
523
        # ~ icon_sap_note = self.srvicm.get_pixbuf_icon('basico-sap-note', 32, 32)
528
        # ~ icon_sap_note_standard = self.srvicm.get_pixbuf_icon('basico-sap-note', 32, 32)
524
        # ~ icon_sap_note_standard = self.srvicm.get_pixbuf_icon('basico-sap-note', 32, 32)
529
        icon_bookmark = self.srvicm.get_pixbuf_icon('basico-bookmarks', 32, 32)
525
        icon_bookmark = self.srvicm.get_pixbuf_icon('basico-bookmarks', 32, 32)
Line 534... Line 530...
534
        # ~ self.column_category.set_visible(False)
530
        # ~ self.column_category.set_visible(False)
535
        # ~ self.column_component.set_visible(True)
531
        # ~ self.column_component.set_visible(True)
536
        completion = self.srvgui.get_widget('gtk_entrycompletion_visor')
532
        completion = self.srvgui.get_widget('gtk_entrycompletion_visor')
537
        completion_model = completion.get_model()
533
        completion_model = completion.get_model()
538
        completion_model.clear()
534
        completion_model.clear()
539
        self.model.clear()
-
 
540
-
 
-
 
535
        model.clear()
541
        if bag is None:
536
        if bag is None:
542
            bag = self.bag
537
            bag = self.bag
543
        else:
538
        else:
544
            self.bag = bag
539
            self.bag = bag
545
-
 
546
540
547
        for sid in self.bag:
541
        for sid in self.bag:
548
            metadata = self.srvdtb.get_sapnote_metadata(sid)
542
            metadata = self.srvdtb.get_sapnote_metadata(sid)
549
            if metadata is not None:
543
            if metadata is not None:
550
                # ~ self.log.debug("%s:\n%s", sid, metadata)
544
                # ~ self.log.debug("%s:\n%s", sid, metadata)
Line 573... Line 567...
573
                timestamp = timestamp.replace('-', '')
567
                timestamp = timestamp.replace('-', '')
574
                timestamp = timestamp.replace(':', '')
568
                timestamp = timestamp.replace(':', '')
575
                timestamp = timestamp.replace('T', '_')
569
                timestamp = timestamp.replace('T', '_')
576
                stype = escape(metadata['type'].lower())
570
                stype = escape(metadata['type'].lower())
577
                icon_name = 'basico-%s' % stype.replace(' ', '-')
571
                icon_name = 'basico-%s' % stype.replace(' ', '-')
578
                self.log.debug(icon_name)
-
 
-
 
572
                # ~ self.log.debug(icon_name)
579
                icon = self.srvicm.get_pixbuf_icon(icon_name, 36, 36)
573
                icon = self.srvicm.get_pixbuf_icon(icon_name, 36, 36)
580
                self.log.debug(icon)
-
 
-
 
574
                # ~ self.log.debug(icon)
581
                # ~ self.log.debug(icon_name)
575
                # ~ self.log.debug(icon_name)
582
                icon_name = None
576
                icon_name = None
583
                node = self.get_node(   int(metadata['id']),
577
                node = self.get_node(   int(metadata['id']),
584
                                        icon,
578
                                        icon,
585
                                        False,
579
                                        False,
Line 588... Line 582...
588
                                        escape(metadata['componentkey']),
582
                                        escape(metadata['componentkey']),
589
                                        escape(metadata['category']),
583
                                        escape(metadata['category']),
590
                                        escape(metadata['type']),
584
                                        escape(metadata['type']),
591
                                        escape(metadata['priority']),
585
                                        escape(metadata['priority']),
592
                                        self.srvutl.fuzzy_date_from_timestamp(timestamp),
586
                                        self.srvutl.fuzzy_date_from_timestamp(timestamp),
593
                                        '',
-
 
594
                                        timestamp
587
                                        timestamp
595
                                    )
588
                                    )
596
                pid = self.model.append(node)
-
 
-
 
589
                pid = model.append(node)
597
590
598
                # Load annotations
591
                # Load annotations
599
                # ~ files = self.srvant.get_by_sid(metadata['id'])
592
                # ~ files = self.srvant.get_by_sid(metadata['id'])
600
                # ~ for fname in files:
593
                # ~ for fname in files:
601
                    # ~ with open(fname, 'r') as fa:
594
                    # ~ with open(fname, 'r') as fa:
Line 616... Line 609...
616
                                                # ~ '',
609
                                                # ~ '',
617
                                                # ~ self.srvutl.fuzzy_date_from_timestamp(annotation['Timestamp']),
610
                                                # ~ self.srvutl.fuzzy_date_from_timestamp(annotation['Timestamp']),
618
                                                # ~ annotation['AID'],
611
                                                # ~ annotation['AID'],
619
                                                # ~ annotation['Timestamp']
612
                                                # ~ annotation['Timestamp']
620
                                            # ~ )
613
                                            # ~ )
621
                        # ~ self.model.append(pid, node)
-
 
-
 
614
                        # ~ model.append(pid, node)
622
615
623
                # Load attachments
616
                # Load attachments
624
                # ~ files = self.srvatc.get_by_sid(metadata['id'])
617
                # ~ files = self.srvatc.get_by_sid(metadata['id'])
625
                # ~ for fname in files:
618
                # ~ for fname in files:
626
                    # ~ with open(fname, 'r') as ft:
619
                    # ~ with open(fname, 'r') as ft:
Line 637... Line 630...
637
                                                # ~ '',
630
                                                # ~ '',
638
                                                # ~ self.srvutl.fuzzy_date_from_timestamp(attachment['Created']),
631
                                                # ~ self.srvutl.fuzzy_date_from_timestamp(attachment['Created']),
639
                                                # ~ attachment['TID'],
632
                                                # ~ attachment['TID'],
640
                                                # ~ attachment['Created']
633
                                                # ~ attachment['Created']
641
                                            # ~ )
634
                                            # ~ )
642
                        # ~ self.model.append(pid, node)
-
 
643
-
 
644
        self.treeview.set_model(sorted_model)
-
 
-
 
635
                        # ~ model.append(pid, node)
-
 
636
        treeview = self.srvgui.get_widget('visor_sapnotes_treeview')
-
 
637
        treeview.set_model(sorted_model)
645
        self.update_total_sapnotes_count()
638
        self.update_total_sapnotes_count()
646
        self.show_widgets()
639
        self.show_widgets()
647
        self.srvclb.gui_show_dashboard()
640
        self.srvclb.gui_show_dashboard()
648
        # ~ stack = self.srvgui.get_widget('gtk_stack_main')
641
        # ~ stack = self.srvgui.get_widget('gtk_stack_main')
649
        # ~ stack.set_visible_child_name('dashboard')
642
        # ~ stack.set_visible_child_name('dashboard')
Line 652... Line 645...
652
    def show_widgets(self):
645
    def show_widgets(self):
653
        self.srvuif.set_widget_visibility('gtk_label_total_notes', True)
646
        self.srvuif.set_widget_visibility('gtk_label_total_notes', True)
654
647
655
648
656
    def right_click(self, treeview, event, data=None):
649
    def right_click(self, treeview, event, data=None):
-
 
650
        treeview = self.srvgui.get_widget('visor_sapnotes_treeview')
657
        if event.button == 3:
651
        if event.button == 3:
658
            rect = Gdk.Rectangle()
652
            rect = Gdk.Rectangle()
659
            rect.x = x = int(event.x)
653
            rect.x = x = int(event.x)
660
            rect.y = y = int(event.y)
654
            rect.y = y = int(event.y)
661
            pthinfo = self.treeview.get_path_at_pos(x,y)
-
 
-
 
655
            pthinfo = treeview.get_path_at_pos(x,y)
662
            if pthinfo is not None:
656
            if pthinfo is not None:
663
                path,col,cellx,celly = pthinfo
657
                path,col,cellx,celly = pthinfo
664
                model = treeview.get_model()
658
                model = treeview.get_model()
665
                treeiter = model.get_iter(path)
659
                treeiter = model.get_iter(path)
666
                component = model[treeiter][5]
-
 
667
                sid = model[treeiter][0]
-
 
-
 
660
                component = model[treeiter][COLUMN.COMPONENT]
-
 
661
                sid = model[treeiter][COLUMN.KEY]
668
                if sid == 0:
662
                if sid == 0:
669
                    return
663
                    return
670
                sid = "0"*(10 - len(str(sid))) + str(sid)
664
                sid = "0"*(10 - len(str(sid))) + str(sid)
671
                # ~ toolbar = self.srvgui.get_widget('visortoolbar')
665
                # ~ toolbar = self.srvgui.get_widget('visortoolbar')
672
                popover = self.srvgui.add_widget('gtk_popover_visor_row', Gtk.Popover.new(treeview))
666
                popover = self.srvgui.add_widget('gtk_popover_visor_row', Gtk.Popover.new(treeview))
Line 800... Line 794...
800
        sorted_model = self.srvgui.get_widget('visor_sapnotes_sorted_model')
794
        sorted_model = self.srvgui.get_widget('visor_sapnotes_sorted_model')
801
        visor_sapnotes = self.srvgui.get_widget('visor_sapnotes')
795
        visor_sapnotes = self.srvgui.get_widget('visor_sapnotes')
802
        selected = []
796
        selected = []
803
797
804
        def get_selected_sapnotes(model, path, itr):
798
        def get_selected_sapnotes(model, path, itr):
805
            sid = model.get(itr, 0)[0]
-
 
806
            aid = model.get(itr, 10)[0]
-
 
-
 
799
            sid = model.get(itr, COLUMN.SID)[0]
807
            if len(aid) == 0:
800
            if len(aid) == 0:
808
                selected.append(str(sid))
801
                selected.append(str(sid))
809
802
810
        sorted_model.foreach(get_selected_sapnotes)
803
        sorted_model.foreach(get_selected_sapnotes)
811
        return selected
804
        return selected