Subversion Repositories basico

Rev

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