Subversion Repositories basico

Rev

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