Subversion Repositories basico

Rev

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

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