Subversion Repositories basico

Rev

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