Subversion Repositories basico

Rev

Rev 106 | Rev 110 | 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
81 t00mlabs 110
        imgtitlebar = self.gui.add_widget('imgtitlebar', Gtk.Image())
101 t00mlabs 111
        imgtitlebar.set_visible(False)
112
        imgtitlebar.set_no_show_all(True)
79 t00mlabs 113
        lbltitlebar = self.gui.add_widget("lbltitlebar", Gtk.Label())
84 t00mlabs 114
        self.cb.update_titlebar_title("Dashboard", "dashboard")
81 t00mlabs 115
        #~ lbltitlebar.set_markup("<big><b>Dashboard</b></big>")
116
        lhbox.pack_start(imgtitlebar, False, False, 3)
117
        lhbox.pack_start(lbltitlebar, False, False, 3)
118
        lhbox.show_all()
79 t00mlabs 119
        hb.pack_start(lhbox)
77 t00mlabs 120
 
79 t00mlabs 121
        # Middle side titlebar
122
        # Dashboard button
100 t00mlabs 123
        #~ button = self.gui.add_widget('btnDashboard', Gtk.Button())
124
        #~ button.set_tooltip_markup('<big><b>Dashboard</b></big>')
125
        #~ icon = self.im.get_pixbuf_icon('dashboard', 24, 24)
126
        #~ image = Gtk.Image()
127
        #~ image.set_from_pixbuf(icon)
128
        #~ button.set_image(image)
129
        #~ button.set_relief(Gtk.ReliefStyle.NONE)
130
        #~ button.connect('clicked', self.cb.show_dashboard)
131
        #~ mhbox.pack_start(button, False, False, 0)
78 t00mlabs 132
 
79 t00mlabs 133
        # Workplace button
134
        button = Gtk.Button()
81 t00mlabs 135
        button.set_tooltip_markup('<big><b>Workplace</b></big>')
92 t00mlabs 136
        icon = self.im.get_pixbuf_icon('workplace', 24, 24)
81 t00mlabs 137
        image = Gtk.Image()
138
        image.set_from_pixbuf(icon)
139
        button.set_image(image)
78 t00mlabs 140
        button.set_relief(Gtk.ReliefStyle.NONE)
141
        button.connect('clicked', self.cb.show_workplace)
79 t00mlabs 142
        mhbox.pack_start(button, False, False, 0)
78 t00mlabs 143
 
84 t00mlabs 144
 
145
        # Workbook button
81 t00mlabs 146
        button = Gtk.Button()
84 t00mlabs 147
        button.set_tooltip_markup('<big><b>Workbook</b></big>')
148
        icon = self.im.get_pixbuf_icon('comments', 24, 24)
81 t00mlabs 149
        image = Gtk.Image()
150
        image.set_from_pixbuf(icon)
151
        button.set_image(image)
152
        button.set_relief(Gtk.ReliefStyle.NONE)
84 t00mlabs 153
        button.connect('clicked', self.cb.show_workbook)
81 t00mlabs 154
        mhbox.pack_start(button, False, False, 0)
155
 
84 t00mlabs 156
 
157
        # School button
81 t00mlabs 158
        button = Gtk.Button()
84 t00mlabs 159
        button.set_tooltip_markup('<big><b>My SAP School</b></big>')
160
        icon = self.im.get_pixbuf_icon('school', 24, 24)
81 t00mlabs 161
        image = Gtk.Image()
162
        image.set_from_pixbuf(icon)
163
        button.set_image(image)
164
        button.set_relief(Gtk.ReliefStyle.NONE)
84 t00mlabs 165
        button.connect('clicked', self.cb.show_school)
81 t00mlabs 166
        mhbox.pack_start(button, False, False, 0)
167
 
168
 
84 t00mlabs 169
        # Search entry
170
        #~ button = Gtk.Button()
171
        #~ button.set_tooltip_markup('<big><b>Search</b></big>')
172
        #~ icon = self.im.get_pixbuf_icon('bsearch', 24, 24)
173
        #~ image = Gtk.Image()
174
        #~ image.set_from_pixbuf(icon)
175
        #~ button.set_image(image)
176
        #~ button.set_relief(Gtk.ReliefStyle.NONE)
177
        #~ button.connect('clicked', self.cb.toggle_search)
178
        #~ mhbox.pack_start(button, False, False, 0)
81 t00mlabs 179
 
84 t00mlabs 180
 
78 t00mlabs 181
        # Right side titlebar
77 t00mlabs 182
        # About
183
        button = Gtk.Button()
81 t00mlabs 184
        button.set_tooltip_markup('<big><b>About</b></big>')
185
        icon = self.im.get_pixbuf_icon('about', 24, 24)
186
        image = Gtk.Image()
187
        image.set_from_pixbuf(icon)
188
        button.set_image(image)
77 t00mlabs 189
        button.set_relief(Gtk.ReliefStyle.NONE)
190
        button.connect('clicked', self.uiapp.cb_show_about)
191
        rhbox.pack_end(button, False, False, 0)
79 t00mlabs 192
 
93 t00mlabs 193
        # Help
194
        button = Gtk.Button()
195
        button.set_tooltip_markup('<big><b>Help</b></big>')
196
        icon = self.im.get_pixbuf_icon('basico_help', 24, 24)
197
        image = Gtk.Image()
198
        image.set_from_pixbuf(icon)
199
        button.set_image(image)
200
        button.set_relief(Gtk.ReliefStyle.NONE)
201
        button.connect('clicked', self.cb.show_help)
202
        rhbox.pack_end(button, False, False, 0)
203
 
79 t00mlabs 204
        # Settings
205
        button = Gtk.Button()
81 t00mlabs 206
        button.set_tooltip_markup('<big><b>Settings</b></big>')
207
        icon = self.im.get_pixbuf_icon('settings', 24, 24)
208
        image = Gtk.Image()
209
        image.set_from_pixbuf(icon)
210
        button.set_image(image)
79 t00mlabs 211
        button.set_relief(Gtk.ReliefStyle.NONE)
212
        button.connect('clicked', self.cb.show_settings)
81 t00mlabs 213
        button.show_all()
84 t00mlabs 214
        self.cb.update_titlebar_title("Settings", "settings")
79 t00mlabs 215
        rhbox.pack_end(button, False, False, 0)
77 t00mlabs 216
        hb.pack_end(rhbox)
217
 
79 t00mlabs 218
        hb.set_custom_title(mhbox)
77 t00mlabs 219
        self.set_titlebar(hb)
220
        hb.show_all()
221
 
222
 
84 t00mlabs 223
    def setup_dashboard_filters(self):
224
        ### SETTINGS POPOVER
225
        menu = Gio.Menu()
226
        #~ self.gui.add_widget("menu", menu)
227
        menu.append_item(self.uif.create_item('Fullscreen', 'app.settings-fullscreen', 'gtk-fullscreen'))
228
        menu.append_item(self.uif.create_item('Rename current project', 'app.project-rename', 'preferences-desktop-personal'))
229
        menu.append_item(self.uif.create_item('Refresh current project', 'app.project-refresh', 'view-refresh'))
230
        menu.append_item(self.uif.create_item('Close current project', 'app.project-close', 'window-close'))
231
        menu.append_item(self.uif.create_item('Delete current project', 'app.project-delete', 'list-remove'))
232
        menu.append_item(self.uif.create_item('Export current project', 'app.project-delete', 'document-save-as'))
233
        window = self.gui.get_window()
234
        window.set_app_menu(menu)
235
        app = self.gui.get_app()
236
        app.add_action(self.uif.create_item("settings-fullscreen"))
237
 
238
        #~ popover_action_group = Gio.SimpleActionGroup()
239
        button = self.gui.get_widget('btnDashboard')
240
        popover_dashboard = Gtk.Popover.new_from_model(button, menu)
241
        popover_dashboard.set_position(Gtk.PositionType.BOTTOM)
242
        button.connect('clicked', lambda _: popover_dashboard.show_all())
243
 
244
 
4 t00mlabs 245
    def setup_menu_settings(self):
246
        ### SETTINGS POPOVER
247
        menu = Gio.Menu()
248
        #~ self.gui.add_widget("menu", menu)
249
        menu.append_item(self.uif.create_item('Fullscreen', 'app.settings-fullscreen', 'gtk-fullscreen'))
250
        menu.append_item(self.uif.create_item('Rename current project', 'app.project-rename', 'preferences-desktop-personal'))
251
        menu.append_item(self.uif.create_item('Refresh current project', 'app.project-refresh', 'view-refresh'))
252
        menu.append_item(self.uif.create_item('Close current project', 'app.project-close', 'window-close'))
253
        menu.append_item(self.uif.create_item('Delete current project', 'app.project-delete', 'list-remove'))
254
        menu.append_item(self.uif.create_item('Export current project', 'app.project-delete', 'document-save-as'))
255
        window = self.gui.get_window()
256
        window.set_app_menu(menu)
257
        app = self.gui.get_app()
258
        app.add_action(self.uif.create_item("settings-fullscreen"))
259
 
260
        #~ popover_action_group = Gio.SimpleActionGroup()
261
        btnsettings = self.gui.get_widget("mnuBtnViews")
262
        popover_settings = Gtk.Popover.new_from_model(btnsettings, menu)
263
        popover_settings.set_position(Gtk.PositionType.BOTTOM)
264
        btnsettings.connect('clicked', lambda _: popover_settings.show_all())
265
 
266
 
267
    def setup_menus(self):
106 t00mlabs 268
        pass
269
        #~ self.setup_menu_views()
84 t00mlabs 270
        #~ self.setup_dashboard_filters
4 t00mlabs 271
        #~ self.setup_menu_actions()
272
        #~ self.setup_menu_settings()
273
 
74 t00mlabs 274
 
4 t00mlabs 275
    def show_home_page(self, *args):
276
        notebook = self.gui.get_widget('notebook')
277
        notebook.set_current_page(0)
278
 
74 t00mlabs 279
 
4 t00mlabs 280
    def show_settings_page(self, *args):
101 t00mlabs 281
        sapnoteview = self.gui.get_widget('viewmenu')
4 t00mlabs 282
        sapnoteview.set_view('settings')
83 t00mlabs 283
        notebook = self.gui.get_widget('mainbox')
284
        notebook.set_current_page(5)
4 t00mlabs 285
 
74 t00mlabs 286
 
287
    def show_stats_page(self, *args):
101 t00mlabs 288
        sapnoteview = self.gui.get_widget('viewmenu')
74 t00mlabs 289
        sapnoteview.set_view('stats')
290
        notebook = self.gui.get_widget('notebook')
291
        notebook.set_current_page(4)
292
 
293
 
4 t00mlabs 294
    def show_browser_page(self, *args):
295
        notebook = self.gui.get_widget('notebook')
296
        notebook.set_current_page(1)
297
 
298
 
299
 
300
 
84 t00mlabs 301
 
74 t00mlabs 302
    def hide_props_window(self):
303
        hpnnotes = self.gui.get_widget('hpnNotesManager')
304
        boxprops = self.gui.get_widget('boxPropsWidget')
305
        size = hpnnotes.get_allocation()
4 t00mlabs 306
 
74 t00mlabs 307
        boxprops.set_no_show_all(True)
308
        boxprops.hide()
309
        hpnnotes.set_position(size.width)
4 t00mlabs 310
 
74 t00mlabs 311
 
312
    def show_props_window(self):
313
        hpnnotes = self.gui.get_widget('hpnNotesManager')
314
        boxprops = self.gui.get_widget('boxPropsWidget')
315
        size = hpnnotes.get_allocation()
316
 
317
        boxprops.set_no_show_all(False)
318
        boxprops.show_all()
319
        hpnnotes.show_all()
320
        hpnnotes.set_position(size.width/5*3)
321
 
322
 
323
    def switch_props_window(self, *args):
324
        tgbprops = self.gui.get_widget('tgbShowManage')
325
 
326
        if tgbprops.get_active():
327
            self.show_props_window()
328
        else:
329
            self.hide_props_window()
330
 
331
 
4 t00mlabs 332
    def setup_widgets(self):
333
        self.mainbox = self.gui.get_widget('mainbox')
334
        self.mainbox.reparent(self)
335
 
86 t00mlabs 336
        #~ # STATUSBAR WIDGETS
337
        # StatusBar disabled
338
        #~ statusbar = self.gui.get_widget('pgbMain')
339
        #~ statusbar.set_text("")
340
        #~ statusbar.set_show_text(True)
341
        #~ statusbar.set_fraction(0.0)
342
 
343
        # SETUP MENUS
4 t00mlabs 344
        self.setup_menus()
82 t00mlabs 345
 
346
        # SETTINGS PAGE WIDGETS
347
        button = self.gui.get_widget('btnPrefsBack')
348
        button.connect('clicked', self.cb.show_workplace)
349
 
350
        button = self.gui.add_widget('btnPrefsSAPApply')
351
        button.connect('clicked', self.cb.apply_preferences)
352
 
353
        button = self.gui.add_widget('btnPrefsSAPCancel')
354
        button.connect('clicked', self.cb.refresh_view)
355
 
356
        button = self.gui.add_widget('btnPrefsSAPReset')
357
        button.connect('clicked', self.cb.default_preferences)
358
 
359
        # SAPNOTEVIEW WIDGETS
101 t00mlabs 360
        #~ viewsbox = self.gui.get_widget('viewsbox')
361
        #~ notesbox = self.gui.get_widget('notesbox')
362
        #~ viewmenu = SAPNoteView(self.controller)
363
        #~ viewnotes = SAPNoteView(self.controller)
364
        #~ self.gui.add_widget('viewmenu', viewmenu)
4 t00mlabs 365
        self.gui.add_widget('combobox')
366
        search = self.gui.add_widget('stySearchInfo')
367
        #~ search.connect('search_changed', self.search_notes)
368
        search.connect('activate', self.cb.search_notes)
74 t00mlabs 369
        self.setup_combobox_search()
101 t00mlabs 370
        #~ self.swap_widget(viewsbox, viewmenu)
4 t00mlabs 371
 
74 t00mlabs 372
 
91 t00mlabs 373
        #~ self.setup_props_window()
74 t00mlabs 374
 
375
 
4 t00mlabs 376
        # Buttons
74 t00mlabs 377
        # Task link button
91 t00mlabs 378
        #~ self.cb.check_task_link_button_status()
4 t00mlabs 379
 
91 t00mlabs 380
        #~ # button quit
381
        #~ image = self.gui.get_widget('imgBtnQuit')
382
        #~ icon = self.im.get_pixbuf_icon('power', 48, 48)
383
        #~ image.set_from_pixbuf(icon)
384
        #~ button = self.gui.get_widget('btnQuit')
385
        #~ button.connect('clicked', self.gui.quit)
4 t00mlabs 386
 
91 t00mlabs 387
        #~ # button about
388
        #~ image = self.gui.get_widget('imgBtnAbout')
389
        #~ icon = self.im.get_pixbuf_icon('about', 48, 48)
390
        #~ image.set_from_pixbuf(icon)
391
        #~ button = self.gui.get_widget('btnAbout')
392
        #~ button.connect('clicked', self.uiapp.cb_show_about)
74 t00mlabs 393
 
91 t00mlabs 394
        #~ # button settings
395
        #~ image = self.gui.get_widget('imgBtnSettings')
396
        #~ icon = self.im.get_pixbuf_icon('settings', 48, 48)
397
        #~ image.set_from_pixbuf(icon)
398
        #~ button = self.gui.get_widget('btnSettings')
399
        #~ button.connect('clicked', self.show_settings_page)
74 t00mlabs 400
 
91 t00mlabs 401
        #~ # button stats
402
        #~ image = self.gui.get_widget('imgBtnStats')
403
        #~ icon = self.im.get_pixbuf_icon('chart', 48, 48)
404
        #~ image.set_from_pixbuf(icon)
405
        #~ button = self.gui.get_widget('btnShowStats')
406
        #~ button.connect('clicked', self.show_stats_page)
74 t00mlabs 407
 
91 t00mlabs 408
        #~ # button show property details
409
        #~ image = self.gui.get_widget('imgBtnShowProps')
410
        #~ icon = self.im.get_pixbuf_icon('fingerprint', 48, 48)
411
        #~ image.set_from_pixbuf(icon)
412
        #~ button = self.gui.get_widget('btnShowProperties')
413
        #~ button.connect('clicked', self.cb.show_properties)
74 t00mlabs 414
 
91 t00mlabs 415
        #~ # button show manage window
416
        #~ image = self.gui.get_widget('imgBtnShowManage')
417
        #~ icon = self.im.get_pixbuf_icon('subwindow', 48, 48)
418
        #~ image.set_from_pixbuf(icon)
419
        #~ button = self.gui.get_widget('tgbShowManage')
420
        #~ button.connect('toggled', self.switch_props_window)
74 t00mlabs 421
 
91 t00mlabs 422
        #~ # button search
423
        #~ image = self.gui.get_widget('imgBtnSearch')
424
        #~ icon = self.im.get_pixbuf_icon('bsearch', 48, 48)
425
        #~ image.set_from_pixbuf(icon)
426
        #~ button = self.gui.get_widget('tgbSearch')
427
        #~ button.connect('toggled', self.cb.show_search)
428
        #~ revsearch = self.gui.get_widget('revSearch')
429
        #~ revsearch.hide()
430
        #~ revsearch.set_no_show_all(True)
74 t00mlabs 431
 
432
        # button import
433
        image = self.gui.get_widget('imgMnuBtnImport')
91 t00mlabs 434
        icon = self.im.get_pixbuf_icon('import', 24, 24)
74 t00mlabs 435
        image.set_from_pixbuf(icon)
436
 
91 t00mlabs 437
        #~ # button refresh
438
        #~ image = self.gui.get_widget('imgBtnRefresh')
439
        #~ icon = self.im.get_pixbuf_icon('refresh', 48, 48)
440
        #~ image.set_from_pixbuf(icon)
441
        #~ button = self.gui.get_widget('btnRefreshSAPNoteView')
442
        #~ button.connect('clicked', self.cb.refresh_and_clear_view)
74 t00mlabs 443
 
91 t00mlabs 444
        #~ button = self.gui.get_widget('btnLinkTasksApply')
445
        #~ button.connect('clicked', self.cb.link_tasks_to_sapnotes)
74 t00mlabs 446
 
91 t00mlabs 447
        #~ btnaddnote = self.gui.get_widget('btnStartDlNotes')
448
        #~ btnaddnote.connect('clicked', self.cb.import_notes)
74 t00mlabs 449
 
91 t00mlabs 450
        #~ btnStopDlNotes = self.gui.get_widget('btnStopDlNotes')
451
        #~ btnStopDlNotes.connect('clicked', self.cb.stop_dl_notes)
74 t00mlabs 452
 
92 t00mlabs 453
        switch = self.gui.get_widget('schExpandCollapse')
101 t00mlabs 454
        #~ switch.connect('state-set', viewmenu.expand_collapse)
100 t00mlabs 455
        #~ switch.connect('toggled', sapnoteview.expand_collapse)
92 t00mlabs 456
        switch = self.gui.get_widget('schSelectNotesAllNone')
101 t00mlabs 457
        #~ switch.connect('state-set', viewmenu.select_all_none)
458
        #~ switch.connect('toggled', viewmenu.select_all_none)
74 t00mlabs 459
 
4 t00mlabs 460
 
91 t00mlabs 461
        #~ # Actions button
462
        #~ button = self.gui.get_widget('mnuBtnActions')
4 t00mlabs 463
 
91 t00mlabs 464
        #~ sap_settings = self.prefs.get_custom_settings()
465
        #~ for setting in sap_settings:
466
            #~ try:
467
                #~ widget = self.gui.add_widget(setting)
468
                #~ widget.set_text(sap_settings[setting])
469
            #~ except:
470
                #~ pass
4 t00mlabs 471
 
74 t00mlabs 472
 
91 t00mlabs 473
        #~ # Stats
474
        #~ statsviewer = self.gui.add_widget('scrStatsViewer')
4 t00mlabs 475
 
91 t00mlabs 476
        #~ btnstats = self.gui.add_widget('btnStatsByCompMain')
477
        #~ btnstats.connect('clicked', self.cb.update_components_stats)
478
        #~ iconwdg = self.gui.add_widget('imgStatsByCompMain')
479
        #~ icon = self.im.get_pixbuf_icon('component', 64, 64)
480
        #~ iconwdg.set_from_pixbuf(icon)
4 t00mlabs 481
 
91 t00mlabs 482
        #~ btnstats = self.gui.add_widget('btnStatsByCategory')
483
        #~ btnstats.connect('clicked', self.cb.update_categories_stats)
484
        #~ iconwdg = self.gui.add_widget('imgStatsByCategory')
485
        #~ icon = self.im.get_pixbuf_icon('category', 64, 64)
486
        #~ iconwdg.set_from_pixbuf(icon)
4 t00mlabs 487
 
91 t00mlabs 488
        #~ self.hide_props_window()
4 t00mlabs 489
        self.show_all()
490
        self.log.debug("GUI loaded")
491
 
100 t00mlabs 492
        self.cb.show_workplace()
4 t00mlabs 493
 
84 t00mlabs 494
 
74 t00mlabs 495
    def setup_props_window(self):
496
        imgtitle = self.gui.get_widget('imgPropsTitle')
497
        icon = self.im.get_icon('fingerprint', 48, 48)
498
        imgtitle.set_from_pixbuf (icon)
499
        model = Gtk.TreeStore(str, str)
500
        trvprops = self.gui.add_widget('trvprops', Gtk.TreeView())
501
        trvprops.set_model(model)
502
 
503
        #~ ## key
504
        #~ renderer = Gtk.CellRendererText()
505
        #~ column = Gtk.TreeViewColumn('Id', renderer, text=0)
506
        #~ column.set_visible(False)
507
        #~ column.set_clickable(False)
508
        #~ column.set_sort_indicator(False)
509
        #~ trvprops.append_column(column)
510
 
511
        # Property
512
        renderer = Gtk.CellRendererText()
513
        renderer.set_alignment(1.0, 0.5)
514
        column = Gtk.TreeViewColumn('Property', renderer, markup=0)
515
        column.set_visible(True)
516
        column.set_expand(False)
517
        column.set_clickable(True)
518
        column.set_sort_indicator(True)
519
        trvprops.append_column(column)
520
 
521
        # Value
522
        renderer = Gtk.CellRendererText()
523
        renderer.set_alignment(0.0, 0.5)
524
        column = Gtk.TreeViewColumn('Value', renderer, markup=1)
525
        column.set_visible(True)
526
        column.set_expand(True)
527
        column.set_clickable(True)
528
        column.set_sort_indicator(True)
529
        trvprops.append_column(column)
530
        trvprops.show_all()
531
 
532
        trvprops.set_headers_visible(True)
533
        trvprops.set_enable_search(True)
534
        trvprops.set_grid_lines(Gtk.TreeViewGridLines.NONE)
535
        trvprops.set_search_column(1)
536
        #~ trvprops.connect('row-activated', self.double_click)
537
        selection = trvprops.get_selection()
538
        selection.set_mode(Gtk.SelectionMode.SINGLE)
539
        #~ trvprops.set_search_entry(self.pname)
540
 
541
        container = self.gui.get_widget('boxProps')
542
        self.gui.swap_widget(container, trvprops)
543
 
544
    def set_notes_manager_pane_position(self, pane, rectangle):
545
        pass
546
        #~ self.log.debug(type(pane.get_allocation()))
547
        position = rectangle.width/5*3
548
        pane.set_position(position)
549
        self.log.debug("Pane position: %s" % position)
550
 
551
 
4 t00mlabs 552
    def __completion_func(self, completion, key, iter):
553
        model = completion.get_model()
554
        text = model.get_value(iter, 0)
555
        if key.upper() in text.upper():
556
            return True
557
        return False
558
 
559
 
560
    def setup_combobox_completions(self, key):
561
        model = Gtk.ListStore(str)
562
        search = self.gui.get_widget("stySearchInfo")
563
        completion = Gtk.EntryCompletion()
564
        completion.set_model(model)
565
        completion.set_text_column(0)
566
        completion.set_match_func(self.__completion_func)
567
        search.set_completion(completion)
568
 
74 t00mlabs 569
        stats = self.db.get_stats()
4 t00mlabs 570
 
571
        try:
572
            items = list(stats[key])
573
            items.sort()
574
            for item in items:
575
                model.append([item])
576
        except:
577
            pass
578
 
579
 
580
    def cb_combobox_changed(self, combobox):
581
        model = combobox.get_model()
582
        treeiter = combobox.get_active_iter()
583
        key = model[treeiter][0]
584
        self.gui.set_key('cmbvalue', key)
585
        self.setup_combobox_completions(key)
586
 
587
 
74 t00mlabs 588
    def setup_combobox_search(self):
589
        combobox = self.gui.get_widget('cmbSearchInfo')
4 t00mlabs 590
        model = Gtk.TreeStore(str, str)
591
        combobox.set_model(model)
592
 
593
        ## key
594
        cell = Gtk.CellRendererText()
595
        cell.set_visible(False)
596
        combobox.pack_start(cell, True)
597
        combobox.add_attribute(cell, 'text', 0)
598
 
599
        ## value
600
        cell = Gtk.CellRendererText()
601
        cell.set_alignment(0.0, 0.5)
602
        combobox.pack_start(cell, expand=False)
603
        combobox.add_attribute(cell, 'markup', 1)
604
        combobox.connect('changed', self.cb_combobox_changed)
605
 
101 t00mlabs 606
        model.append(None, ['search', 'Search in all database'])
607
        model.append(None, ['project', 'Filter by project name'])
608
        model.append(None, ['task', 'Filter by task name'])
609
        model.append(None, ['component', 'Filter by component'])
610
        model.append(None, ['category', 'Filter by category'])
611
        model.append(None, ['type', 'Filter by type'])
612
        model.append(None, ['id', 'Filter by Id'])
613
        model.append(None, ['title', 'Filter by title'])
614
        model.append(None, ['priority', 'Filter by priority'])
615
        model.append(None, ['version', 'Filter by version'])
4 t00mlabs 616
        #~ model.append(None, ['released', 'Filter by release date'])
617
 
618
        combobox.set_active(0)
619
 
620
 
621
    def get_services(self):
622
        """Load services to be used in this class
623
        """
624
        self.gui = self.controller.get_service("GUI")
625
        self.app = self.gui.get_app()
626
        LOG_FILE = self.controller.get_file('LOG')
627
        self.log = get_logger('GtkAppWindow', LOG_FILE)
74 t00mlabs 628
        self.db = self.controller.get_service("DB")
4 t00mlabs 629
        self.uif = self.controller.get_service("UIF")
630
        self.prefs = self.controller.get_service("Settings")
631
        self.im = self.controller.get_service('IM')
632
        self.cb = self.controller.get_service('Callbacks')
74 t00mlabs 633
        self.tasks = self.controller.get_service('Tasks')
106 t00mlabs 634
        #~ self.visor = self.controller.get_service('Workplace')
100 t00mlabs 635
        #~ self.dashboard = self.controller.get_service('Dashboard')
4 t00mlabs 636
 
637
 
638
    def swap_widget(self, container, combobox):
639
        """Shortcut to GUI.swap_widget method
640
        """
641
        self.gui.swap_widget(container, combobox)