Subversion Repositories basico

Rev

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