Subversion Repositories basico

Rev

Rev 183 | Rev 187 | 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
 
183 t00m 24
from .widgets import Statusbar, ImportWidget
133 t00mlabs 25
from .service import Service
4 t00mlabs 26
 
133 t00mlabs 27
class GtkAppWindow(Gtk.ApplicationWindow, Service):
4 t00mlabs 28
    def __init__(self, uiapp):
29
        self.setup_controller(uiapp)
30
        self.get_services()
142 t00mlabs 31
        self.log = self.controller.log
4 t00mlabs 32
        self.gui.add_widget('uiapp', uiapp)
33
        self.setup_window()
141 t00mlabs 34
        self.controller.debug("Window setup correctly")
4 t00mlabs 35
        self.setup_widgets()
141 t00mlabs 36
        self.controller.debug("Widgets setup correctly")
4 t00mlabs 37
 
106 t00mlabs 38
 
182 t00m 39
    def get_services(self):
40
        self.gui = self.controller.get_service("GUI")
41
        self.app = self.gui.get_app()
42
        self.db = self.controller.get_service("DB")
43
        self.uif = self.controller.get_service("UIF")
44
        self.prefs = self.controller.get_service("Settings")
45
        self.im = self.controller.get_service('IM')
46
        self.cb = self.controller.get_service('Callbacks')
4 t00mlabs 47
 
141 t00mlabs 48
 
4 t00mlabs 49
    def setup_controller(self, uiapp):
50
        self.uiapp = uiapp
51
        self.controller = uiapp.get_controller()
52
 
53
 
54
    def setup_window(self):
55
        app_title = self.controller.get_app_info('name')
56
        Gtk.Window.__init__(self, title=app_title, application=self.uiapp)
57
        self.gui.add_widget('mainwindow', self)
153 t00m 58
        icon = self.im.get_icon('basico', 48, 48)
4 t00mlabs 59
        self.set_icon(icon)
60
        # FIXME
61
        # From docs: Don’t use this function. It sets the X xlib.Window
62
        # System “class” and “name” hints for a window.
63
        # But I have to do it or it doesn't shows the right title. ???
64
        self.set_wmclass (app_title, app_title)
65
        self.set_role(app_title)
66
        self.set_default_size(1024, 728)
67
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
93 t00mlabs 68
        self.setup_headerbar()
4 t00mlabs 69
        self.show_all()
70
 
71
 
77 t00mlabs 72
    def setup_headerbar(self):
73
        hb = self.gui.add_widget("HeaderBar", Gtk.HeaderBar())
74
        hb.set_show_close_button(True)
75
        hb.props.title = "Basico"
79 t00mlabs 76
        hb.props.subtitle = "SAP Notes Manager for SAP Consultants"
180 t00m 77
        lhbox = self.setup_headerbar_left(hb)
78
        rhbox = self.setup_headerbar_right(hb)
79
        hb.pack_start(lhbox)
80
        hb.pack_end(rhbox)
81
        self.set_titlebar(hb)
82
        hb.show_all()
83
 
182 t00m 84
 
180 t00m 85
    def setup_headerbar_left(self, hb):
185 t00m 86
        lhbox = Gtk.HBox()
87
 
131 t00mlabs 88
        button = self.gui.add_widget('tgbShowMenuView', Gtk.ToggleButton())
141 t00mlabs 89
        button.set_active(False)
131 t00mlabs 90
        icon = self.im.get_image_icon('gtk-select-color')
91
        button.add(icon)
92
        lhbox.pack_start(button, False, False, 3)
157 t00m 93
        menuviews = self.gui.add_widget('mnuBtnViews', Gtk.Button())
130 t00mlabs 94
        hbox = Gtk.HBox()
95
        label = self.gui.add_widget('lblViewCurrent', Gtk.Label())
141 t00mlabs 96
        label.set_xalign(0.0)
130 t00mlabs 97
        image = self.gui.add_widget('imgViewCurrent', Gtk.Image())
98
        hbox.pack_start(image, False, False, 3)
99
        hbox.pack_start(label, False, False, 3)
100
        menuviews.add(hbox)
101
        lhbox.pack_start(menuviews, False, False, 3)
81 t00mlabs 102
        imgtitlebar = self.gui.add_widget('imgtitlebar', Gtk.Image())
101 t00mlabs 103
        imgtitlebar.set_visible(False)
104
        imgtitlebar.set_no_show_all(True)
79 t00mlabs 105
        lbltitlebar = self.gui.add_widget("lbltitlebar", Gtk.Label())
141 t00mlabs 106
        lbltitlebar.set_xalign(0.0)
107
        lbltitlebar.set_justify(Gtk.Justification.LEFT)
130 t00mlabs 108
        lbltitlebar.set_visible(False)
109
        lbltitlebar.set_no_show_all(True)
81 t00mlabs 110
        lhbox.pack_start(imgtitlebar, False, False, 3)
111
        lhbox.pack_start(lbltitlebar, False, False, 3)
112
        lhbox.show_all()
77 t00mlabs 113
 
180 t00m 114
        return lhbox
115
 
116
 
117
    def setup_headerbar_right(self, hb):
185 t00m 118
        rhbox = Gtk.HBox()
180 t00m 119
 
120
        # Import button
121
        button = Gtk.Button()
122
        icon = self.im.get_image_icon('basico-add', 24, 24)
123
        button.set_image(icon)
130 t00mlabs 124
        button.set_relief(Gtk.ReliefStyle.NONE)
181 t00m 125
        popover = self.gui.add_widget('dlpopover', Gtk.Popover.new(button))
180 t00m 126
        button.connect('clicked', self.cb.show_popover_menu, popover)
127
        button.show_all()
130 t00mlabs 128
 
180 t00m 129
        # Popover body
130
        box = Gtk.Box(spacing = 0, orientation="vertical")
131
        box.set_property('margin', 3)
183 t00m 132
        custom_vbox = self.gui.add_widget('import_widget', ImportWidget(self.controller))
180 t00m 133
        box.add(custom_vbox)
134
        popover.add(box)
135
        rhbox.pack_start(button, False, False, 6)
136
 
153 t00m 137
        ## System Menu
77 t00mlabs 138
        button = Gtk.Button()
155 t00m 139
        icon = self.im.get_pixbuf_icon('menu-system', 24, 24)
81 t00mlabs 140
        image = Gtk.Image()
141
        image.set_from_pixbuf(icon)
142
        button.set_image(image)
77 t00mlabs 143
        button.set_relief(Gtk.ReliefStyle.NONE)
122 t00mlabs 144
        popover = Gtk.Popover.new(button)
150 t00m 145
        self.gui.add_widget('popover-right-menu', popover)
122 t00mlabs 146
        button.connect('clicked', self.cb.show_popover_menu, popover)
147
        #~ button.connect('clicked', self.uiapp.cb_show_about)
77 t00mlabs 148
        rhbox.pack_end(button, False, False, 0)
79 t00mlabs 149
 
122 t00mlabs 150
        # Popover body
151
        box = Gtk.Box(spacing = 0, orientation="vertical")
152
 
153 t00m 153
        ### About
122 t00mlabs 154
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
155
        icon = self.im.get_pixbuf_icon('about', 24, 24)
156
        image = Gtk.Image()
157
        image.set_from_pixbuf(icon)
158
        label = Gtk.Label("About")
159
        hbox.pack_start(image, False, False, 3)
160
        hbox.pack_start(label, False, False, 3)
161
        button = Gtk.Button()
162
        button.add(hbox)
163
        button.set_relief(Gtk.ReliefStyle.NONE)
136 t00mlabs 164
        button.connect('clicked', self.cb.show_about)
122 t00mlabs 165
        box.pack_end(button, False, False, 0)
166
 
153 t00m 167
        ### Help
122 t00mlabs 168
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
153 t00m 169
        icon = self.im.get_pixbuf_icon('basico-help', 24, 24)
93 t00mlabs 170
        image = Gtk.Image()
171
        image.set_from_pixbuf(icon)
122 t00mlabs 172
        label = Gtk.Label("Help")
173
        hbox.pack_start(image, False, False, 3)
174
        hbox.pack_start(label, False, False, 3)
175
        button = Gtk.Button()
176
        button.add(hbox)
93 t00mlabs 177
        button.set_relief(Gtk.ReliefStyle.NONE)
178
        button.connect('clicked', self.cb.show_help)
122 t00mlabs 179
        box.pack_end(button, False, False, 0)
93 t00mlabs 180
 
153 t00m 181
        ### Log viewer
122 t00mlabs 182
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
153 t00m 183
        icon = self.im.get_pixbuf_icon('basico-logviewer', 24, 24)
184
        image = Gtk.Image()
185
        image.set_from_pixbuf(icon)
186
        label = Gtk.Label("Log viewer")
187
        hbox.pack_start(image, False, False, 3)
188
        hbox.pack_start(label, False, False, 3)
189
        button = Gtk.Button()
190
        button.add(hbox)
191
        button.set_relief(Gtk.ReliefStyle.NONE)
192
        button.connect('clicked', self.cb.show_log)
193
        box.pack_end(button, False, False, 0)
194
 
195
        ### Settings
196
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
155 t00m 197
        icon = self.im.get_pixbuf_icon('basico-settings', 24, 24)
81 t00mlabs 198
        image = Gtk.Image()
199
        image.set_from_pixbuf(icon)
122 t00mlabs 200
        label = Gtk.Label("Settings")
201
        hbox.pack_start(image, False, False, 3)
202
        hbox.pack_start(label, False, False, 3)
203
        button = Gtk.Button()
204
        button.add(hbox)
79 t00mlabs 205
        button.set_relief(Gtk.ReliefStyle.NONE)
122 t00mlabs 206
        button.connect('clicked', self.cb.show_settings)
130 t00mlabs 207
        box.pack_start(button, False, False, 0)
122 t00mlabs 208
        popover.add(box)
180 t00m 209
        return rhbox
77 t00mlabs 210
 
211
 
4 t00mlabs 212
    def setup_widgets(self):
137 t00mlabs 213
        # Mainbox
142 t00mlabs 214
        mainbox = self.gui.add_widget('mainbox', Gtk.VBox())
137 t00mlabs 215
        mainbox.set_hexpand(True)
216
        paned = self.gui.add_widget('paned', Gtk.HPaned())
178 t00m 217
        paned.set_property('margin-bottom', 6)
218
        paned.set_wide_handle(False)
164 t00m 219
        paned.set_position(300)
82 t00mlabs 220
 
137 t00mlabs 221
        # Paned
222
        ## Left view
166 t00m 223
        box = self.gui.add_widget('boxMenuView', Gtk.VBox())
224
        box.set_property('margin-left', 6)
225
        box.set_property('margin-right', 6)
176 t00m 226
        box.set_property('margin-bottom', 0)
166 t00m 227
 
228
        ### Toolbar
229
        toolbar = Gtk.Toolbar()
230
        toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
231
 
232
        #### Filter entry tool
233
        tool = Gtk.ToolItem.new()
234
 
235
        hbox = Gtk.HBox()
236
        viewfilter = self.gui.add_widget('viewfilter', Gtk.Entry())
178 t00m 237
        viewfilter.connect('activate', self.cb.filter_viewmenu)
175 t00m 238
 
239
        icon = self.im.get_pixbuf_icon('basico-refresh')
240
        viewfilter.set_icon_from_pixbuf(Gtk.EntryIconPosition.PRIMARY, icon)
241
        viewfilter.set_icon_sensitive(Gtk.EntryIconPosition.PRIMARY, True)
242
        viewfilter.set_icon_tooltip_markup (Gtk.EntryIconPosition.PRIMARY, "Refresh and collapse")
243
 
244
        icon = self.im.get_pixbuf_icon('basico-filter')
245
        viewfilter.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, icon)
246
        viewfilter.set_icon_sensitive(Gtk.EntryIconPosition.SECONDARY, True)
247
        viewfilter.set_icon_tooltip_markup (Gtk.EntryIconPosition.SECONDARY, "Click here to expand the tree")
248
        viewfilter.set_placeholder_text("Filter this view...")
249
 
250
        def on_icon_pressed(entry, icon_pos, event):
251
            if icon_pos == Gtk.EntryIconPosition.PRIMARY:
252
                viewmenu = self.gui.get_widget('viewmenu')
253
                viewmenu.refresh()
254
            elif icon_pos == Gtk.EntryIconPosition.SECONDARY:
255
                self.cb.expand_menuview()
256
 
257
        viewfilter.connect("icon-press", on_icon_pressed)
258
 
166 t00m 259
        hbox.pack_start(viewfilter, True, True, 0)
260
        tool.add(hbox)
261
        tool.set_expand(True)
262
        toolbar.insert(tool, -1)
263
 
264
        box.pack_start(toolbar, False, False, 0)
265
 
185 t00m 266
        ### View treeview
137 t00mlabs 267
        scr = Gtk.ScrolledWindow()
268
        scr.set_hexpand(True)
269
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
164 t00m 270
        scr.set_shadow_type(Gtk.ShadowType.IN)
137 t00mlabs 271
        vwp = Gtk.Viewport()
272
        vwp.set_hexpand(True)
273
        viewsbox = self.gui.add_widget('viewsbox', Gtk.Box())
274
        viewsbox.set_hexpand(True)
275
        vwp.add(viewsbox)
276
        scr.add(vwp)
166 t00m 277
        box.pack_start(scr, True, True, 0)
137 t00mlabs 278
        paned.add1(box)
82 t00mlabs 279
 
137 t00mlabs 280
        ## Right view
168 t00m 281
        box = self.gui.add_widget('boxVisor', Gtk.VBox())
137 t00mlabs 282
        box.set_hexpand(True)
168 t00m 283
 
284
        boxtoolbar = self.gui.add_widget('boxtoolbar', Gtk.HBox())
285
        box.pack_start(boxtoolbar, False, False, 0)
286
 
137 t00mlabs 287
        scr = self.gui.add_widget('scrVisor', Gtk.ScrolledWindow())
288
        scr.set_hexpand(True)
289
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
290
        vwp = Gtk.Viewport()
291
        vwp.set_hexpand(True)
292
        notesbox = self.gui.add_widget('notesbox', Gtk.Box())
293
        notesbox.set_hexpand(True)
168 t00m 294
        notesbox.set_vexpand(True)
137 t00mlabs 295
        vwp.add(notesbox)
296
        scr.add(vwp)
168 t00m 297
        box.pack_start(scr, True, True, 0)
137 t00mlabs 298
        paned.add2(box)
142 t00mlabs 299
        mainbox.pack_start(paned, True, True, 0)
82 t00mlabs 300
 
162 t00m 301
        # Statusbar
142 t00mlabs 302
        statusbar = self.gui.add_widget('statusbar', Statusbar(self.controller))
303
        mainbox.pack_start(statusbar, False, False, 0)
304
 
137 t00mlabs 305
        self.add(mainbox)
306
        self.show_all()
82 t00mlabs 307
 
141 t00mlabs 308
        # Finally, activate Workplace
309
        self.controller.get_service('Workplace')
82 t00mlabs 310