Subversion Repositories basico

Rev

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