Subversion Repositories basico

Rev

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