Subversion Repositories basico

Rev

Rev 214 | Rev 216 | 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
215 t00m 26
from .widgets import About, SettingsView
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
 
153 t00m 128
        ### Settings
129
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
155 t00m 130
        icon = self.im.get_pixbuf_icon('basico-settings', 24, 24)
81 t00mlabs 131
        image = Gtk.Image()
132
        image.set_from_pixbuf(icon)
122 t00mlabs 133
        label = Gtk.Label("Settings")
134
        hbox.pack_start(image, False, False, 3)
135
        hbox.pack_start(label, False, False, 3)
136
        button = Gtk.Button()
137
        button.add(hbox)
79 t00mlabs 138
        button.set_relief(Gtk.ReliefStyle.NONE)
188 t00m 139
        button.connect('clicked', self.cb.gui_show_settings)
130 t00mlabs 140
        box.pack_start(button, False, False, 0)
122 t00mlabs 141
        popover.add(box)
180 t00m 142
        return rhbox
77 t00mlabs 143
 
144
 
4 t00mlabs 145
    def setup_widgets(self):
137 t00mlabs 146
        # Mainbox
213 t00m 147
        mainbox = self.gui.add_widget('gtk_vbox_container_main', Gtk.VBox())
137 t00mlabs 148
        mainbox.set_hexpand(True)
213 t00m 149
        paned = self.gui.add_widget('gtk_hpaned', Gtk.HPaned())
178 t00m 150
        paned.set_property('margin-bottom', 6)
151
        paned.set_wide_handle(False)
164 t00m 152
        paned.set_position(300)
82 t00mlabs 153
 
137 t00mlabs 154
        # Paned
155
        ## Left view
213 t00m 156
        box = self.gui.add_widget('gtk_vbox_container_menu_view', Gtk.VBox())
166 t00m 157
        box.set_property('margin-left', 6)
158
        box.set_property('margin-right', 6)
176 t00m 159
        box.set_property('margin-bottom', 0)
166 t00m 160
 
161
        ### Toolbar
162
        toolbar = Gtk.Toolbar()
163
        toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
164
 
165
        #### Filter entry tool
166
        tool = Gtk.ToolItem.new()
167
 
168
        hbox = Gtk.HBox()
213 t00m 169
        viewfilter = self.gui.add_widget('gtk_entry_filter_view', Gtk.Entry())
188 t00m 170
        viewfilter.connect('activate', self.cb.gui_filter_viewmenu)
175 t00m 171
 
172
        icon = self.im.get_pixbuf_icon('basico-refresh')
173
        viewfilter.set_icon_from_pixbuf(Gtk.EntryIconPosition.PRIMARY, icon)
174
        viewfilter.set_icon_sensitive(Gtk.EntryIconPosition.PRIMARY, True)
175
        viewfilter.set_icon_tooltip_markup (Gtk.EntryIconPosition.PRIMARY, "Refresh and collapse")
176
 
177
        icon = self.im.get_pixbuf_icon('basico-filter')
178
        viewfilter.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, icon)
179
        viewfilter.set_icon_sensitive(Gtk.EntryIconPosition.SECONDARY, True)
180
        viewfilter.set_icon_tooltip_markup (Gtk.EntryIconPosition.SECONDARY, "Click here to expand the tree")
181
        viewfilter.set_placeholder_text("Filter this view...")
182
 
183
        def on_icon_pressed(entry, icon_pos, event):
184
            if icon_pos == Gtk.EntryIconPosition.PRIMARY:
185
                viewmenu = self.gui.get_widget('viewmenu')
186
                viewmenu.refresh()
187
            elif icon_pos == Gtk.EntryIconPosition.SECONDARY:
188
                self.cb.expand_menuview()
189
 
190
        viewfilter.connect("icon-press", on_icon_pressed)
191
 
166 t00m 192
        hbox.pack_start(viewfilter, True, True, 0)
193
        tool.add(hbox)
194
        tool.set_expand(True)
195
        toolbar.insert(tool, -1)
196
 
197
        box.pack_start(toolbar, False, False, 0)
198
 
185 t00m 199
        ### View treeview
137 t00mlabs 200
        scr = Gtk.ScrolledWindow()
201
        scr.set_hexpand(True)
202
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
164 t00m 203
        scr.set_shadow_type(Gtk.ShadowType.IN)
137 t00mlabs 204
        vwp = Gtk.Viewport()
205
        vwp.set_hexpand(True)
213 t00m 206
        viewsbox = self.gui.add_widget('gtk_box_container_views', Gtk.Box())
137 t00mlabs 207
        viewsbox.set_hexpand(True)
208
        vwp.add(viewsbox)
209
        scr.add(vwp)
166 t00m 210
        box.pack_start(scr, True, True, 0)
137 t00mlabs 211
        paned.add1(box)
82 t00mlabs 212
 
137 t00mlabs 213
        ## Right view
213 t00m 214
        box = Gtk.VBox()
137 t00mlabs 215
        box.set_hexpand(True)
214 t00m 216
        self.stack_main = self.gui.add_widget('gtk_stack_main', Gtk.Stack())
215 t00m 217
        # ~ self.stack_main.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
218
        # ~ self.stack_main.set_transition_duration(2500)
214 t00m 219
        box.pack_start(self.stack_main, True, True, 0)
168 t00m 220
 
215 t00m 221
        ### Repository stack
214 t00m 222
        stack = self.setup_stack_visor()
223
        self.stack_main.add_titled(stack, "visor", "SAP Notes Visor")
168 t00m 224
 
215 t00m 225
        ### About stack
226
        stack = self.setup_stack_about()
227
        self.stack_main.add_titled(stack, "about", "About Basico")
207 t00m 228
 
215 t00m 229
        ### Settings stack
230
        stack = self.setup_stack_settings()
231
        self.stack_main.add_titled(stack, "settings", "Basico Settings")
232
 
207 t00m 233
        ## Dialogs
213 t00m 234
        boxdialogs = self.gui.add_widget('gtk_box_container_dialogs', Gtk.Box())
207 t00m 235
        boxdialogs.set_no_show_all(True)
236
        boxdialogs.hide()
237
        box.pack_start(boxdialogs, True, True, 6)
238
 
137 t00mlabs 239
        paned.add2(box)
142 t00mlabs 240
        mainbox.pack_start(paned, True, True, 0)
82 t00mlabs 241
 
162 t00m 242
        # Statusbar
213 t00m 243
        statusbar = self.gui.add_widget('widget_statusbar', Statusbar(self.controller))
142 t00mlabs 244
        mainbox.pack_start(statusbar, False, False, 0)
245
 
203 t00m 246
        # Menu Views
247
        vbox = Gtk.VBox()
213 t00m 248
        viewsbox = self.gui.get_widget('gtk_box_container_views')
203 t00m 249
        viewmenu = self.gui.add_widget('viewmenu', SAPNoteViewMenu(self.controller))
250
        viewmenu.set_hexpand(True)
251
        viewmenu.set_vexpand(True)
252
        vbox.pack_start(viewmenu, True, True, 0)
253
        self.gui.swap_widget(viewsbox, vbox)
254
 
255
        viewmenu = self.gui.get_widget('viewmenu')
256
        viewmenu.set_view('task')
257
 
137 t00mlabs 258
        self.add(mainbox)
259
        self.show_all()
82 t00mlabs 260
 
261
 
214 t00m 262
    def setup_stack_visor(self):
263
        box = Gtk.VBox()
264
        box.set_hexpand(True)
265
 
266
        ### Toolbar
267
        boxtoolbar = self.gui.add_widget('gtk_hbox_container_toolbar', Gtk.HBox())
268
        box.pack_start(boxtoolbar, False, False, 0)
269
        visortoolbar = self.gui.add_widget('visortoolbar', SAPNoteViewVisorToolbar(self.controller))
270
        self.gui.swap_widget(boxtoolbar, visortoolbar)
271
 
272
        ### Visor
273
        scr = Gtk.ScrolledWindow()
274
        scr.set_hexpand(True)
275
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
276
        vwp = Gtk.Viewport()
277
        vwp.set_hexpand(True)
278
        visor = self.gui.add_widget('visor', SAPNoteViewVisor(self.controller))
279
        visor.set_hexpand(True)
280
        visor.set_vexpand(True)
281
        vwp.add(visor)
282
        scr.add(vwp)
283
        box.pack_start(scr, True, True, 0)
284
        visor.show_all()
285
        box.show_all()
286
        return box
215 t00m 287
 
288
 
289
    def setup_stack_about(self):
290
        box = Gtk.VBox()
291
        box.set_hexpand(True)
292
        box.pack_start(About(), True, True, 0)
293
        box.show_all()
294
        return box
295
 
296
 
297
    def setup_stack_settings(self):
298
        box = Gtk.VBox()
299
        box.set_hexpand(True)
300
        settings = self.gui.add_widget('widget_settings', SettingsView(self.controller))
301
        box.pack_start(settings, True, True, 0)
302
        box.show_all()
303
        return box