Subversion Repositories basico

Rev

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