Subversion Repositories basico

Rev

Rev 130 | Rev 133 | 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 threading
11
import time
12
import platform
13
 
14
import gi
15
gi.require_version('Gtk', '3.0')
16
gi.require_version('WebKit', '3.0')
17
 
18
from gi.repository import GLib
19
from gi.repository import GObject
20
from gi.repository import Gtk
21
from gi.repository import Gdk
22
from gi.repository import Gio
23
from gi.repository import Pango
24
from gi.repository import WebKit
25
from gi.repository.GdkPixbuf import Pixbuf
26
 
27
from .log import get_logger
106 t00mlabs 28
#~ from .sapnoteview import SAPNoteView
4 t00mlabs 29
 
30
 
31
MONOSPACE_FONT = 'Lucida Console' if platform.system() == 'Windows' else 'monospace'
32
 
33
class GtkAppWindow(Gtk.ApplicationWindow):
34
    def __init__(self, uiapp):
35
        self.setup_controller(uiapp)
36
        self.get_services()
37
        self.gui.add_widget('uiapp', uiapp)
38
        self.gui.set_key('cmbvalue', 'search')
39
        self.settings = {}
40
        self.settings['fullscreen'] = False
41
        self.current_notes = {}
42
 
43
        self.setup_window()
44
        self.setup_widgets()
45
        self.setup_app()
46
 
106 t00mlabs 47
        self.gui.get_service('Workplace')
48
 
95 t00mlabs 49
        # Then run webserver
100 t00mlabs 50
        #~ self.webserver = self.controller.get_service('WebServer')
51
        #~ self.webserver.run()
4 t00mlabs 52
 
95 t00mlabs 53
 
4 t00mlabs 54
    def setup_controller(self, uiapp):
55
        self.uiapp = uiapp
56
        self.controller = uiapp.get_controller()
57
 
58
 
59
    def setup_app(self):
106 t00mlabs 60
        #~ sapnoteview = self.gui.get_widget('viewmenu')
4 t00mlabs 61
        searchentry = self.gui.get_widget("stySearchInfo")
62
        viewlabel = self.gui.get_widget('lblViewCurrent')
106 t00mlabs 63
        #~ try:
64
            #~ name = sapnoteview.get_view()
65
        #~ except:
66
            #~ name = 'components'
67
        #~ sapnoteview.set_view(name)
91 t00mlabs 68
        #~ label = "<span size='20000'><b>%-10s</b></span>" % name.capitalize()
106 t00mlabs 69
        #~ label = "<b>%-10s</b>" % name.capitalize()
70
        #~ viewlabel.set_markup(label)
102 t00mlabs 71
        #~ self.cb.refresh_view()
4 t00mlabs 72
        searchentry.set_text('')
102 t00mlabs 73
        #~ self.cb.search_notes()
106 t00mlabs 74
        #~ sapnoteview.check_states()
4 t00mlabs 75
 
76
 
77
    def setup_window(self):
78
        app_title = self.controller.get_app_info('name')
79
        Gtk.Window.__init__(self, title=app_title, application=self.uiapp)
80
        self.gui.add_widget('mainwindow', self)
81
        icon = self.im.get_icon('basico')
82
        self.set_icon(icon)
83
        # FIXME
84
        # From docs: Don’t use this function. It sets the X xlib.Window
85
        # System “class” and “name” hints for a window.
86
        # But I have to do it or it doesn't shows the right title. ???
87
        self.set_wmclass (app_title, app_title)
88
        self.set_role(app_title)
89
        self.set_default_size(1024, 728)
90
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
91
        #~ self.connect('destroy', Gtk.main_quit)
93 t00mlabs 92
 
93
        # HEADERBAR WIDGETS
94
        self.setup_headerbar()
4 t00mlabs 95
        self.show_all()
96
 
97
 
77 t00mlabs 98
    def setup_headerbar(self):
99
        #~# Header Bar
100
        hb = self.gui.add_widget("HeaderBar", Gtk.HeaderBar())
101
        hb.set_show_close_button(True)
102
        hb.props.title = "Basico"
79 t00mlabs 103
        hb.props.subtitle = "SAP Notes Manager for SAP Consultants"
77 t00mlabs 104
 
79 t00mlabs 105
        lhbox = Gtk.HBox() # Left side of title bar
106
        mhbox = Gtk.HBox() # Mid side of title bar
107
        rhbox = Gtk.HBox() # Right side of title bar
77 t00mlabs 108
 
79 t00mlabs 109
        # Left side titlebar
131 t00mlabs 110
        button = self.gui.add_widget('tgbShowMenuView', Gtk.ToggleButton())
111
        icon = self.im.get_image_icon('gtk-select-color')
112
        button.add(icon)
113
        lhbox.pack_start(button, False, False, 3)
114
 
130 t00mlabs 115
        menuviews = self.gui.add_widget('mnuBtnViews', Gtk.MenuButton())
116
        hbox = Gtk.HBox()
117
        label = self.gui.add_widget('lblViewCurrent', Gtk.Label())
118
        image = self.gui.add_widget('imgViewCurrent', Gtk.Image())
119
        hbox.pack_start(image, False, False, 3)
120
        hbox.pack_start(label, False, False, 3)
121
        menuviews.add(hbox)
122
        lhbox.pack_start(menuviews, False, False, 3)
123
 
81 t00mlabs 124
        imgtitlebar = self.gui.add_widget('imgtitlebar', Gtk.Image())
101 t00mlabs 125
        imgtitlebar.set_visible(False)
126
        imgtitlebar.set_no_show_all(True)
79 t00mlabs 127
        lbltitlebar = self.gui.add_widget("lbltitlebar", Gtk.Label())
130 t00mlabs 128
        lbltitlebar.set_visible(False)
129
        lbltitlebar.set_no_show_all(True)
130
        #~ self.cb.update_titlebar_title("Dashboard", "dashboard")
81 t00mlabs 131
        #~ lbltitlebar.set_markup("<big><b>Dashboard</b></big>")
132
        lhbox.pack_start(imgtitlebar, False, False, 3)
133
        lhbox.pack_start(lbltitlebar, False, False, 3)
134
        lhbox.show_all()
79 t00mlabs 135
        hb.pack_start(lhbox)
77 t00mlabs 136
 
79 t00mlabs 137
        # Middle side titlebar
130 t00mlabs 138
        # Menu Actions
139
        #~ def estoy_toggled(btnactions):
140
            #~ total = self.db.get_total()
141
            #~ self.log.debug("TOTAL: %d" % total)
142
            #~ if total > 0:
143
                #~ actions_menu = self.gui.get_widget('actions_menu')
144
                #~ btnactions.set_menu_model(actions_menu)
145
            #~ else:
146
                #~ btnactions.set_menu_model(None)
147
 
148
            #~ return True
149
 
150
        label = self.gui.add_widget('lblSelectedNotes', Gtk.Label())
151
        #~ label.set_markup('<b><small>0</small>/0 of <big>%d</big></b>' % self.db.get_total())
152
        button = self.gui.add_widget('mnuBtnActions', Gtk.MenuButton())
153
        #~ button.connect('toggled', estoy_toggled)
154
        button.set_relief(Gtk.ReliefStyle.NONE)
155
        button.set_no_show_all(False)
156
        button.set_visible(False)
157
        button.add(label)
158
        mhbox.pack_start(button, False, False, 0)
159
 
160
        # Quick SAP Note Entry
161
        #~ label = Gtk.Label()
162
        #~ label.set_markup("<b>Quick SAP Note </b>")
163
        #~ mhbox.pack_start(label, False, False, 0)
164
        #~ entry = Gtk.Entry()
165
        #~ entry.set_max_length(10)
166
        #~ entry.set_max_width_chars(5)
167
        #~ entry.set_width_chars(10)
168
        #~ entry.set_alignment(xalign=1)
169
        #~ mhbox.pack_start(entry, False, False, 0)
170
 
79 t00mlabs 171
        # Dashboard button
100 t00mlabs 172
        #~ button = self.gui.add_widget('btnDashboard', Gtk.Button())
173
        #~ button.set_tooltip_markup('<big><b>Dashboard</b></big>')
174
        #~ icon = self.im.get_pixbuf_icon('dashboard', 24, 24)
175
        #~ image = Gtk.Image()
176
        #~ image.set_from_pixbuf(icon)
177
        #~ button.set_image(image)
178
        #~ button.set_relief(Gtk.ReliefStyle.NONE)
179
        #~ button.connect('clicked', self.cb.show_dashboard)
180
        #~ mhbox.pack_start(button, False, False, 0)
78 t00mlabs 181
 
79 t00mlabs 182
        # Workplace button
130 t00mlabs 183
        #~ button = Gtk.Button()
184
        #~ button.set_tooltip_markup('<big><b>Workplace</b></big>')
185
        #~ icon = self.im.get_pixbuf_icon('workplace', 24, 24)
186
        #~ image = Gtk.Image()
187
        #~ image.set_from_pixbuf(icon)
188
        #~ button.set_image(image)
189
        #~ button.set_relief(Gtk.ReliefStyle.NONE)
190
        #~ button.connect('clicked', self.cb.show_workplace)
191
        #~ mhbox.pack_start(button, False, False, 0)
78 t00mlabs 192
 
84 t00mlabs 193
 
194
        # Workbook button
130 t00mlabs 195
        #~ button = Gtk.Button()
196
        #~ button.set_tooltip_markup('<big><b>Workbook</b></big>')
197
        #~ icon = self.im.get_pixbuf_icon('comments', 24, 24)
198
        #~ image = Gtk.Image()
199
        #~ image.set_from_pixbuf(icon)
200
        #~ button.set_image(image)
201
        #~ button.set_relief(Gtk.ReliefStyle.NONE)
202
        #~ button.connect('clicked', self.cb.show_workbook)
203
        #~ mhbox.pack_start(button, False, False, 0)
81 t00mlabs 204
 
84 t00mlabs 205
 
206
        # School button
130 t00mlabs 207
        #~ button = Gtk.Button()
208
        #~ button.set_tooltip_markup('<big><b>My SAP School</b></big>')
209
        #~ icon = self.im.get_pixbuf_icon('school', 24, 24)
210
        #~ image = Gtk.Image()
211
        #~ image.set_from_pixbuf(icon)
212
        #~ button.set_image(image)
213
        #~ button.set_relief(Gtk.ReliefStyle.NONE)
214
        #~ button.connect('clicked', self.cb.show_school)
215
        #~ mhbox.pack_start(button, False, False, 0)
81 t00mlabs 216
 
130 t00mlabs 217
        #~ label = Gtk.Label()
218
        #~ label.set_markup("<b> SAP Note </b>")
219
        #~ mhbox.pack_start(label, False, False, 0)
81 t00mlabs 220
 
130 t00mlabs 221
 
84 t00mlabs 222
        # Search entry
223
        #~ button = Gtk.Button()
224
        #~ button.set_tooltip_markup('<big><b>Search</b></big>')
225
        #~ icon = self.im.get_pixbuf_icon('bsearch', 24, 24)
226
        #~ image = Gtk.Image()
227
        #~ image.set_from_pixbuf(icon)
228
        #~ button.set_image(image)
229
        #~ button.set_relief(Gtk.ReliefStyle.NONE)
230
        #~ button.connect('clicked', self.cb.toggle_search)
231
        #~ mhbox.pack_start(button, False, False, 0)
81 t00mlabs 232
 
84 t00mlabs 233
 
78 t00mlabs 234
        # Right side titlebar
130 t00mlabs 235
        # MnuButton valid with any modern version of Gtk (?> 3.10)
236
        btnactions = self.gui.add_widget('mnuBtnImport', Gtk.MenuButton())
237
        btnactions.set_always_show_image(True)
238
        btnactions.set_property("use-popover", True)
239
        btnactions.set_relief(Gtk.ReliefStyle.NONE)
240
        imgwpimport = Gtk.Image()
241
        icon = self.im.get_pixbuf_icon('download', 22, 22)
242
        imgwpimport.set_from_pixbuf(icon)
243
        btnactions.add(imgwpimport)
244
        #~ actions_menu = self.gui.get_widget('actions_menu')
245
        #~ btnactions.set_menu_model(actions_menu)
246
        rhbox.pack_start(btnactions, False, False, 0)
247
 
122 t00mlabs 248
        # Menu
77 t00mlabs 249
        button = Gtk.Button()
122 t00mlabs 250
        #~ button.set_tooltip_markup('<big><b>About</b></big>')
251
        icon = self.im.get_pixbuf_icon('menu', 24, 24)
81 t00mlabs 252
        image = Gtk.Image()
253
        image.set_from_pixbuf(icon)
254
        button.set_image(image)
77 t00mlabs 255
        button.set_relief(Gtk.ReliefStyle.NONE)
122 t00mlabs 256
        popover = Gtk.Popover.new(button)
257
        button.connect('clicked', self.cb.show_popover_menu, popover)
258
        #~ button.connect('clicked', self.uiapp.cb_show_about)
77 t00mlabs 259
        rhbox.pack_end(button, False, False, 0)
79 t00mlabs 260
 
122 t00mlabs 261
        # Popover body
262
        box = Gtk.Box(spacing = 0, orientation="vertical")
263
 
264
        # About
265
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
266
        icon = self.im.get_pixbuf_icon('about', 24, 24)
267
        image = Gtk.Image()
268
        image.set_from_pixbuf(icon)
269
        label = Gtk.Label("About")
270
        hbox.pack_start(image, False, False, 3)
271
        hbox.pack_start(label, False, False, 3)
272
        button = Gtk.Button()
273
        button.add(hbox)
274
        button.set_relief(Gtk.ReliefStyle.NONE)
275
        button.connect('clicked', self.uiapp.cb_show_about)
276
        box.pack_end(button, False, False, 0)
277
 
93 t00mlabs 278
        # Help
122 t00mlabs 279
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
93 t00mlabs 280
        icon = self.im.get_pixbuf_icon('basico_help', 24, 24)
281
        image = Gtk.Image()
282
        image.set_from_pixbuf(icon)
122 t00mlabs 283
        label = Gtk.Label("Help")
284
        hbox.pack_start(image, False, False, 3)
285
        hbox.pack_start(label, False, False, 3)
286
        button = Gtk.Button()
287
        button.add(hbox)
93 t00mlabs 288
        button.set_relief(Gtk.ReliefStyle.NONE)
289
        button.connect('clicked', self.cb.show_help)
122 t00mlabs 290
        box.pack_end(button, False, False, 0)
93 t00mlabs 291
 
79 t00mlabs 292
        # Settings
122 t00mlabs 293
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
81 t00mlabs 294
        icon = self.im.get_pixbuf_icon('settings', 24, 24)
295
        image = Gtk.Image()
296
        image.set_from_pixbuf(icon)
122 t00mlabs 297
        label = Gtk.Label("Settings")
298
        hbox.pack_start(image, False, False, 3)
299
        hbox.pack_start(label, False, False, 3)
300
        button = Gtk.Button()
301
        button.add(hbox)
79 t00mlabs 302
        button.set_relief(Gtk.ReliefStyle.NONE)
122 t00mlabs 303
        button.connect('clicked', self.cb.show_settings)
130 t00mlabs 304
        box.pack_start(button, False, False, 0)
110 t00mlabs 305
 
122 t00mlabs 306
        popover.add(box)
307
 
308
        #~ # Settings
309
        #~ button = Gtk.Button()
310
        #~ button.set_tooltip_markup('<big><b>Settings</b></big>')
311
        #~ icon = self.im.get_pixbuf_icon('settings', 24, 24)
312
        #~ image = Gtk.Image()
313
        #~ image.set_from_pixbuf(icon)
314
        #~ button.set_image(image)
315
        #~ button.set_relief(Gtk.ReliefStyle.NONE)
316
 
110 t00mlabs 317
        # Popover settings
122 t00mlabs 318
        #~ popover = self.setup_popover_settings(button)
319
        #~ button.connect('clicked', self.cb.show_settings, popover)
320
        #~ button.show_all()
321
        #~ self.cb.update_titlebar_title("Settings", "settings")
322
        #~ rhbox.pack_end(button, False, False, 0)
130 t00mlabs 323
 
77 t00mlabs 324
        hb.pack_end(rhbox)
325
 
79 t00mlabs 326
        hb.set_custom_title(mhbox)
77 t00mlabs 327
        self.set_titlebar(hb)
328
        hb.show_all()
329
 
330
 
84 t00mlabs 331
    def setup_dashboard_filters(self):
332
        ### SETTINGS POPOVER
333
        menu = Gio.Menu()
334
        #~ self.gui.add_widget("menu", menu)
335
        menu.append_item(self.uif.create_item('Fullscreen', 'app.settings-fullscreen', 'gtk-fullscreen'))
336
        menu.append_item(self.uif.create_item('Rename current project', 'app.project-rename', 'preferences-desktop-personal'))
337
        menu.append_item(self.uif.create_item('Refresh current project', 'app.project-refresh', 'view-refresh'))
338
        menu.append_item(self.uif.create_item('Close current project', 'app.project-close', 'window-close'))
339
        menu.append_item(self.uif.create_item('Delete current project', 'app.project-delete', 'list-remove'))
340
        menu.append_item(self.uif.create_item('Export current project', 'app.project-delete', 'document-save-as'))
341
        window = self.gui.get_window()
342
        window.set_app_menu(menu)
343
        app = self.gui.get_app()
344
        app.add_action(self.uif.create_item("settings-fullscreen"))
345
 
346
        #~ popover_action_group = Gio.SimpleActionGroup()
347
        button = self.gui.get_widget('btnDashboard')
348
        popover_dashboard = Gtk.Popover.new_from_model(button, menu)
349
        popover_dashboard.set_position(Gtk.PositionType.BOTTOM)
350
        button.connect('clicked', lambda _: popover_dashboard.show_all())
351
 
352
 
113 t00mlabs 353
    #~ def setup_menu_settings(self):
354
        #~ ### SETTINGS POPOVER
355
        #~ menu = Gio.Menu()
356
        #~ menu.append_item(self.uif.create_item('Fullscreen', 'app.settings-fullscreen', 'gtk-fullscreen'))
357
        #~ menu.append_item(self.uif.create_item('Rename current project', 'app.project-rename', 'preferences-desktop-personal'))
358
        #~ menu.append_item(self.uif.create_item('Refresh current project', 'app.project-refresh', 'view-refresh'))
359
        #~ menu.append_item(self.uif.create_item('Close current project', 'app.project-close', 'window-close'))
360
        #~ menu.append_item(self.uif.create_item('Delete current project', 'app.project-delete', 'list-remove'))
361
        #~ menu.append_item(self.uif.create_item('Export current project', 'app.project-delete', 'document-save-as'))
362
        #~ window = self.gui.get_window()
363
        #~ window.set_app_menu(menu)
364
        #~ app = self.gui.get_app()
365
        #~ app.add_action(self.uif.create_item("settings-fullscreen"))
4 t00mlabs 366
 
113 t00mlabs 367
        #~ btnsettings = self.gui.get_widget("mnuBtnViews")
368
        #~ popover_settings = Gtk.Popover.new_from_model(btnsettings, menu)
369
        #~ popover_settings.set_position(Gtk.PositionType.BOTTOM)
370
        #~ btnsettings.connect('clicked', lambda _: popover_settings.show_all())
4 t00mlabs 371
 
372
 
110 t00mlabs 373
    def setup_popover_settings(self, widget):
374
        #Creating a popover
375
        popover = Gtk.Popover.new(widget)
376
        #~ popover.set_size_request(50,100)
377
 
378
        box = Gtk.Box(spacing = 10, orientation="vertical")
112 t00mlabs 379
        hboxfs = Gtk.Box(spacing = 10, orientation="horizontal")
380
        lblfs = Gtk.Label('Fullscreen')
381
        swFullScreen = self.gui.add_widget('fullscreen', Gtk.Switch())
382
        swFullScreen.connect('state-set', self.uif.fullscreen)
383
        hboxfs.pack_start(lblfs, True, True, 6)
384
        hboxfs.pack_start(swFullScreen, True, True, 6)
385
        hboxfs.set_homogeneous(True)
386
        box.add(hboxfs)
110 t00mlabs 387
        popover.add(box)
388
 
389
        return popover
390
 
391
 
4 t00mlabs 392
    def setup_menus(self):
106 t00mlabs 393
        pass
394
        #~ self.setup_menu_views()
84 t00mlabs 395
        #~ self.setup_dashboard_filters
117 t00mlabs 396
        #~ self.cb.setup_menu_actions()
4 t00mlabs 397
        #~ self.setup_menu_settings()
398
 
74 t00mlabs 399
 
4 t00mlabs 400
    def show_home_page(self, *args):
401
        notebook = self.gui.get_widget('notebook')
402
        notebook.set_current_page(0)
403
 
74 t00mlabs 404
 
4 t00mlabs 405
    def show_settings_page(self, *args):
101 t00mlabs 406
        sapnoteview = self.gui.get_widget('viewmenu')
4 t00mlabs 407
        sapnoteview.set_view('settings')
83 t00mlabs 408
        notebook = self.gui.get_widget('mainbox')
409
        notebook.set_current_page(5)
4 t00mlabs 410
 
74 t00mlabs 411
 
412
    def show_stats_page(self, *args):
101 t00mlabs 413
        sapnoteview = self.gui.get_widget('viewmenu')
74 t00mlabs 414
        sapnoteview.set_view('stats')
415
        notebook = self.gui.get_widget('notebook')
416
        notebook.set_current_page(4)
417
 
418
 
4 t00mlabs 419
    def show_browser_page(self, *args):
420
        notebook = self.gui.get_widget('notebook')
421
        notebook.set_current_page(1)
422
 
423
 
74 t00mlabs 424
    def hide_props_window(self):
425
        hpnnotes = self.gui.get_widget('hpnNotesManager')
426
        boxprops = self.gui.get_widget('boxPropsWidget')
427
        size = hpnnotes.get_allocation()
4 t00mlabs 428
 
74 t00mlabs 429
        boxprops.set_no_show_all(True)
430
        boxprops.hide()
431
        hpnnotes.set_position(size.width)
4 t00mlabs 432
 
74 t00mlabs 433
 
434
    def show_props_window(self):
435
        hpnnotes = self.gui.get_widget('hpnNotesManager')
436
        boxprops = self.gui.get_widget('boxPropsWidget')
437
        size = hpnnotes.get_allocation()
438
 
439
        boxprops.set_no_show_all(False)
440
        boxprops.show_all()
441
        hpnnotes.show_all()
442
        hpnnotes.set_position(size.width/5*3)
443
 
444
 
445
    def switch_props_window(self, *args):
446
        tgbprops = self.gui.get_widget('tgbShowManage')
447
 
448
        if tgbprops.get_active():
449
            self.show_props_window()
450
        else:
451
            self.hide_props_window()
452
 
453
 
4 t00mlabs 454
    def setup_widgets(self):
455
        self.mainbox = self.gui.get_widget('mainbox')
456
        self.mainbox.reparent(self)
457
 
86 t00mlabs 458
        #~ # STATUSBAR WIDGETS
459
        # StatusBar disabled
460
        #~ statusbar = self.gui.get_widget('pgbMain')
461
        #~ statusbar.set_text("")
462
        #~ statusbar.set_show_text(True)
463
        #~ statusbar.set_fraction(0.0)
464
 
465
        # SETUP MENUS
4 t00mlabs 466
        self.setup_menus()
82 t00mlabs 467
 
468
        # SETTINGS PAGE WIDGETS
469
        button = self.gui.get_widget('btnPrefsBack')
470
        button.connect('clicked', self.cb.show_workplace)
471
 
472
        button = self.gui.add_widget('btnPrefsSAPApply')
126 t00mlabs 473
        #~ button.connect('clicked', self.cb.apply_preferences)
82 t00mlabs 474
 
475
        button = self.gui.add_widget('btnPrefsSAPCancel')
476
        button.connect('clicked', self.cb.refresh_view)
477
 
478
        button = self.gui.add_widget('btnPrefsSAPReset')
479
        button.connect('clicked', self.cb.default_preferences)
480
 
481
        # SAPNOTEVIEW WIDGETS
101 t00mlabs 482
        #~ viewsbox = self.gui.get_widget('viewsbox')
483
        #~ notesbox = self.gui.get_widget('notesbox')
484
        #~ viewmenu = SAPNoteView(self.controller)
485
        #~ viewnotes = SAPNoteView(self.controller)
486
        #~ self.gui.add_widget('viewmenu', viewmenu)
4 t00mlabs 487
        self.gui.add_widget('combobox')
488
        search = self.gui.add_widget('stySearchInfo')
489
        #~ search.connect('search_changed', self.search_notes)
490
        search.connect('activate', self.cb.search_notes)
74 t00mlabs 491
        self.setup_combobox_search()
101 t00mlabs 492
        #~ self.swap_widget(viewsbox, viewmenu)
4 t00mlabs 493
 
74 t00mlabs 494
 
91 t00mlabs 495
        #~ self.setup_props_window()
74 t00mlabs 496
 
497
 
4 t00mlabs 498
        # Buttons
74 t00mlabs 499
        # Task link button
91 t00mlabs 500
        #~ self.cb.check_task_link_button_status()
4 t00mlabs 501
 
91 t00mlabs 502
        #~ # button quit
503
        #~ image = self.gui.get_widget('imgBtnQuit')
504
        #~ icon = self.im.get_pixbuf_icon('power', 48, 48)
505
        #~ image.set_from_pixbuf(icon)
506
        #~ button = self.gui.get_widget('btnQuit')
507
        #~ button.connect('clicked', self.gui.quit)
4 t00mlabs 508
 
91 t00mlabs 509
        #~ # button about
510
        #~ image = self.gui.get_widget('imgBtnAbout')
511
        #~ icon = self.im.get_pixbuf_icon('about', 48, 48)
512
        #~ image.set_from_pixbuf(icon)
513
        #~ button = self.gui.get_widget('btnAbout')
514
        #~ button.connect('clicked', self.uiapp.cb_show_about)
74 t00mlabs 515
 
91 t00mlabs 516
        #~ # button settings
517
        #~ image = self.gui.get_widget('imgBtnSettings')
518
        #~ icon = self.im.get_pixbuf_icon('settings', 48, 48)
519
        #~ image.set_from_pixbuf(icon)
520
        #~ button = self.gui.get_widget('btnSettings')
521
        #~ button.connect('clicked', self.show_settings_page)
74 t00mlabs 522
 
91 t00mlabs 523
        #~ # button stats
524
        #~ image = self.gui.get_widget('imgBtnStats')
525
        #~ icon = self.im.get_pixbuf_icon('chart', 48, 48)
526
        #~ image.set_from_pixbuf(icon)
527
        #~ button = self.gui.get_widget('btnShowStats')
528
        #~ button.connect('clicked', self.show_stats_page)
74 t00mlabs 529
 
91 t00mlabs 530
        #~ # button show property details
531
        #~ image = self.gui.get_widget('imgBtnShowProps')
532
        #~ icon = self.im.get_pixbuf_icon('fingerprint', 48, 48)
533
        #~ image.set_from_pixbuf(icon)
534
        #~ button = self.gui.get_widget('btnShowProperties')
535
        #~ button.connect('clicked', self.cb.show_properties)
74 t00mlabs 536
 
91 t00mlabs 537
        #~ # button show manage window
538
        #~ image = self.gui.get_widget('imgBtnShowManage')
539
        #~ icon = self.im.get_pixbuf_icon('subwindow', 48, 48)
540
        #~ image.set_from_pixbuf(icon)
541
        #~ button = self.gui.get_widget('tgbShowManage')
542
        #~ button.connect('toggled', self.switch_props_window)
74 t00mlabs 543
 
91 t00mlabs 544
        #~ # button search
545
        #~ image = self.gui.get_widget('imgBtnSearch')
546
        #~ icon = self.im.get_pixbuf_icon('bsearch', 48, 48)
547
        #~ image.set_from_pixbuf(icon)
548
        #~ button = self.gui.get_widget('tgbSearch')
549
        #~ button.connect('toggled', self.cb.show_search)
550
        #~ revsearch = self.gui.get_widget('revSearch')
551
        #~ revsearch.hide()
552
        #~ revsearch.set_no_show_all(True)
74 t00mlabs 553
 
554
        # button import
130 t00mlabs 555
        #~ image = self.gui.get_widget('imgMnuBtnImport')
556
        #~ icon = self.im.get_pixbuf_icon('import', 24, 24)
557
        #~ image.set_from_pixbuf(icon)
74 t00mlabs 558
 
91 t00mlabs 559
        #~ # button refresh
560
        #~ image = self.gui.get_widget('imgBtnRefresh')
561
        #~ icon = self.im.get_pixbuf_icon('refresh', 48, 48)
562
        #~ image.set_from_pixbuf(icon)
563
        #~ button = self.gui.get_widget('btnRefreshSAPNoteView')
564
        #~ button.connect('clicked', self.cb.refresh_and_clear_view)
74 t00mlabs 565
 
91 t00mlabs 566
        #~ button = self.gui.get_widget('btnLinkTasksApply')
567
        #~ button.connect('clicked', self.cb.link_tasks_to_sapnotes)
74 t00mlabs 568
 
91 t00mlabs 569
        #~ btnaddnote = self.gui.get_widget('btnStartDlNotes')
570
        #~ btnaddnote.connect('clicked', self.cb.import_notes)
74 t00mlabs 571
 
91 t00mlabs 572
        #~ btnStopDlNotes = self.gui.get_widget('btnStopDlNotes')
573
        #~ btnStopDlNotes.connect('clicked', self.cb.stop_dl_notes)
74 t00mlabs 574
 
130 t00mlabs 575
        #~ switch = self.gui.get_widget('schExpandCollapse')
101 t00mlabs 576
        #~ switch.connect('state-set', viewmenu.expand_collapse)
100 t00mlabs 577
        #~ switch.connect('toggled', sapnoteview.expand_collapse)
130 t00mlabs 578
        #~ switch = self.gui.get_widget('schSelectNotesAllNone')
101 t00mlabs 579
        #~ switch.connect('state-set', viewmenu.select_all_none)
580
        #~ switch.connect('toggled', viewmenu.select_all_none)
74 t00mlabs 581
 
4 t00mlabs 582
 
91 t00mlabs 583
        #~ # Actions button
584
        #~ button = self.gui.get_widget('mnuBtnActions')
4 t00mlabs 585
 
91 t00mlabs 586
        #~ sap_settings = self.prefs.get_custom_settings()
587
        #~ for setting in sap_settings:
588
            #~ try:
589
                #~ widget = self.gui.add_widget(setting)
590
                #~ widget.set_text(sap_settings[setting])
591
            #~ except:
592
                #~ pass
4 t00mlabs 593
 
74 t00mlabs 594
 
91 t00mlabs 595
        #~ # Stats
596
        #~ statsviewer = self.gui.add_widget('scrStatsViewer')
4 t00mlabs 597
 
91 t00mlabs 598
        #~ btnstats = self.gui.add_widget('btnStatsByCompMain')
599
        #~ btnstats.connect('clicked', self.cb.update_components_stats)
600
        #~ iconwdg = self.gui.add_widget('imgStatsByCompMain')
601
        #~ icon = self.im.get_pixbuf_icon('component', 64, 64)
602
        #~ iconwdg.set_from_pixbuf(icon)
4 t00mlabs 603
 
91 t00mlabs 604
        #~ btnstats = self.gui.add_widget('btnStatsByCategory')
605
        #~ btnstats.connect('clicked', self.cb.update_categories_stats)
606
        #~ iconwdg = self.gui.add_widget('imgStatsByCategory')
607
        #~ icon = self.im.get_pixbuf_icon('category', 64, 64)
608
        #~ iconwdg.set_from_pixbuf(icon)
4 t00mlabs 609
 
91 t00mlabs 610
        #~ self.hide_props_window()
4 t00mlabs 611
        self.show_all()
612
        self.log.debug("GUI loaded")
613
 
100 t00mlabs 614
        self.cb.show_workplace()
4 t00mlabs 615
 
84 t00mlabs 616
 
74 t00mlabs 617
    def setup_props_window(self):
618
        imgtitle = self.gui.get_widget('imgPropsTitle')
619
        icon = self.im.get_icon('fingerprint', 48, 48)
620
        imgtitle.set_from_pixbuf (icon)
621
        model = Gtk.TreeStore(str, str)
622
        trvprops = self.gui.add_widget('trvprops', Gtk.TreeView())
623
        trvprops.set_model(model)
624
 
625
        #~ ## key
626
        #~ renderer = Gtk.CellRendererText()
627
        #~ column = Gtk.TreeViewColumn('Id', renderer, text=0)
628
        #~ column.set_visible(False)
629
        #~ column.set_clickable(False)
630
        #~ column.set_sort_indicator(False)
631
        #~ trvprops.append_column(column)
632
 
633
        # Property
634
        renderer = Gtk.CellRendererText()
635
        renderer.set_alignment(1.0, 0.5)
636
        column = Gtk.TreeViewColumn('Property', renderer, markup=0)
637
        column.set_visible(True)
638
        column.set_expand(False)
639
        column.set_clickable(True)
640
        column.set_sort_indicator(True)
641
        trvprops.append_column(column)
642
 
643
        # Value
644
        renderer = Gtk.CellRendererText()
645
        renderer.set_alignment(0.0, 0.5)
646
        column = Gtk.TreeViewColumn('Value', renderer, markup=1)
647
        column.set_visible(True)
648
        column.set_expand(True)
649
        column.set_clickable(True)
650
        column.set_sort_indicator(True)
651
        trvprops.append_column(column)
652
        trvprops.show_all()
653
 
654
        trvprops.set_headers_visible(True)
655
        trvprops.set_enable_search(True)
656
        trvprops.set_grid_lines(Gtk.TreeViewGridLines.NONE)
657
        trvprops.set_search_column(1)
658
        #~ trvprops.connect('row-activated', self.double_click)
659
        selection = trvprops.get_selection()
660
        selection.set_mode(Gtk.SelectionMode.SINGLE)
661
        #~ trvprops.set_search_entry(self.pname)
662
 
663
        container = self.gui.get_widget('boxProps')
664
        self.gui.swap_widget(container, trvprops)
665
 
666
    def set_notes_manager_pane_position(self, pane, rectangle):
667
        pass
668
        #~ self.log.debug(type(pane.get_allocation()))
669
        position = rectangle.width/5*3
670
        pane.set_position(position)
671
        self.log.debug("Pane position: %s" % position)
672
 
673
 
4 t00mlabs 674
    def __completion_func(self, completion, key, iter):
675
        model = completion.get_model()
676
        text = model.get_value(iter, 0)
677
        if key.upper() in text.upper():
678
            return True
679
        return False
680
 
681
 
682
    def setup_combobox_completions(self, key):
683
        model = Gtk.ListStore(str)
684
        search = self.gui.get_widget("stySearchInfo")
685
        completion = Gtk.EntryCompletion()
686
        completion.set_model(model)
687
        completion.set_text_column(0)
688
        completion.set_match_func(self.__completion_func)
689
        search.set_completion(completion)
690
 
74 t00mlabs 691
        stats = self.db.get_stats()
4 t00mlabs 692
 
693
        try:
694
            items = list(stats[key])
695
            items.sort()
696
            for item in items:
697
                model.append([item])
698
        except:
699
            pass
700
 
701
 
702
    def cb_combobox_changed(self, combobox):
703
        model = combobox.get_model()
704
        treeiter = combobox.get_active_iter()
705
        key = model[treeiter][0]
706
        self.gui.set_key('cmbvalue', key)
707
        self.setup_combobox_completions(key)
708
 
709
 
74 t00mlabs 710
    def setup_combobox_search(self):
711
        combobox = self.gui.get_widget('cmbSearchInfo')
4 t00mlabs 712
        model = Gtk.TreeStore(str, str)
713
        combobox.set_model(model)
714
 
715
        ## key
716
        cell = Gtk.CellRendererText()
717
        cell.set_visible(False)
718
        combobox.pack_start(cell, True)
719
        combobox.add_attribute(cell, 'text', 0)
720
 
721
        ## value
722
        cell = Gtk.CellRendererText()
723
        cell.set_alignment(0.0, 0.5)
724
        combobox.pack_start(cell, expand=False)
725
        combobox.add_attribute(cell, 'markup', 1)
726
        combobox.connect('changed', self.cb_combobox_changed)
727
 
101 t00mlabs 728
        model.append(None, ['search', 'Search in all database'])
729
        model.append(None, ['project', 'Filter by project name'])
730
        model.append(None, ['task', 'Filter by task name'])
731
        model.append(None, ['component', 'Filter by component'])
732
        model.append(None, ['category', 'Filter by category'])
733
        model.append(None, ['type', 'Filter by type'])
734
        model.append(None, ['id', 'Filter by Id'])
735
        model.append(None, ['title', 'Filter by title'])
736
        model.append(None, ['priority', 'Filter by priority'])
737
        model.append(None, ['version', 'Filter by version'])
4 t00mlabs 738
        #~ model.append(None, ['released', 'Filter by release date'])
739
 
740
        combobox.set_active(0)
741
 
742
 
743
    def get_services(self):
744
        """Load services to be used in this class
745
        """
746
        self.gui = self.controller.get_service("GUI")
747
        self.app = self.gui.get_app()
748
        LOG_FILE = self.controller.get_file('LOG')
749
        self.log = get_logger('GtkAppWindow', LOG_FILE)
74 t00mlabs 750
        self.db = self.controller.get_service("DB")
4 t00mlabs 751
        self.uif = self.controller.get_service("UIF")
752
        self.prefs = self.controller.get_service("Settings")
753
        self.im = self.controller.get_service('IM')
754
        self.cb = self.controller.get_service('Callbacks')
74 t00mlabs 755
        self.tasks = self.controller.get_service('Tasks')
106 t00mlabs 756
        #~ self.visor = self.controller.get_service('Workplace')
100 t00mlabs 757
        #~ self.dashboard = self.controller.get_service('Dashboard')
4 t00mlabs 758
 
759
 
760
    def swap_widget(self, container, combobox):
761
        """Shortcut to GUI.swap_widget method
762
        """
763
        self.gui.swap_widget(container, combobox)