Subversion Repositories basico

Rev

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

Rev Author Line No. Line
340 t00mlabs 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
"""
4
# File: mod_win.py
5
# Author: Tomás Vírseda
6
# License: GPL v3
7
# Description: Gtk.ApplicationWindow implementation
8
"""
9
 
10
import os
11
import sys
12
import stat
13
import time
14
import platform
15
 
16
import gi
17
gi.require_version('Gtk', '3.0')
18
 
19
from gi.repository import GLib
20
from gi.repository import GObject
21
from gi.repository import Gtk
22
from gi.repository import Gdk
23
from gi.repository import Gio
24
from gi.repository import Pango
25
from gi.repository.GdkPixbuf import Pixbuf
26
 
27
from basico.core.mod_srv import Service
28
from basico.core.mod_env import APP, FILE, ATYPES
29
from basico.widgets.wdg_menuview import MenuView
30
from basico.widgets.wdg_visor_sapnotes import SAPNotesVisor
31
from basico.widgets.wdg_visor_annotations import AnnotationsVisor
353 t00mlabs 32
from basico.widgets.wdg_visor_attachments import AttachmentsVisor
340 t00mlabs 33
from basico.widgets.wdg_visor_toolbar import VisorToolbar
34
from basico.widgets.wdg_about import About
35
from basico.widgets.wdg_settingsview import SettingsView
36
from basico.widgets.wdg_logviewer import LogViewer
37
from basico.widgets.wdg_annot import AnnotationWidget
38
from basico.widgets.wdg_statusbar import Statusbar
39
from basico.core.mod_log import get_logger
40
 
41
 
42
class GtkAppWindow(Gtk.ApplicationWindow, Service):
43
    def __init__(self, uiapp):
44
        self.setup_controller(uiapp)
45
        self.get_logger(__class__.__name__)
46
        self.get_services()
47
        self.srvgui.add_widget('uiapp', uiapp)
48
        self.app = self.srvgui.get_app()
49
        self.setup_window(uiapp)
361 t00mlabs 50
        self.setup_widgets()        
340 t00mlabs 51
        self.run()
52
 
53
 
54
    def get_services(self):
55
        self.srvbnr = self.controller.get_service("BNR")
56
        self.srvgui = self.controller.get_service("GUI")
57
        self.srvdtb = self.controller.get_service("DB")
58
        self.srvuif = self.controller.get_service("UIF")
59
        self.srvicm = self.controller.get_service('IM')
60
        self.srvclb = self.controller.get_service('Callbacks')
61
        self.srvant = self.controller.get_service('Annotation')
62
 
63
 
64
    def setup_controller(self, uiapp):
65
        self.controller = uiapp.get_controller()
66
 
67
 
68
    def setup_window(self, uiapp):
69
        Gtk.Window.__init__(self, title=APP['name'], application=uiapp)
70
        icon = self.srvicm.get_icon('basico-component', 48, 48)
71
        self.set_icon(icon)
72
        # FIXME
73
        # From docs: Don’t use this function. It sets the X xlib.Window
74
        # System “class” and “name” hints for a window.
75
        # But I have to do it or it doesn't shows the right title. ???
76
        self.set_wmclass (APP['name'], APP['name'])
77
        self.set_role(APP['name'])
78
        self.set_default_size(1024, 728)
79
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
348 t00mlabs 80
 
81
        self.log.debug(self.get_name())
82
        #FIX: hack to avoid white background in widgets within a notebook tab
83
        #FIXME: it should be managed by settings
84
        screen = Gdk.Screen.get_default()
85
        css_provider = Gtk.CssProvider()
86
        css_provider.load_from_path(FILE['CSS'])
87
        context = Gtk.StyleContext()
88
        context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
89
 
340 t00mlabs 90
        self.maximize ()
91
        self.setup_headerbar()
92
        self.show_all()
93
 
353 t00mlabs 94
 
340 t00mlabs 95
    def setup_headerbar(self):
96
        hb = self.srvgui.add_widget('gtk_headerbar_container', Gtk.HeaderBar())
97
        hb.set_show_close_button(True)
98
        hb.props.title = "Basico"
99
        hb.props.subtitle = "SAP Notes Manager for SAP Consultants"
100
        lhbox = self.setup_headerbar_left(hb)
101
        hb.pack_start(lhbox)
102
        rhbox = self.setup_headerbar_right(hb)
103
 
104
        hb.pack_end(rhbox)
105
        self.set_titlebar(hb)
106
        hb.show_all()
107
 
108
 
109
    def setup_headerbar_left(self, hb):
110
        # ~ '''Left headerbar side not used by now'''
111
        lhbox = Gtk.HBox()
112
 
113
        ### Dashboard / Visor
114
        hbox = Gtk.HBox()
115
        icon = self.srvicm.get_pixbuf_icon('basico-dashboard', 24, 24)
116
        image = Gtk.Image()
117
        image.set_from_pixbuf(icon)
118
        label = Gtk.Label()
119
        hbox.pack_start(image, False, False, 3)
120
        hbox.pack_start(label, False, False, 3)
121
        button = self.srvgui.add_widget('gtk_button_dashboard', Gtk.Button())
122
        button.add(hbox)
123
        button.set_relief(Gtk.ReliefStyle.NONE)
124
        lhbox.pack_start(button, False, False, 0)
125
        button.connect('clicked', self.srvclb.gui_show_dashboard)
126
 
127
        return lhbox
128
 
129
 
130
    def setup_headerbar_right(self, hb):
131
        rhbox = Gtk.HBox()
132
 
133
        ## Help togglebutton
134
        # ~ if self.srvuif.webkit_support():
135
            # ~ button = self.srvgui.add_widget('gtk_togglebutton_help', Gtk.ToggleButton())
136
            # ~ icon = self.srvicm.get_pixbuf_icon('basico-help', 24, 24)
137
            # ~ image = Gtk.Image()
138
            # ~ image.set_from_pixbuf(icon)
139
            # ~ button.set_image(image)
140
            # ~ button.set_relief(Gtk.ReliefStyle.NONE)
141
            # ~ button.connect('toggled', self.srvclb.gui_toggle_help_visor)
142
        # ~ else:
143
            # ~ button = self.srvgui.add_widget('gtk_button_help', Gtk.Button())
144
            # ~ icon = self.srvicm.get_pixbuf_icon('basico-help', 24, 24)
145
            # ~ image = Gtk.Image()
146
            # ~ image.set_from_pixbuf(icon)
147
            # ~ button.set_image(image)
148
            # ~ button.set_relief(Gtk.ReliefStyle.NONE)
149
            # ~ button.connect('clicked', self.srvclb.gui_lauch_help_visor)
150
 
151
        # ~ rhbox.pack_end(button, False, False, 0)
152
 
153
        ## System Menu
154
        button = Gtk.Button()
155
        icon = self.srvicm.get_pixbuf_icon('basico-menu-system', 24, 24)
156
        image = Gtk.Image()
157
        image.set_from_pixbuf(icon)
158
        button.set_image(image)
159
        button.set_relief(Gtk.ReliefStyle.NONE)
160
        popover = Gtk.Popover.new(button)
161
        self.srvgui.add_widget('gtk_popover_button_menu_system', popover)
162
        button.connect('clicked', self.srvclb.gui_show_popover, popover)
163
        rhbox.pack_end(button, False, False, 0)
164
 
165
        # Popover body
166
        box = Gtk.Box(spacing = 0, orientation="vertical")
167
        popover.add(box)
168
 
169
        ### About
170
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
171
        icon = self.srvicm.get_pixbuf_icon('basico-about', 48, 48)
172
        image = Gtk.Image()
173
        image.set_from_pixbuf(icon)
174
        label = Gtk.Label("About")
175
        hbox.pack_start(image, False, False, 3)
176
        hbox.pack_start(label, False, False, 3)
177
        button = Gtk.Button()
178
        button.add(hbox)
179
        button.set_relief(Gtk.ReliefStyle.NONE)
180
        button.connect('clicked', self.srvclb.gui_show_about)
181
        box.pack_end(button, False, False, 0)
182
 
183
        # ~ ### Help
184
        # ~ hbox = Gtk.Box(spacing = 0, orientation="horizontal")
185
        # ~ icon = self.srvicm.get_pixbuf_icon('basico-help', 48, 48)
186
        # ~ image = Gtk.Image()
187
        # ~ image.set_from_pixbuf(icon)
188
        # ~ label = Gtk.Label("Help")
189
        # ~ hbox.pack_start(image, False, False, 3)
190
        # ~ hbox.pack_start(label, False, False, 3)
191
        # ~ button = Gtk.Button()
192
        # ~ button.add(hbox)
193
        # ~ button.set_relief(Gtk.ReliefStyle.NONE)
194
        # ~ button.connect('clicked', self.srvclb.gui_show_help)
195
        # ~ box.pack_end(button, False, False, 0)
196
 
197
        ### Log viewer
198
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
199
        icon = self.srvicm.get_pixbuf_icon('basico-logviewer', 48, 48)
200
        image = Gtk.Image()
201
        image.set_from_pixbuf(icon)
202
        label = Gtk.Label("Event viewer")
203
        hbox.pack_start(image, False, False, 3)
204
        hbox.pack_start(label, False, False, 3)
205
        button = Gtk.Button()
206
        button.add(hbox)
207
        button.set_relief(Gtk.ReliefStyle.NONE)
208
        button.connect('clicked', self.srvclb.gui_show_log)
209
        box.pack_end(button, False, False, 0)
210
 
211
        ### Settings
212
        # ~ hbox = Gtk.Box(spacing = 0, orientation="horizontal")
213
        # ~ icon = self.srvicm.get_pixbuf_icon('basico-settings', 48, 48)
214
        # ~ image = Gtk.Image()
215
        # ~ image.set_from_pixbuf(icon)
216
        # ~ label = Gtk.Label("Settings")
217
        # ~ hbox.pack_start(image, False, False, 3)
218
        # ~ hbox.pack_start(label, False, False, 3)
219
        # ~ button = Gtk.Button()
220
        # ~ button.add(hbox)
221
        # ~ button.set_relief(Gtk.ReliefStyle.NONE)
222
        # ~ button.connect('clicked', self.srvclb.gui_show_settings)
223
        # ~ box.pack_start(button, False, False, 0)
224
 
225
        ### Backup
226
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
227
        icon = self.srvicm.get_pixbuf_icon('basico-backup-restore', 48, 48)
228
        image = Gtk.Image()
229
        image.set_from_pixbuf(icon)
230
        label = Gtk.Label("Backup/Restore")
231
        hbox.pack_start(image, False, False, 3)
232
        hbox.pack_start(label, False, False, 3)
233
        button = Gtk.Button()
234
        button.add(hbox)
235
        button.set_relief(Gtk.ReliefStyle.NONE)
236
        box.pack_start(button, False, False, 0)
237
 
238
        box_bnr = Gtk.VBox()
239
        popover_bnr = Gtk.Popover.new(button)
240
        popover_bnr.set_position(Gtk.PositionType.LEFT)
241
        popover_bnr.add(box_bnr)
242
        self.srvgui.add_widget('gtk_popover_button_menu_system', popover_bnr)
243
        button.connect('clicked', self.srvclb.gui_show_popover, popover_bnr)
244
 
245
        hbox_backup = Gtk.VBox()
246
        button_backup = self.srvuif.create_button('basico-backup', 48, 48, '<b>Backup database</b> ')
247
        button_backup.connect('clicked', self.srvclb.gui_database_backup)
248
        box_bnr.pack_start(button_backup, False, False, 0)
249
        button_restore = self.srvuif.create_button('basico-restore', 48, 48, '<b>Restore from backup</b>')
250
        button_restore.connect('clicked', self.srvclb.gui_database_restore)
251
        # ~ button_cache = self.srvuif.create_button('basico-restore', 48, 48, '<b>Restore from cache</b>')
252
        # ~ button_cache.connect('clicked', self.srvbnr.restore_from_cache)
253
 
254
        box_bnr.pack_start(button_restore, False, False, 0)
255
        # ~ box_bnr.pack_start(button_cache, False, False, 0)
256
 
257
        return rhbox
258
 
259
 
260
    def setup_widgets(self):
261
        # Mainbox
262
        mainbox = self.srvgui.add_widget('gtk_vbox_container_main', Gtk.VBox())
263
        mainbox.set_hexpand(True)
264
        paned = self.srvgui.add_widget('gtk_hpaned', Gtk.HPaned())
265
        paned.set_property('margin-bottom', 6)
352 t00mlabs 266
        paned.set_wide_handle(True)
340 t00mlabs 267
        paned.set_position(300)
268
 
269
        # (Build first menuview)
270
        notebook_menuview = self.srvgui.add_widget('gtk_notebook_menuview', Gtk.Notebook())
271
        notebook_menuview.set_show_border(False)
272
        notebook_menuview.set_show_tabs(False)
273
        notebook_menuview.set_hexpand(True)
274
 
275
        menuview_sapnotes_page = self.setup_tab_menuview_sapnotes()
276
        menuview_sapnotes_page.set_hexpand(True)
277
        tab_widget = self.srvuif.create_notebook_tab_label('basico-sapnote', '<b>SAP Notes</b>')
278
        notebook_menuview.append_page(menuview_sapnotes_page, tab_widget)
279
 
280
        menuview_annotation_page = self.setup_tab_menuview_annotations()
281
        menuview_annotation_page.set_hexpand(True)
282
        tab_widget = self.srvuif.create_notebook_tab_label('basico-annotation', '<b>Annotations</b>')
283
        notebook_menuview.append_page(menuview_annotation_page, tab_widget)
284
 
285
 
286
        # Paned
345 t00mlabs 287
        ## left pane
288
        paned.add1(notebook_menuview)
289
        notebook_menuview.show_all()
290
 
340 t00mlabs 291
        ## Right pane
352 t00mlabs 292
 
293
        vpaned = self.srvgui.add_widget('gtk_vpaned_visor', Gtk.VPaned())
294
        vpaned.set_property('margin-bottom', 6)
295
        vpaned.set_wide_handle(True)
296
        vpaned.set_position(600)
297
 
340 t00mlabs 298
        box = Gtk.VBox()
299
        box.set_hexpand(True)
345 t00mlabs 300
 
347 t00mlabs 301
        # Main Stack (up)
340 t00mlabs 302
        stack_main = self.srvgui.add_widget('gtk_stack_main', Gtk.Stack())
303
        stack_main.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
304
        stack_main.set_transition_duration(250)
305
        box.pack_start(stack_main, True, True, 0)
306
 
345 t00mlabs 307
        ### Visor stack child
340 t00mlabs 308
        stack_child = self.setup_stack_visor()
309
        stack_main.add_titled(stack_child, "visor", "SAP Notes Visor")
310
 
345 t00mlabs 311
        ### About stack child
340 t00mlabs 312
        stack_child = self.setup_stack_about()
313
        stack_main.add_titled(stack_child, "about", "About Basico")
314
 
345 t00mlabs 315
        ### Log stack child
340 t00mlabs 316
        stack_child = self.setup_stack_log()
317
        stack_main.add_titled(stack_child, "log", "Event Viewer")
318
 
345 t00mlabs 319
        ### Settings stack child
340 t00mlabs 320
        stack_child = self.setup_stack_settings()
321
        stack_main.add_titled(stack_child, "settings", "Basico Settings")
322
 
323
 
347 t00mlabs 324
        ## Annotation widget (down)
340 t00mlabs 325
        boxannotations = self.srvgui.add_widget('gtk_vbox_container_annotations', Gtk.VBox())
346 t00mlabs 326
        self.srvuif.set_widget_visibility('gtk_vbox_container_annotations', False)
353 t00mlabs 327
        widget_annotation = self.srvgui.add_widget('widget_annotation', AnnotationWidget(self.controller))        
349 t00mlabs 328
        boxannotations.add(widget_annotation) # <--
352 t00mlabs 329
 
330
        vpaned.add1(box)
331
        vpaned.add2(boxannotations)
345 t00mlabs 332
 
352 t00mlabs 333
        paned.add2(vpaned)
340 t00mlabs 334
        mainbox.pack_start(paned, True, True, 0)
335
 
336
        # Statusbar
337
        statusbar = self.srvgui.add_widget('widget_statusbar', Statusbar(self.controller))
338
        mainbox.pack_start(statusbar, False, False, 0)
339
 
340
        # Menu Views
341
        vbox = Gtk.VBox()
342
        viewsbox = self.srvgui.get_widget('gtk_box_container_views')
343
        viewmenu = self.srvgui.add_widget('viewmenu', MenuView(self.controller))
344
        viewmenu.set_hexpand(True)
345
        viewmenu.set_vexpand(True)
346
        vbox.pack_start(viewmenu, True, True, 0)
347
        self.srvgui.swap_widget(viewsbox, vbox)
348
 
349
        visor_annotations = self.srvgui.get_widget('visor_annotations')
350
        visor_annotations.connect_menuview_signals()
351
        visor_annotations.set_active_categories()
352
        self.add(mainbox)
353
        self.show_all()
354
 
355
 
356
    def setup_stack_visor(self):
357
        box = Gtk.VBox()
358
        box.set_hexpand(True)
359
 
360
        ### Toolbar
361
        boxtoolbar = self.srvgui.add_widget('gtk_hbox_container_toolbar', Gtk.HBox())
362
        box.pack_start(boxtoolbar, False, False, 0)
363
        visortoolbar = self.srvgui.add_widget('visortoolbar', VisorToolbar(self.controller))
364
        self.srvgui.swap_widget(boxtoolbar, visortoolbar)
365
 
366
        ### Visor
367
        notebook = self.srvgui.add_widget('gtk_notebook_visor', Gtk.Notebook())
368
        notebook.connect('switch-page', self.srvclb.gui_visor_switch_page)
369
        notebook.set_show_border(False)
370
        notebook.set_hexpand(True)
371
 
353 t00mlabs 372
        # Notebook tab for SAP Notes Visor
340 t00mlabs 373
        visor_sapnotes_page = self.setup_tab_sapnote_visor()
374
        visor_sapnotes_page.set_hexpand(True)
375
        tab_widget = self.srvuif.create_notebook_tab_label('basico-sapnote', '<b>SAP Notes</b>')
376
        notebook.append_page(visor_sapnotes_page, tab_widget)
377
 
353 t00mlabs 378
        # Notebook tab for SAP Notes Visor
340 t00mlabs 379
        visor_annotations_page = self.setup_tab_annotations_visor()
380
        visor_annotations_page.set_hexpand(True)
381
        tab_widget = self.srvuif.create_notebook_tab_label('basico-annotation', '<b>Annotations</b>')
382
        notebook.append_page(visor_annotations_page, tab_widget)
383
 
353 t00mlabs 384
        # Notebook tab for Attachments Visor
385
        visor_attachments_page = self.setup_tab_attachments_visor()
386
        visor_attachments_page.set_hexpand(True)
387
        tab_widget = self.srvuif.create_notebook_tab_label('basico-attachment', '<b>Attachments</b>')
388
        notebook.append_page(visor_attachments_page, tab_widget)
389
 
390
        # ~ # Notebook tab for Webbookmarks Visor
391
        # ~ visor_annotations_page = self.setup_tab_annotations_visor()
392
        # ~ visor_annotations_page.set_hexpand(True)
393
        # ~ tab_widget = self.srvuif.create_notebook_tab_label('basico-annotation', '<b>Annotations</b>')
394
        # ~ notebook.append_page(visor_annotations_page, tab_widget)
395
 
340 t00mlabs 396
        # ~ if self.srvuif.webkit_support():
397
            # ~ visor_help_page = self.srvgui.add_widget('gtk_notebook_help_page', self.setup_tab_help_visor())
398
            # ~ visor_help_page.set_hexpand(True)
399
            # ~ tab_widget = self.srvuif.create_notebook_tab_label('basico-help', '<b>Help</b>')
400
            # ~ notebook.append_page(visor_help_page, tab_widget)
401
            # ~ self.srvuif.set_widget_visibility('gtk_notebook_help_page', False)
402
            # ~ notebook.child_set_property(visor_help_page, "tab-expand", True)
403
            # ~ notebook.child_set_property(visor_help_page, "tab-fill", False)
404
 
405
 
406
        notebook.child_set_property(visor_sapnotes_page, "tab-expand", True)
407
        notebook.child_set_property(visor_sapnotes_page, "tab-fill", False)
408
        notebook.child_set_property(visor_annotations_page, "tab-expand", True)
409
        notebook.child_set_property(visor_annotations_page, "tab-fill", False)
353 t00mlabs 410
        notebook.child_set_property(visor_attachments_page, "tab-expand", True)
411
        notebook.child_set_property(visor_attachments_page, "tab-fill", False)
340 t00mlabs 412
 
413
        box.pack_start(notebook, True, True, 0)
414
 
415
        return box
416
 
417
    # ~ def setup_tab_help_visor(self):
418
        # ~ from basico.widgets.wdg_browser import BasicoBrowser
419
        # ~ box = Gtk.VBox()
420
        # ~ box.set_hexpand(True)
421
 
422
        # ~ ### Help Visor
423
        # ~ browser = BasicoBrowser()
424
        # ~ self.controller.debug(FILE['HELP_INDEX'])
425
        # ~ browser.load_url("file://%s" % FILE['HELP_INDEX'])
426
        # ~ box.pack_start(browser, True, True, 0)
427
        # ~ box.show_all()
428
        # ~ return box
429
 
430
 
431
    def setup_tab_sapnote_visor(self):
432
        box = Gtk.VBox()
433
        box.set_hexpand(True)
434
 
435
        ### Visor
436
        scr = Gtk.ScrolledWindow()
437
        scr.set_hexpand(True)
438
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
439
        scr.set_shadow_type(Gtk.ShadowType.NONE)
440
        vwp = Gtk.Viewport()
441
        vwp.set_hexpand(True)
442
        visor = self.srvgui.add_widget('visor_sapnotes', SAPNotesVisor(self.controller))
443
        visor.set_hexpand(True)
444
        visor.set_vexpand(True)
445
        vwp.add(visor)
446
        scr.add(vwp)
447
        box.pack_start(scr, True, True, 0)
448
        visor.show_all()
449
        box.show_all()
450
        return box
451
 
452
 
453
    def setup_tab_annotations_visor(self):
454
        box = Gtk.VBox()
455
        box.set_hexpand(True)
456
 
457
        ### Visor
458
        scr = Gtk.ScrolledWindow()
459
        scr.set_hexpand(True)
460
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
461
        scr.set_shadow_type(Gtk.ShadowType.NONE)
462
        vwp = Gtk.Viewport()
463
        vwp.set_hexpand(True)
464
        visor = self.srvgui.add_widget('visor_annotations', AnnotationsVisor(self.controller))
465
        visor.set_hexpand(True)
466
        visor.set_vexpand(True)
467
        vwp.add(visor)
468
        scr.add(vwp)
469
        box.pack_start(scr, True, True, 0)
470
        visor.show_all()
471
        box.show_all()
472
        return box
473
 
474
 
353 t00mlabs 475
    def setup_tab_attachments_visor(self):
476
        box = Gtk.VBox()
477
        box.set_hexpand(True)
478
 
479
        ### Visor
480
        scr = Gtk.ScrolledWindow()
481
        scr.set_hexpand(True)
482
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
483
        scr.set_shadow_type(Gtk.ShadowType.NONE)
484
        vwp = Gtk.Viewport()
485
        vwp.set_hexpand(True)
486
        visor = self.srvgui.add_widget('visor_attachments', AttachmentsVisor(self.controller))
487
        visor.set_hexpand(True)
488
        visor.set_vexpand(True)
489
        vwp.add(visor)
490
        scr.add(vwp)
491
        box.pack_start(scr, True, True, 0)
492
        visor.show_all()
493
        box.show_all()
494
        return box
495
 
496
 
340 t00mlabs 497
    def setup_tab_menuview_sapnotes(self):
498
        ## Left view - SAP Notes Menu view
499
        box = self.srvgui.add_widget('gtk_vbox_container_menu_view', Gtk.VBox())
500
        box.set_property('margin-left', 0)
501
        box.set_property('margin-right', 0)
502
        box.set_property('margin-bottom', 0)
503
 
504
        # View combobox button/popover
505
        lhbox = Gtk.HBox()
506
        menuviews = self.srvgui.add_widget('gtk_button_menu_views', Gtk.Button())
507
        menuviews.set_relief(Gtk.ReliefStyle.NONE)
508
        hbox = Gtk.HBox()
509
        label = self.srvgui.add_widget('gtk_label_current_view', Gtk.Label())
510
        label.set_xalign(0.0)
511
        image = self.srvgui.add_widget('gtk_image_current_view', Gtk.Image())
512
        hbox.pack_start(image, False, False, 3)
513
        hbox.pack_start(label, True, True, 3)
514
        menuviews.add(hbox)
515
        lhbox.pack_start(menuviews, True, True, 3)
516
        lhbox.show_all()
517
        box.pack_start(lhbox, False, False, 3)
518
 
519
        ### Popover menuviews
520
        popover = self.srvgui.add_widget('gtk_popover_button_menu_views', Gtk.Popover.new(menuviews))
521
        menuviews.connect('clicked', self.srvclb.gui_show_popover, popover)
522
        box_views = Gtk.Box(spacing = 0, orientation="vertical")
523
        popover.add(box_views)
524
 
525
        box_views.pack_start(self.srvuif.create_menuview_button('collection'), False, False, 0)
526
        separator = Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL)
527
        box_views.pack_start(separator, False, False, 0)
528
        box_views.pack_start(self.srvuif.create_menuview_button('component'), False, False, 0)
529
        box_views.pack_start(self.srvuif.create_menuview_button('description'), False, False, 0)
530
        box_views.pack_start(self.srvuif.create_menuview_button('bookmarks'), False, False, 0)
531
        box_views.pack_start(self.srvuif.create_menuview_button('category'), False, False, 0)
532
        box_views.pack_start(self.srvuif.create_menuview_button('chronologic'), False, False, 0)
533
        box_views.pack_start(self.srvuif.create_menuview_button('priority'), False, False, 0)
534
        box_views.pack_start(self.srvuif.create_menuview_button('type'), False, False, 0)
535
 
536
        ### Toolbar
537
        toolbar = Gtk.Toolbar()
538
        toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
539
 
540
        #### Filter entry tool
541
        tool = Gtk.ToolItem.new()
542
 
543
        hbox = Gtk.HBox()
544
        viewfilter = self.srvgui.add_widget('gtk_entry_filter_view', Gtk.Entry())
545
        completion = self.srvgui.get_widget('gtk_entrycompletion_viewmenu')
546
        viewfilter.set_completion(completion)
547
        viewfilter.connect('activate', self.srvclb.gui_viewmenu_filter)
548
 
549
        icon = self.srvicm.get_pixbuf_icon('basico-refresh')
550
        viewfilter.set_icon_from_pixbuf(Gtk.EntryIconPosition.PRIMARY, icon)
551
        viewfilter.set_icon_sensitive(Gtk.EntryIconPosition.PRIMARY, True)
552
        viewfilter.set_icon_tooltip_markup (Gtk.EntryIconPosition.PRIMARY, "Refresh and collapse")
553
 
554
        icon = self.srvicm.get_pixbuf_icon('basico-filter')
555
        viewfilter.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, icon)
556
        viewfilter.set_icon_sensitive(Gtk.EntryIconPosition.SECONDARY, True)
557
        viewfilter.set_icon_tooltip_markup (Gtk.EntryIconPosition.SECONDARY, "Click here to expand the tree")
558
        viewfilter.set_placeholder_text("Filter this view...")
559
 
560
        def on_icon_pressed(entry, icon_pos, event):
561
            if icon_pos == Gtk.EntryIconPosition.PRIMARY:
562
                viewmenu = self.srvgui.get_widget('viewmenu')
563
                viewmenu.refresh()
564
            elif icon_pos == Gtk.EntryIconPosition.SECONDARY:
565
                self.srvclb.expand_menuview()
566
 
567
        viewfilter.connect("icon-press", on_icon_pressed)
568
 
569
        hbox.pack_start(viewfilter, True, True, 0)
570
        tool.add(hbox)
571
        tool.set_expand(True)
572
        toolbar.insert(tool, -1)
573
 
574
        box.pack_start(toolbar, False, False, 0)
575
 
576
        ### View treeview
577
        box_trv = Gtk.VBox()
578
        box_trv.set_property('margin-left', 3)
579
        box_trv.set_property('margin-right', 3)
580
        box_trv.set_property('margin-bottom', 0)
581
        scr = Gtk.ScrolledWindow()
582
        scr.set_hexpand(True)
583
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
584
        scr.set_shadow_type(Gtk.ShadowType.IN)
585
        vwp = Gtk.Viewport()
586
        vwp.set_hexpand(True)
587
        viewsbox = self.srvgui.add_widget('gtk_box_container_views', Gtk.Box())
588
        viewsbox.set_hexpand(True)
589
        vwp.add(viewsbox)
590
        scr.add(vwp)
591
        box_trv.pack_start(scr, True, True, 0)
592
 
593
        box.pack_start(box_trv, True, True, 0)
594
 
595
        return box
596
 
597
 
598
    def setup_tab_menuview_annotations(self):
599
        vbox_main = Gtk.VBox()
600
        vbox_main.set_hexpand(False)
601
        vbox_main.set_property('margin-top', 6)
602
        vbox_main.set_property('margin-left', 6)
603
        vbox_main.set_property('margin-right', 6)
604
        vbox_main.set_property('margin-bottom', 3)
605
 
606
 
607
        def create_panel_elem_button(icon, title):
608
            button = self.srvgui.add_widget('gtk_togglebutton_%s' % title, Gtk.ToggleButton())
609
            button.set_relief(Gtk.ReliefStyle.NONE)
610
            icon = self.srvicm.get_image_icon(icon, 36, 36)
611
            label = Gtk.Label('')
612
            label.set_markup('%s' % title.capitalize())
613
            hbox_cat_elem = Gtk.HBox()
614
            hbox_cat_elem.set_hexpand(False)
615
            hbox_cat_elem.pack_start(icon, False, False, 3)
616
            hbox_cat_elem.pack_start(label, False, False, 3)
617
            button.add(hbox_cat_elem)
618
 
619
            return button
620
 
349 t00mlabs 621
        hbox_main = Gtk.HBox()
622
        hbox_main.set_homogeneous(True)
623
        vbox_main.pack_start(hbox_main, False, False, 0)
624
 
625
        separator = Gtk.Separator()
626
        vbox_main.pack_start(separator, False, False, 6)
627
 
340 t00mlabs 628
        # Categories
629
        button = self.srvgui.add_widget('gtk_togglebutton_categories', Gtk.ToggleButton())
630
        button.set_relief(Gtk.ReliefStyle.NONE)
631
        icon = self.srvicm.get_image_icon('basico-category', 48, 48)
632
        label = Gtk.Label('')
633
        label.set_markup('<big><b>Categories</b></big>')
634
        hbox_cat = Gtk.HBox()
635
        hbox_cat.set_hexpand(True)
636
        hbox_cat.pack_start(icon, False, False, 3)
637
        hbox_cat.pack_start(label, False, False, 3)
638
        button.add(hbox_cat)
349 t00mlabs 639
        hbox_main.pack_start(button, True, True, 6)
340 t00mlabs 640
 
641
        revealer = self.srvgui.add_widget('gtk_revealer_annotations_categories', Gtk.Revealer())
642
        vbox_revealer = Gtk.VBox()
643
        vbox_revealer.set_hexpand(False)
644
 
645
        for name in ['inbox', 'drafts', 'archived']:
646
            button = create_panel_elem_button('basico-%s' % name.lower(), name)
647
            self.srvgui.add_widget('gtk_button_category_%s' % name, button)
648
            vbox_revealer.pack_start(button, False, False, 2)
649
 
650
        revealer.add(vbox_revealer)
651
        vbox_main.pack_start(revealer, False, False, 6)
652
 
653
        # Types
654
        button = self.srvgui.add_widget('gtk_togglebutton_types', Gtk.ToggleButton())
655
        button.set_relief(Gtk.ReliefStyle.NONE)
656
        icon = self.srvicm.get_image_icon('basico-type', 48, 48)
657
        label = Gtk.Label('')
658
        label.set_markup('<big><b>Types</b></big>')
659
        hbox_type = Gtk.HBox()
349 t00mlabs 660
        hbox_type.set_hexpand(True)
340 t00mlabs 661
 
662
        hbox_type.pack_start(icon, False, False, 3)
663
        hbox_type.pack_start(label, False, False, 3)
664
        button.add(hbox_type)
349 t00mlabs 665
        hbox_main.pack_start(button, True, True, 0)
340 t00mlabs 666
 
667
        revealer = self.srvgui.add_widget('gtk_revealer_annotations_types', Gtk.Revealer())
668
        vbox_revealer = Gtk.VBox()
669
        vbox_revealer.set_hexpand(False)
670
 
671
        hbox_sel = Gtk.HBox()
672
        switch = Gtk.Switch()
673
        switch.set_active(True)
674
        switch.set_state(True)
675
        switch.connect('state-set', self.srvclb.gui_switch_selection_atypes)
349 t00mlabs 676
        label_select = Gtk.Label()
677
        label_select.set_markup("<b>All selected</b>")
678
        label = self.srvgui.add_widget('gtk_label_switch_select_atypes', label_select)
679
        hbox_sel.pack_start(label, False, False, 6)
340 t00mlabs 680
        hbox_sel.pack_start(switch, False, False, 6)
681
        vbox_revealer.pack_start(hbox_sel, False, False, 6)
682
 
683
        for name in ATYPES:
684
            button = create_panel_elem_button('basico-annotation-type-%s' % name.lower(), name.lower())
685
            self.srvgui.add_widget('gtk_button_type_%s' % name.lower(), button)
686
            button.set_active(True)
687
            vbox_revealer.pack_start(button, False, False, 2)
688
 
689
        revealer.add(vbox_revealer)
690
        vbox_main.pack_start(revealer, False, False, 6)
691
 
349 t00mlabs 692
        # ~ separator = Gtk.Separator()
693
        # ~ vbox_main.pack_start(separator, False, False, 6)
694
 
340 t00mlabs 695
        return vbox_main
696
 
697
 
698
    def setup_stack_about(self):
699
        box = Gtk.VBox()
700
        box.set_hexpand(True)
701
        about = self.srvgui.add_widget('widget_about', About(self.controller))
702
        box.pack_start(about, True, True, 0)
703
        box.show_all()
704
        return box
705
 
706
 
707
    def setup_stack_settings(self):
708
        box = Gtk.VBox()
709
        box.set_hexpand(True)
710
        settings = self.srvgui.add_widget('widget_settings', SettingsView(self.controller))
711
        box.pack_start(settings, True, True, 0)
712
        box.show_all()
713
        return box
714
 
715
 
716
    def setup_stack_log(self):
717
        box = Gtk.VBox()
718
        box.set_hexpand(True)
719
        logviewer = self.srvgui.add_widget('widget_logviewer', LogViewer(self.controller))
720
        box.pack_start(logviewer, True, True, 0)
721
        box.show_all()
722
        return box
723
 
724
 
344 t00mlabs 725
    # ~ def setup_stack_annotation(self):
726
        # ~ return self.srvgui.add_widget('widget_annotation', AnnotationWidget(self.controller)) 
340 t00mlabs 727
 
728
 
729
    def run(self):
730
        visor_annotations = self.srvgui.get_widget('visor_annotations')
731
        viewmenu = self.srvgui.get_widget('viewmenu')
732
        viewmenu.set_view('collection')
733
        self.srvclb.gui_show_visor_annotations()
734
        annotations = self.srvant.search_term('')
735
        visor_annotations.populate_annotations(annotations)
736
        self.srvclb.gui_viewmenu_select_first_entry()