Subversion Repositories basico

Rev

Rev 215 | Rev 217 | 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)
213 t00m 60
        # ~ self.gui.add_widget('gtk_app_window_main', self)
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)
93 t00mlabs 71
        self.setup_headerbar()
4 t00mlabs 72
        self.show_all()
73
 
74
 
77 t00mlabs 75
    def setup_headerbar(self):
213 t00m 76
        hb = self.gui.add_widget('gtk_headerbar_container', Gtk.HeaderBar())
77 t00mlabs 77
        hb.set_show_close_button(True)
78
        hb.props.title = "Basico"
79 t00mlabs 79
        hb.props.subtitle = "SAP Notes Manager for SAP Consultants"
203 t00m 80
        # ~ lhbox = self.setup_headerbar_left(hb)
81
        # ~ hb.pack_start(lhbox)
180 t00m 82
        rhbox = self.setup_headerbar_right(hb)
203 t00m 83
 
180 t00m 84
        hb.pack_end(rhbox)
85
        self.set_titlebar(hb)
86
        hb.show_all()
87
 
182 t00m 88
 
180 t00m 89
    def setup_headerbar_left(self, hb):
203 t00m 90
        '''Left headerbar side not used by now'''
91
        pass
92
        # ~ lhbox = Gtk.HBox()
93
        # ~ return lhbox
185 t00m 94
 
77 t00mlabs 95
 
180 t00m 96
    def setup_headerbar_right(self, hb):
185 t00m 97
        rhbox = Gtk.HBox()
180 t00m 98
 
153 t00m 99
        ## System Menu
77 t00mlabs 100
        button = Gtk.Button()
187 t00m 101
        icon = self.im.get_pixbuf_icon('basico-menu-system', 24, 24)
81 t00mlabs 102
        image = Gtk.Image()
103
        image.set_from_pixbuf(icon)
104
        button.set_image(image)
77 t00mlabs 105
        button.set_relief(Gtk.ReliefStyle.NONE)
122 t00mlabs 106
        popover = Gtk.Popover.new(button)
213 t00m 107
        self.gui.add_widget('gtk_popover_button_menu_system', popover)
188 t00m 108
        button.connect('clicked', self.cb.gui_show_popover, popover)
77 t00mlabs 109
        rhbox.pack_end(button, False, False, 0)
79 t00mlabs 110
 
122 t00mlabs 111
        # Popover body
112
        box = Gtk.Box(spacing = 0, orientation="vertical")
113
 
153 t00m 114
        ### About
122 t00mlabs 115
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
187 t00m 116
        icon = self.im.get_pixbuf_icon('basico-about', 24, 24)
122 t00mlabs 117
        image = Gtk.Image()
118
        image.set_from_pixbuf(icon)
119
        label = Gtk.Label("About")
120
        hbox.pack_start(image, False, False, 3)
121
        hbox.pack_start(label, False, False, 3)
122
        button = Gtk.Button()
123
        button.add(hbox)
124
        button.set_relief(Gtk.ReliefStyle.NONE)
188 t00m 125
        button.connect('clicked', self.cb.gui_show_about)
122 t00mlabs 126
        box.pack_end(button, False, False, 0)
127
 
216 t00m 128
        # ~ ### Help
129
        # ~ hbox = Gtk.Box(spacing = 0, orientation="horizontal")
130
        # ~ icon = self.im.get_pixbuf_icon('basico-help', 24, 24)
131
        # ~ image = Gtk.Image()
132
        # ~ image.set_from_pixbuf(icon)
133
        # ~ label = Gtk.Label("Help")
134
        # ~ hbox.pack_start(image, False, False, 3)
135
        # ~ hbox.pack_start(label, False, False, 3)
136
        # ~ button = Gtk.Button()
137
        # ~ button.add(hbox)
138
        # ~ button.set_relief(Gtk.ReliefStyle.NONE)
139
        # ~ button.connect('clicked', self.cb.gui_show_help)
140
        # ~ box.pack_end(button, False, False, 0)
141
 
142
        ### Log viewer
143
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
144
        icon = self.im.get_pixbuf_icon('basico-logviewer', 24, 24)
145
        image = Gtk.Image()
146
        image.set_from_pixbuf(icon)
147
        label = Gtk.Label("Log viewer")
148
        hbox.pack_start(image, False, False, 3)
149
        hbox.pack_start(label, False, False, 3)
150
        button = Gtk.Button()
151
        button.add(hbox)
152
        button.set_relief(Gtk.ReliefStyle.NONE)
153
        button.connect('clicked', self.cb.gui_show_log)
154
        box.pack_end(button, False, False, 0)
155
 
153 t00m 156
        ### Settings
157
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
155 t00m 158
        icon = self.im.get_pixbuf_icon('basico-settings', 24, 24)
81 t00mlabs 159
        image = Gtk.Image()
160
        image.set_from_pixbuf(icon)
122 t00mlabs 161
        label = Gtk.Label("Settings")
162
        hbox.pack_start(image, False, False, 3)
163
        hbox.pack_start(label, False, False, 3)
164
        button = Gtk.Button()
165
        button.add(hbox)
79 t00mlabs 166
        button.set_relief(Gtk.ReliefStyle.NONE)
188 t00m 167
        button.connect('clicked', self.cb.gui_show_settings)
130 t00mlabs 168
        box.pack_start(button, False, False, 0)
122 t00mlabs 169
        popover.add(box)
180 t00m 170
        return rhbox
77 t00mlabs 171
 
172
 
4 t00mlabs 173
    def setup_widgets(self):
137 t00mlabs 174
        # Mainbox
213 t00m 175
        mainbox = self.gui.add_widget('gtk_vbox_container_main', Gtk.VBox())
137 t00mlabs 176
        mainbox.set_hexpand(True)
213 t00m 177
        paned = self.gui.add_widget('gtk_hpaned', Gtk.HPaned())
178 t00m 178
        paned.set_property('margin-bottom', 6)
179
        paned.set_wide_handle(False)
164 t00m 180
        paned.set_position(300)
82 t00mlabs 181
 
137 t00mlabs 182
        # Paned
183
        ## Left view
213 t00m 184
        box = self.gui.add_widget('gtk_vbox_container_menu_view', Gtk.VBox())
166 t00m 185
        box.set_property('margin-left', 6)
186
        box.set_property('margin-right', 6)
176 t00m 187
        box.set_property('margin-bottom', 0)
166 t00m 188
 
189
        ### Toolbar
190
        toolbar = Gtk.Toolbar()
191
        toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
192
 
193
        #### Filter entry tool
194
        tool = Gtk.ToolItem.new()
195
 
196
        hbox = Gtk.HBox()
213 t00m 197
        viewfilter = self.gui.add_widget('gtk_entry_filter_view', Gtk.Entry())
188 t00m 198
        viewfilter.connect('activate', self.cb.gui_filter_viewmenu)
175 t00m 199
 
200
        icon = self.im.get_pixbuf_icon('basico-refresh')
201
        viewfilter.set_icon_from_pixbuf(Gtk.EntryIconPosition.PRIMARY, icon)
202
        viewfilter.set_icon_sensitive(Gtk.EntryIconPosition.PRIMARY, True)
203
        viewfilter.set_icon_tooltip_markup (Gtk.EntryIconPosition.PRIMARY, "Refresh and collapse")
204
 
205
        icon = self.im.get_pixbuf_icon('basico-filter')
206
        viewfilter.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, icon)
207
        viewfilter.set_icon_sensitive(Gtk.EntryIconPosition.SECONDARY, True)
208
        viewfilter.set_icon_tooltip_markup (Gtk.EntryIconPosition.SECONDARY, "Click here to expand the tree")
209
        viewfilter.set_placeholder_text("Filter this view...")
210
 
211
        def on_icon_pressed(entry, icon_pos, event):
212
            if icon_pos == Gtk.EntryIconPosition.PRIMARY:
213
                viewmenu = self.gui.get_widget('viewmenu')
214
                viewmenu.refresh()
215
            elif icon_pos == Gtk.EntryIconPosition.SECONDARY:
216
                self.cb.expand_menuview()
217
 
218
        viewfilter.connect("icon-press", on_icon_pressed)
219
 
166 t00m 220
        hbox.pack_start(viewfilter, True, True, 0)
221
        tool.add(hbox)
222
        tool.set_expand(True)
223
        toolbar.insert(tool, -1)
224
 
225
        box.pack_start(toolbar, False, False, 0)
226
 
185 t00m 227
        ### View treeview
137 t00mlabs 228
        scr = Gtk.ScrolledWindow()
229
        scr.set_hexpand(True)
230
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
164 t00m 231
        scr.set_shadow_type(Gtk.ShadowType.IN)
137 t00mlabs 232
        vwp = Gtk.Viewport()
233
        vwp.set_hexpand(True)
213 t00m 234
        viewsbox = self.gui.add_widget('gtk_box_container_views', Gtk.Box())
137 t00mlabs 235
        viewsbox.set_hexpand(True)
236
        vwp.add(viewsbox)
237
        scr.add(vwp)
166 t00m 238
        box.pack_start(scr, True, True, 0)
137 t00mlabs 239
        paned.add1(box)
82 t00mlabs 240
 
137 t00mlabs 241
        ## Right view
213 t00m 242
        box = Gtk.VBox()
137 t00mlabs 243
        box.set_hexpand(True)
214 t00m 244
        self.stack_main = self.gui.add_widget('gtk_stack_main', Gtk.Stack())
215 t00m 245
        # ~ self.stack_main.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
246
        # ~ self.stack_main.set_transition_duration(2500)
214 t00m 247
        box.pack_start(self.stack_main, True, True, 0)
168 t00m 248
 
216 t00m 249
        ### Visor stack
214 t00m 250
        stack = self.setup_stack_visor()
251
        self.stack_main.add_titled(stack, "visor", "SAP Notes Visor")
168 t00m 252
 
215 t00m 253
        ### About stack
254
        stack = self.setup_stack_about()
255
        self.stack_main.add_titled(stack, "about", "About Basico")
207 t00m 256
 
216 t00m 257
        # ~ ### Log stack
258
        # FIXME: Segmentation fault (core dumped)
259
        stack = self.setup_stack_log()
260
        self.stack_main.add_titled(stack, "log", "Log Viewer")
261
 
215 t00m 262
        ### Settings stack
263
        stack = self.setup_stack_settings()
264
        self.stack_main.add_titled(stack, "settings", "Basico Settings")
265
 
207 t00m 266
        ## Dialogs
213 t00m 267
        boxdialogs = self.gui.add_widget('gtk_box_container_dialogs', Gtk.Box())
207 t00m 268
        boxdialogs.set_no_show_all(True)
269
        boxdialogs.hide()
270
        box.pack_start(boxdialogs, True, True, 6)
271
 
137 t00mlabs 272
        paned.add2(box)
142 t00mlabs 273
        mainbox.pack_start(paned, True, True, 0)
82 t00mlabs 274
 
162 t00m 275
        # Statusbar
213 t00m 276
        statusbar = self.gui.add_widget('widget_statusbar', Statusbar(self.controller))
142 t00mlabs 277
        mainbox.pack_start(statusbar, False, False, 0)
278
 
203 t00m 279
        # Menu Views
280
        vbox = Gtk.VBox()
213 t00m 281
        viewsbox = self.gui.get_widget('gtk_box_container_views')
203 t00m 282
        viewmenu = self.gui.add_widget('viewmenu', SAPNoteViewMenu(self.controller))
283
        viewmenu.set_hexpand(True)
284
        viewmenu.set_vexpand(True)
285
        vbox.pack_start(viewmenu, True, True, 0)
286
        self.gui.swap_widget(viewsbox, vbox)
287
 
288
        viewmenu = self.gui.get_widget('viewmenu')
289
        viewmenu.set_view('task')
290
 
137 t00mlabs 291
        self.add(mainbox)
292
        self.show_all()
82 t00mlabs 293
 
294
 
214 t00m 295
    def setup_stack_visor(self):
296
        box = Gtk.VBox()
297
        box.set_hexpand(True)
298
 
299
        ### Toolbar
300
        boxtoolbar = self.gui.add_widget('gtk_hbox_container_toolbar', Gtk.HBox())
301
        box.pack_start(boxtoolbar, False, False, 0)
302
        visortoolbar = self.gui.add_widget('visortoolbar', SAPNoteViewVisorToolbar(self.controller))
303
        self.gui.swap_widget(boxtoolbar, visortoolbar)
304
 
305
        ### Visor
306
        scr = Gtk.ScrolledWindow()
307
        scr.set_hexpand(True)
308
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
309
        vwp = Gtk.Viewport()
310
        vwp.set_hexpand(True)
311
        visor = self.gui.add_widget('visor', SAPNoteViewVisor(self.controller))
312
        visor.set_hexpand(True)
313
        visor.set_vexpand(True)
314
        vwp.add(visor)
315
        scr.add(vwp)
316
        box.pack_start(scr, True, True, 0)
317
        visor.show_all()
318
        box.show_all()
319
        return box
215 t00m 320
 
321
 
322
    def setup_stack_about(self):
323
        box = Gtk.VBox()
324
        box.set_hexpand(True)
216 t00m 325
        about = self.gui.add_widget('widget_about', About())
326
        box.pack_start(about, True, True, 0)
215 t00m 327
        box.show_all()
328
        return box
329
 
330
 
331
    def setup_stack_settings(self):
332
        box = Gtk.VBox()
333
        box.set_hexpand(True)
334
        settings = self.gui.add_widget('widget_settings', SettingsView(self.controller))
335
        box.pack_start(settings, True, True, 0)
336
        box.show_all()
337
        return box
216 t00m 338
 
339
    def setup_stack_log(self):
340
        box = Gtk.VBox()
341
        box.set_hexpand(True)
342
        logviewer = self.gui.add_widget('widget_logviewer', LogViewer(self.controller))
343
        box.pack_start(logviewer, True, True, 0)
344
        box.show_all()
345
        return box