Subversion Repositories basico

Rev

Rev 248 | Rev 252 | 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 -*-
251 t00m 3
# File: mod_win.py
4 t00mlabs 4
# Author: Tomás Vírseda
5
# License: GPL v3
6
# Description: Gtk.ApplicationWindow implementation
7
 
8
import os
9
import stat
10
import time
11
import platform
12
 
13
import gi
14
gi.require_version('Gtk', '3.0')
15
 
16
from gi.repository import GLib
17
from gi.repository import GObject
18
from gi.repository import Gtk
19
from gi.repository import Gdk
20
from gi.repository import Gio
21
from gi.repository import Pango
22
from gi.repository.GdkPixbuf import Pixbuf
23
 
243 t00m 24
from basico.core.mod_env import APP
25
from basico.widgets.wdg_menuview import SAPNoteViewMenu
26
from basico.widgets.wdg_visor import SAPNoteViewVisor, SAPNoteViewVisorToolbar
27
from basico.widgets.wdg_about import About
28
from basico.widgets.wdg_settingsview import SettingsView
29
from basico.widgets.wdg_logviewer import LogViewer
30
from basico.widgets.wdg_annot import AnnotationWidget
31
from basico.widgets.wdg_statusbar import Statusbar
4 t00mlabs 32
 
243 t00m 33
 
236 t00m 34
class GtkAppWindow(Gtk.ApplicationWindow):
4 t00mlabs 35
    def __init__(self, uiapp):
36
        self.setup_controller(uiapp)
37
        self.get_services()
247 t00m 38
        self.app = self.srvgui.get_app()
39
        self.srvgui.add_widget('uiapp', uiapp)
236 t00m 40
        self.setup_window(uiapp)
4 t00mlabs 41
        self.setup_widgets()
230 t00m 42
        self.run()
248 t00m 43
        self.controller.debug("GUI loaded")
4 t00mlabs 44
 
106 t00mlabs 45
 
182 t00m 46
    def get_services(self):
247 t00m 47
        self.srvbnr = self.controller.get_service("BNR")
48
        self.srvgui = self.controller.get_service("GUI")
49
        self.srvdtb = self.controller.get_service("DB")
50
        self.srvuif = self.controller.get_service("UIF")
51
        self.srvicm = self.controller.get_service('IM')
52
        self.srvclb = self.controller.get_service('Callbacks')
4 t00mlabs 53
 
141 t00mlabs 54
 
4 t00mlabs 55
    def setup_controller(self, uiapp):
56
        self.controller = uiapp.get_controller()
57
 
58
 
236 t00m 59
    def setup_window(self, uiapp):
243 t00m 60
        Gtk.Window.__init__(self, title=APP['name'], application=uiapp)
247 t00m 61
        icon = self.srvicm.get_icon('basico-component', 48, 48)
4 t00mlabs 62
        self.set_icon(icon)
63
        # FIXME
64
        # From docs: Don’t use this function. It sets the X xlib.Window
65
        # System “class” and “name” hints for a window.
66
        # But I have to do it or it doesn't shows the right title. ???
243 t00m 67
        self.set_wmclass (APP['name'], APP['name'])
68
        self.set_role(APP['name'])
4 t00mlabs 69
        self.set_default_size(1024, 728)
70
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
230 t00m 71
        self.maximize ()
93 t00mlabs 72
        self.setup_headerbar()
4 t00mlabs 73
        self.show_all()
74
 
75
 
77 t00mlabs 76
    def setup_headerbar(self):
247 t00m 77
        hb = self.srvgui.add_widget('gtk_headerbar_container', Gtk.HeaderBar())
77 t00mlabs 78
        hb.set_show_close_button(True)
79
        hb.props.title = "Basico"
79 t00mlabs 80
        hb.props.subtitle = "SAP Notes Manager for SAP Consultants"
231 t00m 81
        lhbox = self.setup_headerbar_left(hb)
82
        hb.pack_start(lhbox)
180 t00m 83
        rhbox = self.setup_headerbar_right(hb)
203 t00m 84
 
180 t00m 85
        hb.pack_end(rhbox)
86
        self.set_titlebar(hb)
87
        hb.show_all()
88
 
182 t00m 89
 
180 t00m 90
    def setup_headerbar_left(self, hb):
231 t00m 91
        # ~ '''Left headerbar side not used by now'''
92
        lhbox = Gtk.HBox()
185 t00m 93
 
231 t00m 94
        ### Dashboard / Visor
95
        hbox = Gtk.HBox()
247 t00m 96
        icon = self.srvicm.get_pixbuf_icon('basico-dashboard', 24, 24)
231 t00m 97
        image = Gtk.Image()
98
        image.set_from_pixbuf(icon)
99
        label = Gtk.Label()
100
        hbox.pack_start(image, False, False, 3)
101
        hbox.pack_start(label, False, False, 3)
247 t00m 102
        button = self.srvgui.add_widget('gtk_button_dashboard', Gtk.Button())
231 t00m 103
        button.add(hbox)
104
        button.set_relief(Gtk.ReliefStyle.NONE)
105
        lhbox.pack_start(button, False, False, 0)
247 t00m 106
        button.connect('clicked', self.srvclb.gui_show_dashboard)
77 t00mlabs 107
 
231 t00m 108
        return lhbox
109
 
110
 
180 t00m 111
    def setup_headerbar_right(self, hb):
185 t00m 112
        rhbox = Gtk.HBox()
180 t00m 113
 
153 t00m 114
        ## System Menu
77 t00mlabs 115
        button = Gtk.Button()
247 t00m 116
        icon = self.srvicm.get_pixbuf_icon('basico-menu-system', 24, 24)
81 t00mlabs 117
        image = Gtk.Image()
118
        image.set_from_pixbuf(icon)
119
        button.set_image(image)
77 t00mlabs 120
        button.set_relief(Gtk.ReliefStyle.NONE)
122 t00mlabs 121
        popover = Gtk.Popover.new(button)
247 t00m 122
        self.srvgui.add_widget('gtk_popover_button_menu_system', popover)
123
        button.connect('clicked', self.srvclb.gui_show_popover, popover)
77 t00mlabs 124
        rhbox.pack_end(button, False, False, 0)
79 t00mlabs 125
 
122 t00mlabs 126
        # Popover body
127
        box = Gtk.Box(spacing = 0, orientation="vertical")
237 t00m 128
        popover.add(box)
122 t00mlabs 129
 
153 t00m 130
        ### About
122 t00mlabs 131
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
247 t00m 132
        icon = self.srvicm.get_pixbuf_icon('basico-about', 48, 48)
122 t00mlabs 133
        image = Gtk.Image()
134
        image.set_from_pixbuf(icon)
135
        label = Gtk.Label("About")
136
        hbox.pack_start(image, False, False, 3)
137
        hbox.pack_start(label, False, False, 3)
138
        button = Gtk.Button()
139
        button.add(hbox)
140
        button.set_relief(Gtk.ReliefStyle.NONE)
247 t00m 141
        button.connect('clicked', self.srvclb.gui_show_about)
122 t00mlabs 142
        box.pack_end(button, False, False, 0)
143
 
216 t00m 144
        # ~ ### Help
145
        # ~ hbox = Gtk.Box(spacing = 0, orientation="horizontal")
247 t00m 146
        # ~ icon = self.srvicm.get_pixbuf_icon('basico-help', 48, 48)
216 t00m 147
        # ~ image = Gtk.Image()
148
        # ~ image.set_from_pixbuf(icon)
149
        # ~ label = Gtk.Label("Help")
150
        # ~ hbox.pack_start(image, False, False, 3)
151
        # ~ hbox.pack_start(label, False, False, 3)
152
        # ~ button = Gtk.Button()
153
        # ~ button.add(hbox)
154
        # ~ button.set_relief(Gtk.ReliefStyle.NONE)
247 t00m 155
        # ~ button.connect('clicked', self.srvclb.gui_show_help)
216 t00m 156
        # ~ box.pack_end(button, False, False, 0)
157
 
158
        ### Log viewer
159
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
247 t00m 160
        icon = self.srvicm.get_pixbuf_icon('basico-logviewer', 48, 48)
216 t00m 161
        image = Gtk.Image()
162
        image.set_from_pixbuf(icon)
163
        label = Gtk.Label("Log viewer")
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_log)
216 t00m 170
        box.pack_end(button, False, False, 0)
171
 
153 t00m 172
        ### Settings
173
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
247 t00m 174
        icon = self.srvicm.get_pixbuf_icon('basico-settings', 48, 48)
81 t00mlabs 175
        image = Gtk.Image()
176
        image.set_from_pixbuf(icon)
122 t00mlabs 177
        label = Gtk.Label("Settings")
178
        hbox.pack_start(image, False, False, 3)
179
        hbox.pack_start(label, False, False, 3)
180
        button = Gtk.Button()
181
        button.add(hbox)
79 t00mlabs 182
        button.set_relief(Gtk.ReliefStyle.NONE)
247 t00m 183
        button.connect('clicked', self.srvclb.gui_show_settings)
130 t00mlabs 184
        box.pack_start(button, False, False, 0)
217 t00m 185
 
227 t00m 186
        ### Backup
187
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
247 t00m 188
        icon = self.srvicm.get_pixbuf_icon('basico-backup-restore', 48, 48)
227 t00m 189
        image = Gtk.Image()
190
        image.set_from_pixbuf(icon)
238 t00m 191
        label = Gtk.Label("Backup/Restore")
227 t00m 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.srvbnr.backup)
227 t00m 198
        box.pack_start(button, False, False, 0)
199
 
237 t00m 200
        box_bnr = Gtk.VBox()
201
        popover_bnr = Gtk.Popover.new(button)
202
        popover_bnr.set_position(Gtk.PositionType.LEFT)
203
        popover_bnr.add(box_bnr)
247 t00m 204
        self.srvgui.add_widget('gtk_popover_button_menu_system', popover_bnr)
205
        button.connect('clicked', self.srvclb.gui_show_popover, popover_bnr)
227 t00m 206
 
247 t00m 207
        button_backup = self.srvuif.create_button('basico-backup', 48, 48, '<b>Backup database</b> ')
208
        button_restore = self.srvuif.create_button('basico-restore', 48, 48, '<b>Restore from backup</b>')
209
        button_restore.connect('clicked', self.srvclb.gui_show_filechooser_restore)
210
        button_cache = self.srvuif.create_button('basico-restore', 48, 48, '<b>Restore from cache</b>')
211
        button_cache.connect('clicked', self.srvbnr.restore_from_cache)
237 t00m 212
        box_bnr.pack_start(button_backup, False, False, 0)
213
        box_bnr.pack_start(button_restore, False, False, 0)
238 t00m 214
        box_bnr.pack_start(button_cache, False, False, 0)
237 t00m 215
 
180 t00m 216
        return rhbox
77 t00mlabs 217
 
218
 
240 t00m 219
    def reveal_filechooser_restore(self, *args):
247 t00m 220
        revealer = self.srvgui.get_widget('gtk_revealer_restore')
240 t00m 221
        revealer.set_reveal_child(True)
222
 
223
 
224
    def file_chooser_button_clicked(self, filechooser):
225
        def find_child_classes(container, cls):
226
            return [widget for widget in container.get_children() if isinstance(widget, cls)]
227
 
228
        widget = find_child_classes(filechooser, Gtk.Button)
229
        self.controller.debug(widget.get_name())
230
 
231
    def file_chooser_close(self, *args):
232
        self.debug(args)
233
 
4 t00mlabs 234
    def setup_widgets(self):
137 t00mlabs 235
        # Mainbox
247 t00m 236
        mainbox = self.srvgui.add_widget('gtk_vbox_container_main', Gtk.VBox())
137 t00mlabs 237
        mainbox.set_hexpand(True)
247 t00m 238
        paned = self.srvgui.add_widget('gtk_hpaned', Gtk.HPaned())
178 t00m 239
        paned.set_property('margin-bottom', 6)
240
        paned.set_wide_handle(False)
164 t00m 241
        paned.set_position(300)
82 t00mlabs 242
 
137 t00mlabs 243
        # Paned
244
        ## Left view
247 t00m 245
        box = self.srvgui.add_widget('gtk_vbox_container_menu_view', Gtk.VBox())
166 t00m 246
        box.set_property('margin-left', 6)
247
        box.set_property('margin-right', 6)
176 t00m 248
        box.set_property('margin-bottom', 0)
166 t00m 249
 
250
        ### Toolbar
251
        toolbar = Gtk.Toolbar()
252
        toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
253
 
254
        #### Filter entry tool
255
        tool = Gtk.ToolItem.new()
256
 
257
        hbox = Gtk.HBox()
247 t00m 258
        viewfilter = self.srvgui.add_widget('gtk_entry_filter_view', Gtk.Entry())
259
        completion = self.srvgui.get_widget('gtk_entrycompletion_viewmenu')
242 t00m 260
        viewfilter.set_completion(completion)
247 t00m 261
        viewfilter.connect('activate', self.srvclb.gui_viewmenu_filter)
175 t00m 262
 
247 t00m 263
        icon = self.srvicm.get_pixbuf_icon('basico-refresh')
175 t00m 264
        viewfilter.set_icon_from_pixbuf(Gtk.EntryIconPosition.PRIMARY, icon)
265
        viewfilter.set_icon_sensitive(Gtk.EntryIconPosition.PRIMARY, True)
266
        viewfilter.set_icon_tooltip_markup (Gtk.EntryIconPosition.PRIMARY, "Refresh and collapse")
267
 
247 t00m 268
        icon = self.srvicm.get_pixbuf_icon('basico-filter')
175 t00m 269
        viewfilter.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, icon)
270
        viewfilter.set_icon_sensitive(Gtk.EntryIconPosition.SECONDARY, True)
271
        viewfilter.set_icon_tooltip_markup (Gtk.EntryIconPosition.SECONDARY, "Click here to expand the tree")
272
        viewfilter.set_placeholder_text("Filter this view...")
273
 
274
        def on_icon_pressed(entry, icon_pos, event):
275
            if icon_pos == Gtk.EntryIconPosition.PRIMARY:
247 t00m 276
                viewmenu = self.srvgui.get_widget('viewmenu')
175 t00m 277
                viewmenu.refresh()
278
            elif icon_pos == Gtk.EntryIconPosition.SECONDARY:
247 t00m 279
                self.srvclb.expand_menuview()
175 t00m 280
 
281
        viewfilter.connect("icon-press", on_icon_pressed)
282
 
166 t00m 283
        hbox.pack_start(viewfilter, True, True, 0)
284
        tool.add(hbox)
285
        tool.set_expand(True)
286
        toolbar.insert(tool, -1)
287
 
288
        box.pack_start(toolbar, False, False, 0)
289
 
185 t00m 290
        ### View treeview
137 t00mlabs 291
        scr = Gtk.ScrolledWindow()
292
        scr.set_hexpand(True)
293
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
164 t00m 294
        scr.set_shadow_type(Gtk.ShadowType.IN)
137 t00mlabs 295
        vwp = Gtk.Viewport()
296
        vwp.set_hexpand(True)
247 t00m 297
        viewsbox = self.srvgui.add_widget('gtk_box_container_views', Gtk.Box())
137 t00mlabs 298
        viewsbox.set_hexpand(True)
299
        vwp.add(viewsbox)
300
        scr.add(vwp)
166 t00m 301
        box.pack_start(scr, True, True, 0)
137 t00mlabs 302
        paned.add1(box)
82 t00mlabs 303
 
137 t00mlabs 304
        ## Right view
213 t00m 305
        box = Gtk.VBox()
137 t00mlabs 306
        box.set_hexpand(True)
247 t00m 307
        stack_main = self.srvgui.add_widget('gtk_stack_main', Gtk.Stack())
220 t00m 308
        stack_main.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
309
        stack_main.set_transition_duration(2500)
310
        box.pack_start(stack_main, True, True, 0)
168 t00m 311
 
216 t00m 312
        ### Visor stack
220 t00m 313
        stack_child = self.setup_stack_visor()
314
        stack_main.add_titled(stack_child, "visor", "SAP Notes Visor")
168 t00m 315
 
215 t00m 316
        ### About stack
220 t00m 317
        stack_child = self.setup_stack_about()
318
        stack_main.add_titled(stack_child, "about", "About Basico")
207 t00m 319
 
220 t00m 320
        ### Log stack
321
        stack_child = self.setup_stack_log()
322
        stack_main.add_titled(stack_child, "log", "Log Viewer")
216 t00m 323
 
215 t00m 324
        ### Settings stack
220 t00m 325
        stack_child = self.setup_stack_settings()
326
        stack_main.add_titled(stack_child, "settings", "Basico Settings")
215 t00m 327
 
218 t00m 328
        ## Annotations
247 t00m 329
        boxannotations = self.srvgui.add_widget('gtk_vbox_container_annotations', Gtk.VBox())
220 t00m 330
 
247 t00m 331
        stack_annot = self.srvgui.add_widget('gtk_stack_annotation', Gtk.Stack())
220 t00m 332
        stack_annot.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
333
        stack_annot.set_transition_duration(2500)
334
 
335
        stack_child = self.setup_stack_annotation()
336
        stack_annot.add_titled(stack_child, "comment", "New comment")
337
        stack_annot.child_set_property (stack_child, "icon-name", "basico-comments")
338
 
339
        # ~ stack_child = self.setup_stack_annotation_link()
340
        # ~ stack_annot.add_titled(stack_child, "link", "New link")
341
        # ~ stack_annot.child_set_property (stack_child, "icon-name", "basico-browse")
342
 
247 t00m 343
        self.srvuif.set_widget_visibility('gtk_vbox_container_annotations', False)
220 t00m 344
        boxannotations.add(stack_annot)
345
 
346
 
218 t00m 347
        box.pack_start(boxannotations, True, True, 6)
137 t00mlabs 348
        paned.add2(box)
142 t00mlabs 349
        mainbox.pack_start(paned, True, True, 0)
82 t00mlabs 350
 
162 t00m 351
        # Statusbar
247 t00m 352
        statusbar = self.srvgui.add_widget('widget_statusbar', Statusbar(self.controller))
142 t00mlabs 353
        mainbox.pack_start(statusbar, False, False, 0)
354
 
203 t00m 355
        # Menu Views
356
        vbox = Gtk.VBox()
247 t00m 357
        viewsbox = self.srvgui.get_widget('gtk_box_container_views')
358
        viewmenu = self.srvgui.add_widget('viewmenu', SAPNoteViewMenu(self.controller))
203 t00m 359
        viewmenu.set_hexpand(True)
360
        viewmenu.set_vexpand(True)
361
        vbox.pack_start(viewmenu, True, True, 0)
247 t00m 362
        self.srvgui.swap_widget(viewsbox, vbox)
203 t00m 363
 
137 t00mlabs 364
        self.add(mainbox)
365
        self.show_all()
82 t00mlabs 366
 
367
 
214 t00m 368
    def setup_stack_visor(self):
369
        box = Gtk.VBox()
370
        box.set_hexpand(True)
371
 
372
        ### Toolbar
247 t00m 373
        boxtoolbar = self.srvgui.add_widget('gtk_hbox_container_toolbar', Gtk.HBox())
214 t00m 374
        box.pack_start(boxtoolbar, False, False, 0)
247 t00m 375
        visortoolbar = self.srvgui.add_widget('visortoolbar', SAPNoteViewVisorToolbar(self.controller))
376
        self.srvgui.swap_widget(boxtoolbar, visortoolbar)
214 t00m 377
 
378
        ### Visor
379
        scr = Gtk.ScrolledWindow()
380
        scr.set_hexpand(True)
381
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
382
        vwp = Gtk.Viewport()
383
        vwp.set_hexpand(True)
247 t00m 384
        visor = self.srvgui.add_widget('visor', SAPNoteViewVisor(self.controller))
214 t00m 385
        visor.set_hexpand(True)
386
        visor.set_vexpand(True)
387
        vwp.add(visor)
388
        scr.add(vwp)
389
        box.pack_start(scr, True, True, 0)
390
        visor.show_all()
391
        box.show_all()
392
        return box
215 t00m 393
 
394
 
395
    def setup_stack_about(self):
396
        box = Gtk.VBox()
397
        box.set_hexpand(True)
247 t00m 398
        about = self.srvgui.add_widget('widget_about', About())
216 t00m 399
        box.pack_start(about, True, True, 0)
215 t00m 400
        box.show_all()
401
        return box
402
 
403
 
404
    def setup_stack_settings(self):
405
        box = Gtk.VBox()
406
        box.set_hexpand(True)
247 t00m 407
        settings = self.srvgui.add_widget('widget_settings', SettingsView(self.controller))
215 t00m 408
        box.pack_start(settings, True, True, 0)
409
        box.show_all()
410
        return box
216 t00m 411
 
412
    def setup_stack_log(self):
413
        box = Gtk.VBox()
414
        box.set_hexpand(True)
247 t00m 415
        logviewer = self.srvgui.add_widget('widget_logviewer', LogViewer(self.controller))
216 t00m 416
        box.pack_start(logviewer, True, True, 0)
417
        box.show_all()
418
        return box
220 t00m 419
 
420
 
421
    def setup_stack_annotation(self):
247 t00m 422
        return self.srvgui.add_widget('widget_annotation', AnnotationWidget(self.controller))
230 t00m 423
 
424
 
425
    def run(self):
247 t00m 426
        viewmenu = self.srvgui.get_widget('viewmenu')
230 t00m 427
        viewmenu.set_view('annotation')
247 t00m 428
        self.srvclb.gui_show_dashboard()
429
        # ~ self.srvclb.gui_show_about()