Subversion Repositories basico

Rev

Rev 230 | Rev 232 | 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
 
203 t00m 24
from .sapnoteviewmenu import SAPNoteViewMenu
25
from .sapnoteviewvisor import SAPNoteViewVisor, SAPNoteViewVisorToolbar
218 t00m 26
from .widgets import About, SettingsView, LogViewer, AnnotationWidget
201 t00m 27
from .widgets import Statusbar
133 t00mlabs 28
from .service import Service
4 t00mlabs 29
 
133 t00mlabs 30
class GtkAppWindow(Gtk.ApplicationWindow, Service):
4 t00mlabs 31
    def __init__(self, uiapp):
32
        self.setup_controller(uiapp)
33
        self.get_services()
142 t00mlabs 34
        self.log = self.controller.log
4 t00mlabs 35
        self.gui.add_widget('uiapp', uiapp)
36
        self.setup_window()
141 t00mlabs 37
        self.controller.debug("Window setup correctly")
4 t00mlabs 38
        self.setup_widgets()
141 t00mlabs 39
        self.controller.debug("Widgets setup correctly")
230 t00m 40
        self.run()
4 t00mlabs 41
 
106 t00mlabs 42
 
182 t00m 43
    def get_services(self):
44
        self.gui = self.controller.get_service("GUI")
45
        self.app = self.gui.get_app()
46
        self.db = self.controller.get_service("DB")
47
        self.uif = self.controller.get_service("UIF")
48
        self.prefs = self.controller.get_service("Settings")
49
        self.im = self.controller.get_service('IM')
50
        self.cb = self.controller.get_service('Callbacks')
4 t00mlabs 51
 
141 t00mlabs 52
 
4 t00mlabs 53
    def setup_controller(self, uiapp):
54
        self.uiapp = uiapp
55
        self.controller = uiapp.get_controller()
56
 
57
 
58
    def setup_window(self):
59
        app_title = self.controller.get_app_info('name')
60
        Gtk.Window.__init__(self, title=app_title, application=self.uiapp)
201 t00m 61
        icon = self.im.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. ???
67
        self.set_wmclass (app_title, app_title)
68
        self.set_role(app_title)
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):
213 t00m 77
        hb = self.gui.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()
96
        icon = self.im.get_pixbuf_icon('basico-dashboard', 24, 24)
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)
102
        button = self.gui.add_widget('gtk_button_dashboard', Gtk.Button())
103
        button.add(hbox)
104
        button.set_relief(Gtk.ReliefStyle.NONE)
105
        lhbox.pack_start(button, False, False, 0)
106
        button.connect('clicked', self.cb.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()
187 t00m 116
        icon = self.im.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)
213 t00m 122
        self.gui.add_widget('gtk_popover_button_menu_system', popover)
188 t00m 123
        button.connect('clicked', self.cb.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")
128
 
153 t00m 129
        ### About
122 t00mlabs 130
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
187 t00m 131
        icon = self.im.get_pixbuf_icon('basico-about', 24, 24)
122 t00mlabs 132
        image = Gtk.Image()
133
        image.set_from_pixbuf(icon)
134
        label = Gtk.Label("About")
135
        hbox.pack_start(image, False, False, 3)
136
        hbox.pack_start(label, False, False, 3)
137
        button = Gtk.Button()
138
        button.add(hbox)
139
        button.set_relief(Gtk.ReliefStyle.NONE)
188 t00m 140
        button.connect('clicked', self.cb.gui_show_about)
122 t00mlabs 141
        box.pack_end(button, False, False, 0)
142
 
216 t00m 143
        # ~ ### Help
144
        # ~ hbox = Gtk.Box(spacing = 0, orientation="horizontal")
145
        # ~ icon = self.im.get_pixbuf_icon('basico-help', 24, 24)
146
        # ~ image = Gtk.Image()
147
        # ~ image.set_from_pixbuf(icon)
148
        # ~ label = Gtk.Label("Help")
149
        # ~ hbox.pack_start(image, False, False, 3)
150
        # ~ hbox.pack_start(label, False, False, 3)
151
        # ~ button = Gtk.Button()
152
        # ~ button.add(hbox)
153
        # ~ button.set_relief(Gtk.ReliefStyle.NONE)
154
        # ~ button.connect('clicked', self.cb.gui_show_help)
155
        # ~ box.pack_end(button, False, False, 0)
156
 
157
        ### Log viewer
158
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
159
        icon = self.im.get_pixbuf_icon('basico-logviewer', 24, 24)
160
        image = Gtk.Image()
161
        image.set_from_pixbuf(icon)
162
        label = Gtk.Label("Log viewer")
163
        hbox.pack_start(image, False, False, 3)
164
        hbox.pack_start(label, False, False, 3)
165
        button = Gtk.Button()
166
        button.add(hbox)
167
        button.set_relief(Gtk.ReliefStyle.NONE)
168
        button.connect('clicked', self.cb.gui_show_log)
169
        box.pack_end(button, False, False, 0)
170
 
153 t00m 171
        ### Settings
172
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
155 t00m 173
        icon = self.im.get_pixbuf_icon('basico-settings', 24, 24)
81 t00mlabs 174
        image = Gtk.Image()
175
        image.set_from_pixbuf(icon)
122 t00mlabs 176
        label = Gtk.Label("Settings")
177
        hbox.pack_start(image, False, False, 3)
178
        hbox.pack_start(label, False, False, 3)
179
        button = Gtk.Button()
180
        button.add(hbox)
79 t00mlabs 181
        button.set_relief(Gtk.ReliefStyle.NONE)
188 t00m 182
        button.connect('clicked', self.cb.gui_show_settings)
130 t00mlabs 183
        box.pack_start(button, False, False, 0)
217 t00m 184
 
227 t00m 185
        ### Backup
186
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
187
        icon = self.im.get_pixbuf_icon('basico-backup', 24, 24)
188
        image = Gtk.Image()
189
        image.set_from_pixbuf(icon)
190
        label = Gtk.Label("Backup")
191
        hbox.pack_start(image, False, False, 3)
192
        hbox.pack_start(label, False, False, 3)
193
        button = Gtk.Button()
194
        button.add(hbox)
195
        button.set_relief(Gtk.ReliefStyle.NONE)
196
        button.connect('clicked', self.cb.action_backup)
197
        box.pack_start(button, False, False, 0)
198
 
199
 
122 t00mlabs 200
        popover.add(box)
180 t00m 201
        return rhbox
77 t00mlabs 202
 
203
 
4 t00mlabs 204
    def setup_widgets(self):
137 t00mlabs 205
        # Mainbox
213 t00m 206
        mainbox = self.gui.add_widget('gtk_vbox_container_main', Gtk.VBox())
137 t00mlabs 207
        mainbox.set_hexpand(True)
213 t00m 208
        paned = self.gui.add_widget('gtk_hpaned', Gtk.HPaned())
178 t00m 209
        paned.set_property('margin-bottom', 6)
210
        paned.set_wide_handle(False)
164 t00m 211
        paned.set_position(300)
82 t00mlabs 212
 
137 t00mlabs 213
        # Paned
214
        ## Left view
213 t00m 215
        box = self.gui.add_widget('gtk_vbox_container_menu_view', Gtk.VBox())
166 t00m 216
        box.set_property('margin-left', 6)
217
        box.set_property('margin-right', 6)
176 t00m 218
        box.set_property('margin-bottom', 0)
166 t00m 219
 
220
        ### Toolbar
221
        toolbar = Gtk.Toolbar()
222
        toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
223
 
224
        #### Filter entry tool
225
        tool = Gtk.ToolItem.new()
226
 
227
        hbox = Gtk.HBox()
213 t00m 228
        viewfilter = self.gui.add_widget('gtk_entry_filter_view', Gtk.Entry())
222 t00m 229
        viewfilter.connect('activate', self.cb.gui_viewmenu_filter)
175 t00m 230
 
231
        icon = self.im.get_pixbuf_icon('basico-refresh')
232
        viewfilter.set_icon_from_pixbuf(Gtk.EntryIconPosition.PRIMARY, icon)
233
        viewfilter.set_icon_sensitive(Gtk.EntryIconPosition.PRIMARY, True)
234
        viewfilter.set_icon_tooltip_markup (Gtk.EntryIconPosition.PRIMARY, "Refresh and collapse")
235
 
236
        icon = self.im.get_pixbuf_icon('basico-filter')
237
        viewfilter.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, icon)
238
        viewfilter.set_icon_sensitive(Gtk.EntryIconPosition.SECONDARY, True)
239
        viewfilter.set_icon_tooltip_markup (Gtk.EntryIconPosition.SECONDARY, "Click here to expand the tree")
240
        viewfilter.set_placeholder_text("Filter this view...")
241
 
242
        def on_icon_pressed(entry, icon_pos, event):
243
            if icon_pos == Gtk.EntryIconPosition.PRIMARY:
244
                viewmenu = self.gui.get_widget('viewmenu')
245
                viewmenu.refresh()
246
            elif icon_pos == Gtk.EntryIconPosition.SECONDARY:
247
                self.cb.expand_menuview()
248
 
249
        viewfilter.connect("icon-press", on_icon_pressed)
250
 
166 t00m 251
        hbox.pack_start(viewfilter, True, True, 0)
252
        tool.add(hbox)
253
        tool.set_expand(True)
254
        toolbar.insert(tool, -1)
255
 
256
        box.pack_start(toolbar, False, False, 0)
257
 
185 t00m 258
        ### View treeview
137 t00mlabs 259
        scr = Gtk.ScrolledWindow()
260
        scr.set_hexpand(True)
261
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
164 t00m 262
        scr.set_shadow_type(Gtk.ShadowType.IN)
137 t00mlabs 263
        vwp = Gtk.Viewport()
264
        vwp.set_hexpand(True)
213 t00m 265
        viewsbox = self.gui.add_widget('gtk_box_container_views', Gtk.Box())
137 t00mlabs 266
        viewsbox.set_hexpand(True)
267
        vwp.add(viewsbox)
268
        scr.add(vwp)
166 t00m 269
        box.pack_start(scr, True, True, 0)
137 t00mlabs 270
        paned.add1(box)
82 t00mlabs 271
 
137 t00mlabs 272
        ## Right view
213 t00m 273
        box = Gtk.VBox()
137 t00mlabs 274
        box.set_hexpand(True)
220 t00m 275
        stack_main = self.gui.add_widget('gtk_stack_main', Gtk.Stack())
276
        stack_main.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
277
        stack_main.set_transition_duration(2500)
278
        box.pack_start(stack_main, True, True, 0)
168 t00m 279
 
216 t00m 280
        ### Visor stack
220 t00m 281
        stack_child = self.setup_stack_visor()
282
        stack_main.add_titled(stack_child, "visor", "SAP Notes Visor")
168 t00m 283
 
215 t00m 284
        ### About stack
220 t00m 285
        stack_child = self.setup_stack_about()
286
        stack_main.add_titled(stack_child, "about", "About Basico")
207 t00m 287
 
220 t00m 288
        ### Log stack
289
        stack_child = self.setup_stack_log()
290
        stack_main.add_titled(stack_child, "log", "Log Viewer")
216 t00m 291
 
215 t00m 292
        ### Settings stack
220 t00m 293
        stack_child = self.setup_stack_settings()
294
        stack_main.add_titled(stack_child, "settings", "Basico Settings")
215 t00m 295
 
218 t00m 296
        ## Annotations
220 t00m 297
        boxannotations = self.gui.add_widget('gtk_vbox_container_annotations', Gtk.VBox())
298
 
299
        stack_annot = self.gui.add_widget('gtk_stack_annotation', Gtk.Stack())
300
        stack_annot.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
301
        stack_annot.set_transition_duration(2500)
302
 
303
        stack_child = self.setup_stack_annotation()
304
        stack_annot.add_titled(stack_child, "comment", "New comment")
305
        stack_annot.child_set_property (stack_child, "icon-name", "basico-comments")
306
 
307
        # ~ stack_child = self.setup_stack_annotation_link()
308
        # ~ stack_annot.add_titled(stack_child, "link", "New link")
309
        # ~ stack_annot.child_set_property (stack_child, "icon-name", "basico-browse")
310
 
311
        boxannotations.add(stack_annot)
218 t00m 312
        boxannotations.set_no_show_all(True)
313
        boxannotations.hide()
220 t00m 314
 
315
 
218 t00m 316
        box.pack_start(boxannotations, True, True, 6)
137 t00mlabs 317
        paned.add2(box)
142 t00mlabs 318
        mainbox.pack_start(paned, True, True, 0)
82 t00mlabs 319
 
162 t00m 320
        # Statusbar
213 t00m 321
        statusbar = self.gui.add_widget('widget_statusbar', Statusbar(self.controller))
142 t00mlabs 322
        mainbox.pack_start(statusbar, False, False, 0)
323
 
203 t00m 324
        # Menu Views
325
        vbox = Gtk.VBox()
213 t00m 326
        viewsbox = self.gui.get_widget('gtk_box_container_views')
203 t00m 327
        viewmenu = self.gui.add_widget('viewmenu', SAPNoteViewMenu(self.controller))
328
        viewmenu.set_hexpand(True)
329
        viewmenu.set_vexpand(True)
330
        vbox.pack_start(viewmenu, True, True, 0)
331
        self.gui.swap_widget(viewsbox, vbox)
332
 
137 t00mlabs 333
        self.add(mainbox)
334
        self.show_all()
82 t00mlabs 335
 
336
 
214 t00m 337
    def setup_stack_visor(self):
338
        box = Gtk.VBox()
339
        box.set_hexpand(True)
340
 
341
        ### Toolbar
342
        boxtoolbar = self.gui.add_widget('gtk_hbox_container_toolbar', Gtk.HBox())
343
        box.pack_start(boxtoolbar, False, False, 0)
344
        visortoolbar = self.gui.add_widget('visortoolbar', SAPNoteViewVisorToolbar(self.controller))
345
        self.gui.swap_widget(boxtoolbar, visortoolbar)
346
 
347
        ### Visor
348
        scr = Gtk.ScrolledWindow()
349
        scr.set_hexpand(True)
350
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
351
        vwp = Gtk.Viewport()
352
        vwp.set_hexpand(True)
353
        visor = self.gui.add_widget('visor', SAPNoteViewVisor(self.controller))
354
        visor.set_hexpand(True)
355
        visor.set_vexpand(True)
356
        vwp.add(visor)
357
        scr.add(vwp)
358
        box.pack_start(scr, True, True, 0)
359
        visor.show_all()
360
        box.show_all()
361
        return box
215 t00m 362
 
363
 
364
    def setup_stack_about(self):
365
        box = Gtk.VBox()
366
        box.set_hexpand(True)
216 t00m 367
        about = self.gui.add_widget('widget_about', About())
368
        box.pack_start(about, True, True, 0)
215 t00m 369
        box.show_all()
370
        return box
371
 
372
 
373
    def setup_stack_settings(self):
374
        box = Gtk.VBox()
375
        box.set_hexpand(True)
376
        settings = self.gui.add_widget('widget_settings', SettingsView(self.controller))
377
        box.pack_start(settings, True, True, 0)
378
        box.show_all()
379
        return box
216 t00m 380
 
381
    def setup_stack_log(self):
382
        box = Gtk.VBox()
383
        box.set_hexpand(True)
384
        logviewer = self.gui.add_widget('widget_logviewer', LogViewer(self.controller))
385
        box.pack_start(logviewer, True, True, 0)
386
        box.show_all()
387
        return box
220 t00m 388
 
389
 
390
    def setup_stack_annotation(self):
391
        return self.gui.add_widget('widget_annotation', AnnotationWidget(self.controller))
230 t00m 392
 
393
 
394
    def run(self):
395
        viewmenu = self.gui.get_widget('viewmenu')
396
        viewmenu.set_view('annotation')
397
        self.cb.gui_show_dashboard()
398
        # ~ self.cb.gui_show_about()