Subversion Repositories basico

Rev

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