Subversion Repositories basico

Rev

Rev 82 | Rev 84 | 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
 
83 t00mlabs 143
        # Workbook button
81 t00mlabs 144
        button = Gtk.Button()
83 t00mlabs 145
        button.set_tooltip_markup('<big><b>Workbook</b></big>')
81 t00mlabs 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)
83 t00mlabs 151
        button.connect('clicked', self.cb.show_workbook)
81 t00mlabs 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')
83 t00mlabs 288
        notebook = self.gui.get_widget('mainbox')
289
        notebook.set_current_page(5)
4 t00mlabs 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
 
82 t00mlabs 351
        # HEADERBAR WIDGETS
77 t00mlabs 352
        self.setup_headerbar()
353
 
82 t00mlabs 354
        # STATUSBAR WIDGETS
74 t00mlabs 355
        statusbar = self.gui.get_widget('pgbMain')
356
        statusbar.set_text("")
357
        statusbar.set_show_text(True)
358
        statusbar.set_fraction(0.0)
4 t00mlabs 359
        self.setup_menus()
82 t00mlabs 360
 
361
        # SETTINGS PAGE WIDGETS
362
        button = self.gui.get_widget('btnPrefsBack')
363
        button.connect('clicked', self.cb.show_workplace)
364
 
365
        button = self.gui.add_widget('btnPrefsSAPApply')
366
        button.connect('clicked', self.cb.apply_preferences)
367
 
368
        button = self.gui.add_widget('btnPrefsSAPCancel')
369
        button.connect('clicked', self.cb.refresh_view)
370
 
371
        button = self.gui.add_widget('btnPrefsSAPReset')
372
        button.connect('clicked', self.cb.default_preferences)
373
 
374
        # SAPNOTEVIEW WIDGETS
4 t00mlabs 375
        notesbox = self.gui.get_widget('notesbox')
376
        sapnoteview = SAPNoteView(self.controller)
377
        self.gui.add_widget('sapnoteview', sapnoteview)
378
        self.gui.add_widget('combobox')
379
        search = self.gui.add_widget('stySearchInfo')
380
        #~ search.connect('search_changed', self.search_notes)
381
        search.connect('activate', self.cb.search_notes)
74 t00mlabs 382
        self.setup_combobox_search()
4 t00mlabs 383
        self.swap_widget(notesbox, sapnoteview)
384
 
74 t00mlabs 385
 
386
        self.setup_props_window()
387
 
388
 
4 t00mlabs 389
        # Buttons
74 t00mlabs 390
        # Task link button
391
        self.cb.check_task_link_button_status()
4 t00mlabs 392
 
74 t00mlabs 393
        # button quit
394
        image = self.gui.get_widget('imgBtnQuit')
395
        icon = self.im.get_pixbuf_icon('power', 48, 48)
396
        image.set_from_pixbuf(icon)
397
        button = self.gui.get_widget('btnQuit')
398
        button.connect('clicked', self.gui.quit)
4 t00mlabs 399
 
74 t00mlabs 400
        # button about
401
        image = self.gui.get_widget('imgBtnAbout')
402
        icon = self.im.get_pixbuf_icon('about', 48, 48)
403
        image.set_from_pixbuf(icon)
404
        button = self.gui.get_widget('btnAbout')
405
        button.connect('clicked', self.uiapp.cb_show_about)
406
 
407
        # button settings
408
        image = self.gui.get_widget('imgBtnSettings')
409
        icon = self.im.get_pixbuf_icon('settings', 48, 48)
410
        image.set_from_pixbuf(icon)
411
        button = self.gui.get_widget('btnSettings')
412
        button.connect('clicked', self.show_settings_page)
413
 
414
        # button stats
415
        image = self.gui.get_widget('imgBtnStats')
416
        icon = self.im.get_pixbuf_icon('chart', 48, 48)
417
        image.set_from_pixbuf(icon)
418
        button = self.gui.get_widget('btnShowStats')
419
        button.connect('clicked', self.show_stats_page)
420
 
421
        # button show property details
422
        image = self.gui.get_widget('imgBtnShowProps')
423
        icon = self.im.get_pixbuf_icon('fingerprint', 48, 48)
424
        image.set_from_pixbuf(icon)
425
        button = self.gui.get_widget('btnShowProperties')
426
        button.connect('clicked', self.cb.show_properties)
427
 
428
        # button show manage window
429
        image = self.gui.get_widget('imgBtnShowManage')
430
        icon = self.im.get_pixbuf_icon('subwindow', 48, 48)
431
        image.set_from_pixbuf(icon)
432
        button = self.gui.get_widget('tgbShowManage')
433
        button.connect('toggled', self.switch_props_window)
434
 
435
        # button search
436
        image = self.gui.get_widget('imgBtnSearch')
437
        icon = self.im.get_pixbuf_icon('bsearch', 48, 48)
438
        image.set_from_pixbuf(icon)
439
        button = self.gui.get_widget('tgbSearch')
440
        button.connect('toggled', self.show_search)
441
        revsearch = self.gui.get_widget('revSearch')
442
        revsearch.hide()
443
        revsearch.set_no_show_all(True)
444
 
445
        # button import
446
        image = self.gui.get_widget('imgMnuBtnImport')
447
        icon = self.im.get_pixbuf_icon('import', 48, 48)
448
        image.set_from_pixbuf(icon)
449
        #~ button = self.gui.get_widget('mnuBtnImport')
450
        #~ button.connect('toggled', self.switch_props_window)
451
 
452
        # button refresh
453
        image = self.gui.get_widget('imgBtnRefresh')
454
        icon = self.im.get_pixbuf_icon('refresh', 48, 48)
455
        image.set_from_pixbuf(icon)
456
        button = self.gui.get_widget('btnRefreshSAPNoteView')
457
        button.connect('clicked', self.cb.refresh_and_clear_view)
458
 
459
 
460
        button = self.gui.get_widget('btnLinkTasksApply')
461
        button.connect('clicked', self.cb.link_tasks_to_sapnotes)
462
 
463
 
464
 
4 t00mlabs 465
        btnaddnote = self.gui.get_widget('btnStartDlNotes')
466
        btnaddnote.connect('clicked', self.cb.import_notes)
467
 
468
 
469
 
74 t00mlabs 470
        #~ btnShowAddSAPNotesDlg = self.gui.get_widget('btnShowAddSAPNotesDlg')
471
        #~ btnShowAddSAPNotesDlg.connect('clicked', self.show_addsapnotes_dialog)
472
 
4 t00mlabs 473
        btnStopDlNotes = self.gui.get_widget('btnStopDlNotes')
474
        btnStopDlNotes.connect('clicked', self.cb.stop_dl_notes)
475
 
74 t00mlabs 476
        #~ toggle= self.gui.get_widget('tgbFullScreen')
477
        #~ toggle.connect('toggled', self.uif.fullscreen)
4 t00mlabs 478
        switch = self.gui.get_widget('schExpandCollapse')
479
        switch.connect('state-set', sapnoteview.expand_collapse)
480
        switch = self.gui.get_widget('schSelectNotesAllNone')
481
        switch.connect('state-set', sapnoteview.select_all_none)
482
 
483
 
484
        # Actions button
485
        button = self.gui.get_widget('mnuBtnActions')
486
 
487
        # Notebook Import Widget
74 t00mlabs 488
        #~ ntbimport = self.gui.add_widget('ntbAddSAPNotes')
4 t00mlabs 489
 
74 t00mlabs 490
        sap_settings = self.prefs.get_custom_settings()
4 t00mlabs 491
        for setting in sap_settings:
74 t00mlabs 492
            try:
493
                widget = self.gui.add_widget(setting)
494
                widget.set_text(sap_settings[setting])
495
            except:
496
                pass
4 t00mlabs 497
 
74 t00mlabs 498
 
4 t00mlabs 499
        # Stats
500
        statsviewer = self.gui.add_widget('scrStatsViewer')
501
 
502
        btnstats = self.gui.add_widget('btnStatsByCompMain')
503
        btnstats.connect('clicked', self.cb.update_components_stats)
504
        iconwdg = self.gui.add_widget('imgStatsByCompMain')
505
        icon = self.im.get_pixbuf_icon('component', 64, 64)
506
        iconwdg.set_from_pixbuf(icon)
507
 
508
        btnstats = self.gui.add_widget('btnStatsByCategory')
509
        btnstats.connect('clicked', self.cb.update_categories_stats)
510
        iconwdg = self.gui.add_widget('imgStatsByCategory')
511
        icon = self.im.get_pixbuf_icon('category', 64, 64)
512
        iconwdg.set_from_pixbuf(icon)
513
 
74 t00mlabs 514
        self.hide_props_window()
4 t00mlabs 515
        self.show_all()
516
        self.log.debug("GUI loaded")
517
 
518
 
74 t00mlabs 519
    def setup_props_window(self):
520
        imgtitle = self.gui.get_widget('imgPropsTitle')
521
        icon = self.im.get_icon('fingerprint', 48, 48)
522
        imgtitle.set_from_pixbuf (icon)
523
        model = Gtk.TreeStore(str, str)
524
        trvprops = self.gui.add_widget('trvprops', Gtk.TreeView())
525
        trvprops.set_model(model)
526
 
527
        #~ ## key
528
        #~ renderer = Gtk.CellRendererText()
529
        #~ column = Gtk.TreeViewColumn('Id', renderer, text=0)
530
        #~ column.set_visible(False)
531
        #~ column.set_clickable(False)
532
        #~ column.set_sort_indicator(False)
533
        #~ trvprops.append_column(column)
534
 
535
        # Property
536
        renderer = Gtk.CellRendererText()
537
        renderer.set_alignment(1.0, 0.5)
538
        column = Gtk.TreeViewColumn('Property', renderer, markup=0)
539
        column.set_visible(True)
540
        column.set_expand(False)
541
        column.set_clickable(True)
542
        column.set_sort_indicator(True)
543
        trvprops.append_column(column)
544
 
545
        # Value
546
        renderer = Gtk.CellRendererText()
547
        renderer.set_alignment(0.0, 0.5)
548
        column = Gtk.TreeViewColumn('Value', renderer, markup=1)
549
        column.set_visible(True)
550
        column.set_expand(True)
551
        column.set_clickable(True)
552
        column.set_sort_indicator(True)
553
        trvprops.append_column(column)
554
        trvprops.show_all()
555
 
556
        trvprops.set_headers_visible(True)
557
        trvprops.set_enable_search(True)
558
        trvprops.set_grid_lines(Gtk.TreeViewGridLines.NONE)
559
        trvprops.set_search_column(1)
560
        #~ trvprops.connect('row-activated', self.double_click)
561
        selection = trvprops.get_selection()
562
        selection.set_mode(Gtk.SelectionMode.SINGLE)
563
        #~ trvprops.set_search_entry(self.pname)
564
 
565
        container = self.gui.get_widget('boxProps')
566
        self.gui.swap_widget(container, trvprops)
567
 
568
    def set_notes_manager_pane_position(self, pane, rectangle):
569
        pass
570
        #~ self.log.debug(type(pane.get_allocation()))
571
        position = rectangle.width/5*3
572
        pane.set_position(position)
573
        self.log.debug("Pane position: %s" % position)
574
 
575
 
576
 
4 t00mlabs 577
    def __completion_func(self, completion, key, iter):
578
        model = completion.get_model()
579
        text = model.get_value(iter, 0)
580
        if key.upper() in text.upper():
581
            return True
582
        return False
583
 
584
 
585
    def setup_combobox_completions(self, key):
586
        model = Gtk.ListStore(str)
587
        search = self.gui.get_widget("stySearchInfo")
588
        completion = Gtk.EntryCompletion()
589
        completion.set_model(model)
590
        completion.set_text_column(0)
591
        completion.set_match_func(self.__completion_func)
592
        search.set_completion(completion)
593
 
74 t00mlabs 594
        stats = self.db.get_stats()
4 t00mlabs 595
 
596
        try:
597
            items = list(stats[key])
598
            items.sort()
599
            for item in items:
600
                model.append([item])
601
        except:
602
            pass
603
 
604
 
605
    def cb_combobox_changed(self, combobox):
606
        model = combobox.get_model()
607
        treeiter = combobox.get_active_iter()
608
        key = model[treeiter][0]
609
        self.gui.set_key('cmbvalue', key)
610
        self.setup_combobox_completions(key)
611
 
612
 
74 t00mlabs 613
    def setup_combobox_search(self):
614
        combobox = self.gui.get_widget('cmbSearchInfo')
4 t00mlabs 615
        model = Gtk.TreeStore(str, str)
616
        combobox.set_model(model)
617
 
618
        ## key
619
        cell = Gtk.CellRendererText()
620
        cell.set_visible(False)
621
        combobox.pack_start(cell, True)
622
        combobox.add_attribute(cell, 'text', 0)
623
 
624
        ## value
625
        cell = Gtk.CellRendererText()
626
        cell.set_alignment(0.0, 0.5)
627
        combobox.pack_start(cell, expand=False)
628
        combobox.add_attribute(cell, 'markup', 1)
629
        combobox.connect('changed', self.cb_combobox_changed)
630
 
631
        model.append(None, ['search', 'Search in all database'])
632
        model.append(None, ['project', 'Filter by project name'])
633
        model.append(None, ['task', 'Filter by task name'])
634
        model.append(None, ['component', 'Filter by component'])
635
        model.append(None, ['category', 'Filter by category'])
636
        model.append(None, ['type', 'Filter by type'])
637
        model.append(None, ['id', 'Filter by Id'])
638
        model.append(None, ['title', 'Filter by title'])
639
        model.append(None, ['priority', 'Filter by priority'])
640
        model.append(None, ['version', 'Filter by version'])
641
        #~ model.append(None, ['released', 'Filter by release date'])
642
 
643
        combobox.set_active(0)
644
 
645
 
646
    def get_services(self):
647
        """Load services to be used in this class
648
        """
649
        self.gui = self.controller.get_service("GUI")
650
        self.app = self.gui.get_app()
651
        LOG_FILE = self.controller.get_file('LOG')
652
        self.log = get_logger('GtkAppWindow', LOG_FILE)
74 t00mlabs 653
        self.db = self.controller.get_service("DB")
4 t00mlabs 654
        self.uif = self.controller.get_service("UIF")
655
        self.prefs = self.controller.get_service("Settings")
656
        self.im = self.controller.get_service('IM')
657
        self.cb = self.controller.get_service('Callbacks')
74 t00mlabs 658
        self.tasks = self.controller.get_service('Tasks')
80 t00mlabs 659
        self.dashboard = self.controller.get_service('Dashboard')
4 t00mlabs 660
 
661
 
662
    def swap_widget(self, container, combobox):
663
        """Shortcut to GUI.swap_widget method
664
        """
665
        self.gui.swap_widget(container, combobox)