Subversion Repositories basico

Rev

Rev 216 | Rev 218 | 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
216 t00m 26
from .widgets import About, SettingsView, LogViewer
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)
214 t00m 258
        self.stack_main = self.gui.add_widget('gtk_stack_main', Gtk.Stack())
215 t00m 259
        # ~ self.stack_main.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
260
        # ~ self.stack_main.set_transition_duration(2500)
214 t00m 261
        box.pack_start(self.stack_main, True, True, 0)
168 t00m 262
 
216 t00m 263
        ### Visor stack
214 t00m 264
        stack = self.setup_stack_visor()
265
        self.stack_main.add_titled(stack, "visor", "SAP Notes Visor")
168 t00m 266
 
215 t00m 267
        ### About stack
268
        stack = self.setup_stack_about()
269
        self.stack_main.add_titled(stack, "about", "About Basico")
207 t00m 270
 
216 t00m 271
        # ~ ### Log stack
272
        # FIXME: Segmentation fault (core dumped)
273
        stack = self.setup_stack_log()
274
        self.stack_main.add_titled(stack, "log", "Log Viewer")
275
 
215 t00m 276
        ### Settings stack
277
        stack = self.setup_stack_settings()
278
        self.stack_main.add_titled(stack, "settings", "Basico Settings")
279
 
207 t00m 280
        ## Dialogs
213 t00m 281
        boxdialogs = self.gui.add_widget('gtk_box_container_dialogs', Gtk.Box())
207 t00m 282
        boxdialogs.set_no_show_all(True)
283
        boxdialogs.hide()
284
        box.pack_start(boxdialogs, True, True, 6)
285
 
137 t00mlabs 286
        paned.add2(box)
142 t00mlabs 287
        mainbox.pack_start(paned, True, True, 0)
82 t00mlabs 288
 
162 t00m 289
        # Statusbar
213 t00m 290
        statusbar = self.gui.add_widget('widget_statusbar', Statusbar(self.controller))
142 t00mlabs 291
        mainbox.pack_start(statusbar, False, False, 0)
292
 
203 t00m 293
        # Menu Views
294
        vbox = Gtk.VBox()
213 t00m 295
        viewsbox = self.gui.get_widget('gtk_box_container_views')
203 t00m 296
        viewmenu = self.gui.add_widget('viewmenu', SAPNoteViewMenu(self.controller))
297
        viewmenu.set_hexpand(True)
298
        viewmenu.set_vexpand(True)
299
        vbox.pack_start(viewmenu, True, True, 0)
300
        self.gui.swap_widget(viewsbox, vbox)
301
 
302
        viewmenu = self.gui.get_widget('viewmenu')
303
        viewmenu.set_view('task')
304
 
137 t00mlabs 305
        self.add(mainbox)
306
        self.show_all()
82 t00mlabs 307
 
308
 
214 t00m 309
    def setup_stack_visor(self):
310
        box = Gtk.VBox()
311
        box.set_hexpand(True)
312
 
313
        ### Toolbar
314
        boxtoolbar = self.gui.add_widget('gtk_hbox_container_toolbar', Gtk.HBox())
315
        box.pack_start(boxtoolbar, False, False, 0)
316
        visortoolbar = self.gui.add_widget('visortoolbar', SAPNoteViewVisorToolbar(self.controller))
317
        self.gui.swap_widget(boxtoolbar, visortoolbar)
318
 
319
        ### Visor
320
        scr = Gtk.ScrolledWindow()
321
        scr.set_hexpand(True)
322
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
323
        vwp = Gtk.Viewport()
324
        vwp.set_hexpand(True)
325
        visor = self.gui.add_widget('visor', SAPNoteViewVisor(self.controller))
326
        visor.set_hexpand(True)
327
        visor.set_vexpand(True)
328
        vwp.add(visor)
329
        scr.add(vwp)
330
        box.pack_start(scr, True, True, 0)
331
        visor.show_all()
332
        box.show_all()
333
        return box
215 t00m 334
 
335
 
336
    def setup_stack_about(self):
337
        box = Gtk.VBox()
338
        box.set_hexpand(True)
216 t00m 339
        about = self.gui.add_widget('widget_about', About())
340
        box.pack_start(about, True, True, 0)
215 t00m 341
        box.show_all()
342
        return box
343
 
344
 
345
    def setup_stack_settings(self):
346
        box = Gtk.VBox()
347
        box.set_hexpand(True)
348
        settings = self.gui.add_widget('widget_settings', SettingsView(self.controller))
349
        box.pack_start(settings, True, True, 0)
350
        box.show_all()
351
        return box
216 t00m 352
 
353
    def setup_stack_log(self):
354
        box = Gtk.VBox()
355
        box.set_hexpand(True)
356
        logviewer = self.gui.add_widget('widget_logviewer', LogViewer(self.controller))
357
        box.pack_start(logviewer, True, True, 0)
358
        box.show_all()
359
        return box