Subversion Repositories basico

Rev

Rev 201 | Rev 207 | 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
26
from .widgets import About
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)
60
        self.gui.add_widget('mainwindow', 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):
76
        hb = self.gui.add_widget("HeaderBar", Gtk.HeaderBar())
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)
150 t00m 107
        self.gui.add_widget('popover-right-menu', 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
        ### Help
122 t00mlabs 129
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
153 t00m 130
        icon = self.im.get_pixbuf_icon('basico-help', 24, 24)
93 t00mlabs 131
        image = Gtk.Image()
132
        image.set_from_pixbuf(icon)
122 t00mlabs 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)
93 t00mlabs 138
        button.set_relief(Gtk.ReliefStyle.NONE)
188 t00m 139
        button.connect('clicked', self.cb.gui_show_help)
122 t00mlabs 140
        box.pack_end(button, False, False, 0)
93 t00mlabs 141
 
153 t00m 142
        ### Log viewer
122 t00mlabs 143
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
153 t00m 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)
188 t00m 153
        button.connect('clicked', self.cb.gui_show_log)
153 t00m 154
        box.pack_end(button, False, False, 0)
155
 
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
142 t00mlabs 175
        mainbox = self.gui.add_widget('mainbox', Gtk.VBox())
137 t00mlabs 176
        mainbox.set_hexpand(True)
177
        paned = self.gui.add_widget('paned', 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
166 t00m 184
        box = self.gui.add_widget('boxMenuView', Gtk.VBox())
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()
197
        viewfilter = self.gui.add_widget('viewfilter', 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)
234
        viewsbox = self.gui.add_widget('viewsbox', Gtk.Box())
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
168 t00m 242
        box = self.gui.add_widget('boxVisor', Gtk.VBox())
137 t00mlabs 243
        box.set_hexpand(True)
168 t00m 244
 
245
        boxtoolbar = self.gui.add_widget('boxtoolbar', Gtk.HBox())
246
        box.pack_start(boxtoolbar, False, False, 0)
247
 
137 t00mlabs 248
        scr = self.gui.add_widget('scrVisor', Gtk.ScrolledWindow())
249
        scr.set_hexpand(True)
250
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
251
        vwp = Gtk.Viewport()
252
        vwp.set_hexpand(True)
253
        notesbox = self.gui.add_widget('notesbox', Gtk.Box())
254
        notesbox.set_hexpand(True)
168 t00m 255
        notesbox.set_vexpand(True)
137 t00mlabs 256
        vwp.add(notesbox)
257
        scr.add(vwp)
168 t00m 258
        box.pack_start(scr, True, True, 0)
137 t00mlabs 259
        paned.add2(box)
142 t00mlabs 260
        mainbox.pack_start(paned, True, True, 0)
82 t00mlabs 261
 
162 t00m 262
        # Statusbar
142 t00mlabs 263
        statusbar = self.gui.add_widget('statusbar', Statusbar(self.controller))
264
        mainbox.pack_start(statusbar, False, False, 0)
265
 
203 t00m 266
        # Menu Views
267
        vbox = Gtk.VBox()
268
        viewsbox = self.gui.get_widget('viewsbox')
269
        viewmenu = self.gui.add_widget('viewmenu', SAPNoteViewMenu(self.controller))
270
        viewmenu.set_hexpand(True)
271
        viewmenu.set_vexpand(True)
272
        vbox.pack_start(viewmenu, True, True, 0)
273
        self.gui.swap_widget(viewsbox, vbox)
274
 
275
        # SAP Notes Visor
276
        vbox = self.gui.add_widget('visor_container', Gtk.VBox())
277
        visortoolbar = self.gui.add_widget('visortoolbar', SAPNoteViewVisorToolbar(self.controller))
278
        boxtoolbar = self.gui.get_widget('boxtoolbar')
279
        self.gui.swap_widget(boxtoolbar, visortoolbar)
280
 
281
        visorbox = self.gui.get_widget('notesbox')
282
        visor = self.gui.add_widget('visor', SAPNoteViewVisor(self.controller))
283
        visor.set_hexpand(True)
284
        visor.set_vexpand(True)
285
        vbox.pack_start(visor, True, True, 0)
286
        self.gui.swap_widget(visorbox, vbox)
287
 
288
        viewmenu = self.gui.get_widget('viewmenu')
289
        viewmenu.set_view('task')
290
        visorbox = self.gui.get_widget('notesbox')
291
        self.gui.swap_widget(visorbox, About())
292
 
137 t00mlabs 293
        self.add(mainbox)
294
        self.show_all()
82 t00mlabs 295
 
296