Subversion Repositories basico

Rev

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