Subversion Repositories basico

Rev

Rev 179 | Rev 181 | 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 time
11
import platform
12
 
13
import gi
14
gi.require_version('Gtk', '3.0')
138 t00mlabs 15
#~ gi.require_version('WebKit', '3.0')
4 t00mlabs 16
 
17
from gi.repository import GLib
18
from gi.repository import GObject
19
from gi.repository import Gtk
20
from gi.repository import Gdk
21
from gi.repository import Gio
22
from gi.repository import Pango
138 t00mlabs 23
#~ from gi.repository import WebKit
4 t00mlabs 24
from gi.repository.GdkPixbuf import Pixbuf
25
 
142 t00mlabs 26
from .widgets import Statusbar
133 t00mlabs 27
from .service import Service
4 t00mlabs 28
 
29
 
30
MONOSPACE_FONT = 'Lucida Console' if platform.system() == 'Windows' else 'monospace'
31
 
133 t00mlabs 32
class GtkAppWindow(Gtk.ApplicationWindow, Service):
4 t00mlabs 33
    def __init__(self, uiapp):
34
        self.setup_controller(uiapp)
35
        self.get_services()
142 t00mlabs 36
        self.log = self.controller.log
4 t00mlabs 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()
141 t00mlabs 44
        self.controller.debug("Window setup correctly")
4 t00mlabs 45
        self.setup_widgets()
141 t00mlabs 46
        self.controller.debug("Widgets setup correctly")
137 t00mlabs 47
        #~ self.setup_app()
4 t00mlabs 48
 
106 t00mlabs 49
 
4 t00mlabs 50
 
141 t00mlabs 51
 
4 t00mlabs 52
    def setup_controller(self, uiapp):
53
        self.uiapp = uiapp
54
        self.controller = uiapp.get_controller()
55
 
56
 
57
    def setup_window(self):
58
        app_title = self.controller.get_app_info('name')
59
        Gtk.Window.__init__(self, title=app_title, application=self.uiapp)
60
        self.gui.add_widget('mainwindow', self)
153 t00m 61
        icon = self.im.get_icon('basico', 48, 48)
4 t00mlabs 62
        self.set_icon(icon)
63
        # FIXME
64
        # From docs: Don’t use this function. It sets the X xlib.Window
65
        # System “class” and “name” hints for a window.
66
        # But I have to do it or it doesn't shows the right title. ???
67
        self.set_wmclass (app_title, app_title)
68
        self.set_role(app_title)
69
        self.set_default_size(1024, 728)
70
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
93 t00mlabs 71
 
72
        # HEADERBAR WIDGETS
73
        self.setup_headerbar()
4 t00mlabs 74
        self.show_all()
75
 
76
 
77 t00mlabs 77
    def setup_headerbar(self):
78
        #~# Header Bar
79
        hb = self.gui.add_widget("HeaderBar", Gtk.HeaderBar())
80
        hb.set_show_close_button(True)
81
        hb.props.title = "Basico"
79 t00mlabs 82
        hb.props.subtitle = "SAP Notes Manager for SAP Consultants"
77 t00mlabs 83
 
180 t00m 84
        lhbox = self.setup_headerbar_left(hb)
85
        rhbox = self.setup_headerbar_right(hb)
86
        hb.pack_start(lhbox)
87
        hb.pack_end(rhbox)
88
        # ~ self.setup_headerbar_middle(hb)
89
 
90
        self.set_titlebar(hb)
91
        hb.show_all()
92
 
93
    def setup_headerbar_left(self, hb):
79 t00mlabs 94
        lhbox = Gtk.HBox() # Left side of title bar
131 t00mlabs 95
        button = self.gui.add_widget('tgbShowMenuView', Gtk.ToggleButton())
141 t00mlabs 96
        #~ button.connect('toggled', self.workplace.show_menu_view)
97
        button.set_active(False)
131 t00mlabs 98
        icon = self.im.get_image_icon('gtk-select-color')
99
        button.add(icon)
100
        lhbox.pack_start(button, False, False, 3)
101
 
157 t00m 102
        menuviews = self.gui.add_widget('mnuBtnViews', Gtk.Button())
130 t00mlabs 103
        hbox = Gtk.HBox()
104
        label = self.gui.add_widget('lblViewCurrent', Gtk.Label())
141 t00mlabs 105
        label.set_xalign(0.0)
130 t00mlabs 106
        image = self.gui.add_widget('imgViewCurrent', Gtk.Image())
107
        hbox.pack_start(image, False, False, 3)
108
        hbox.pack_start(label, False, False, 3)
109
        menuviews.add(hbox)
110
        lhbox.pack_start(menuviews, False, False, 3)
111
 
81 t00mlabs 112
        imgtitlebar = self.gui.add_widget('imgtitlebar', Gtk.Image())
101 t00mlabs 113
        imgtitlebar.set_visible(False)
114
        imgtitlebar.set_no_show_all(True)
79 t00mlabs 115
        lbltitlebar = self.gui.add_widget("lbltitlebar", Gtk.Label())
141 t00mlabs 116
        lbltitlebar.set_xalign(0.0)
117
        lbltitlebar.set_justify(Gtk.Justification.LEFT)
130 t00mlabs 118
        lbltitlebar.set_visible(False)
119
        lbltitlebar.set_no_show_all(True)
81 t00mlabs 120
        lhbox.pack_start(imgtitlebar, False, False, 3)
121
        lhbox.pack_start(lbltitlebar, False, False, 3)
122
        lhbox.show_all()
77 t00mlabs 123
 
180 t00m 124
        return lhbox
125
 
126
 
127
 
128
        # ~ mhbox = Gtk.HBox() # Mid side of title bar
129
        # ~
130
 
131
        # ~ # Middle side titlebar
132
        # ~ label = self.gui.add_widget('lblSelectedNotes', Gtk.Label())
133
        # ~ #~ label.set_markup('<b><small>0</small>/0 of <big>%d</big></b>' % self.db.get_total())
134
        # ~ button = self.gui.add_widget('mnuBtnActions', Gtk.MenuButton())
135
        # ~ button.set_relief(Gtk.ReliefStyle.NONE)
136
        # ~ button.set_no_show_all(False)
137
        # ~ button.set_visible(False)
138
        # ~ button.add(label)
139
        # ~ mhbox.pack_start(button, False, False, 0)
140
        # ~ hb.set_custom_title(mhbox)
141
 
142
    def setup_headerbar_right(self, hb):
143
        rhbox = Gtk.HBox() # Right side of title bar
144
 
145
        # Import button
146
        button = Gtk.Button()
147
        icon = self.im.get_image_icon('basico-add', 24, 24)
148
        button.set_image(icon)
130 t00mlabs 149
        button.set_relief(Gtk.ReliefStyle.NONE)
180 t00m 150
        popover = Gtk.Popover.new(button)
151
        button.connect('clicked', self.cb.show_popover_menu, popover)
152
        button.show_all()
130 t00mlabs 153
 
180 t00m 154
        # Popover body
155
        box = Gtk.Box(spacing = 0, orientation="vertical")
156
        box.set_size_request(300,200)
157
        box.set_hexpand(True)
158
        box.set_vexpand(True)
159
        box.set_property('margin', 3)
130 t00mlabs 160
 
180 t00m 161
        custom_vbox = Gtk.VBox()
162
 
163
        label = Gtk.Label()
164
        message = "<small>Write down the list of SAP Notes that you want to download.\nThey can be separated by a new line or by commas.</small>"
165
        label.set_markup('%s' % message)
166
        label.set_justify(Gtk.Justification.CENTER)
167
        # ~ label.modify_font(Pango.FontDescription('Arial 12'))
168
        custom_vbox.pack_start(label, False, True, 6)
169
 
170
        custom_scroller = Gtk.ScrolledWindow()
171
        custom_scroller.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
172
        custom_scroller.set_shadow_type(Gtk.ShadowType.IN)
173
        custom_scroller.set_vexpand(True)
174
        custom_button = Gtk.Button("Download")
175
        custom_button.connect('clicked', self.cb.import_notes_from_sapnet)
176
        custom_vbox.pack_end(custom_button, False, False, 3)
177
        custom_text_view = self.gui.add_widget('dltxtview', Gtk.TextView())
178
        custom_text_view.set_vexpand(True)
179
        custom_text_buffer = Gtk.TextBuffer()
180
        custom_text_buffer.set_text('')
181
        custom_text_view.set_buffer(custom_text_buffer)
182
        custom_scroller.add(custom_text_view)
183
        custom_vbox.pack_start(custom_scroller, True, True, 0)
184
        box.add(custom_vbox)
185
        popover.add(box)
186
 
187
 
188
        rhbox.pack_start(button, False, False, 6)
189
 
190
        # ~ btnactions = self.gui.add_widget('mnuBtnImport', Gtk.MenuButton())
191
        # ~ btnactions.set_always_show_image(True)
192
        # ~ btnactions.set_property("use-popover", True)
193
        # ~ btnactions.set_relief(Gtk.ReliefStyle.NONE)
194
        # ~ imgwpimport = Gtk.Image()
195
        # ~ icon = self.im.get_pixbuf_icon('menu-add-new', 24, 24)
196
        # ~ imgwpimport.set_from_pixbuf(icon)
197
        # ~ btnactions.add(imgwpimport)
198
        # ~ #~ actions_menu = self.gui.get_widget('actions_menu')
199
        # ~ #~ btnactions.set_menu_model(actions_menu)
200
        # ~ lhbox.pack_start(btnactions, False, False, 0)
201
 
153 t00m 202
        ## System Menu
77 t00mlabs 203
        button = Gtk.Button()
122 t00mlabs 204
        #~ button.set_tooltip_markup('<big><b>About</b></big>')
155 t00m 205
        icon = self.im.get_pixbuf_icon('menu-system', 24, 24)
81 t00mlabs 206
        image = Gtk.Image()
207
        image.set_from_pixbuf(icon)
208
        button.set_image(image)
77 t00mlabs 209
        button.set_relief(Gtk.ReliefStyle.NONE)
122 t00mlabs 210
        popover = Gtk.Popover.new(button)
150 t00m 211
        self.gui.add_widget('popover-right-menu', popover)
122 t00mlabs 212
        button.connect('clicked', self.cb.show_popover_menu, popover)
213
        #~ button.connect('clicked', self.uiapp.cb_show_about)
77 t00mlabs 214
        rhbox.pack_end(button, False, False, 0)
79 t00mlabs 215
 
122 t00mlabs 216
        # Popover body
217
        box = Gtk.Box(spacing = 0, orientation="vertical")
218
 
153 t00m 219
        ### About
122 t00mlabs 220
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
221
        icon = self.im.get_pixbuf_icon('about', 24, 24)
222
        image = Gtk.Image()
223
        image.set_from_pixbuf(icon)
224
        label = Gtk.Label("About")
225
        hbox.pack_start(image, False, False, 3)
226
        hbox.pack_start(label, False, False, 3)
227
        button = Gtk.Button()
228
        button.add(hbox)
229
        button.set_relief(Gtk.ReliefStyle.NONE)
136 t00mlabs 230
        button.connect('clicked', self.cb.show_about)
122 t00mlabs 231
        box.pack_end(button, False, False, 0)
232
 
153 t00m 233
        ### Help
122 t00mlabs 234
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
153 t00m 235
        icon = self.im.get_pixbuf_icon('basico-help', 24, 24)
93 t00mlabs 236
        image = Gtk.Image()
237
        image.set_from_pixbuf(icon)
122 t00mlabs 238
        label = Gtk.Label("Help")
239
        hbox.pack_start(image, False, False, 3)
240
        hbox.pack_start(label, False, False, 3)
241
        button = Gtk.Button()
242
        button.add(hbox)
93 t00mlabs 243
        button.set_relief(Gtk.ReliefStyle.NONE)
244
        button.connect('clicked', self.cb.show_help)
122 t00mlabs 245
        box.pack_end(button, False, False, 0)
93 t00mlabs 246
 
153 t00m 247
        ### Log viewer
122 t00mlabs 248
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
153 t00m 249
        icon = self.im.get_pixbuf_icon('basico-logviewer', 24, 24)
250
        image = Gtk.Image()
251
        image.set_from_pixbuf(icon)
252
        label = Gtk.Label("Log viewer")
253
        hbox.pack_start(image, False, False, 3)
254
        hbox.pack_start(label, False, False, 3)
255
        button = Gtk.Button()
256
        button.add(hbox)
257
        button.set_relief(Gtk.ReliefStyle.NONE)
258
        button.connect('clicked', self.cb.show_log)
259
        box.pack_end(button, False, False, 0)
260
 
261
        ### Settings
262
        hbox = Gtk.Box(spacing = 0, orientation="horizontal")
155 t00m 263
        icon = self.im.get_pixbuf_icon('basico-settings', 24, 24)
81 t00mlabs 264
        image = Gtk.Image()
265
        image.set_from_pixbuf(icon)
122 t00mlabs 266
        label = Gtk.Label("Settings")
267
        hbox.pack_start(image, False, False, 3)
268
        hbox.pack_start(label, False, False, 3)
269
        button = Gtk.Button()
270
        button.add(hbox)
79 t00mlabs 271
        button.set_relief(Gtk.ReliefStyle.NONE)
122 t00mlabs 272
        button.connect('clicked', self.cb.show_settings)
130 t00mlabs 273
        box.pack_start(button, False, False, 0)
122 t00mlabs 274
        popover.add(box)
180 t00m 275
        return rhbox
77 t00mlabs 276
 
277
 
110 t00mlabs 278
    def setup_popover_settings(self, widget):
279
        #Creating a popover
280
        popover = Gtk.Popover.new(widget)
281
        #~ popover.set_size_request(50,100)
282
 
283
        box = Gtk.Box(spacing = 10, orientation="vertical")
112 t00mlabs 284
        hboxfs = Gtk.Box(spacing = 10, orientation="horizontal")
285
        lblfs = Gtk.Label('Fullscreen')
286
        swFullScreen = self.gui.add_widget('fullscreen', Gtk.Switch())
287
        swFullScreen.connect('state-set', self.uif.fullscreen)
288
        hboxfs.pack_start(lblfs, True, True, 6)
289
        hboxfs.pack_start(swFullScreen, True, True, 6)
290
        hboxfs.set_homogeneous(True)
291
        box.add(hboxfs)
110 t00mlabs 292
        popover.add(box)
293
 
294
        return popover
295
 
296
 
4 t00mlabs 297
    def setup_menus(self):
106 t00mlabs 298
        pass
4 t00mlabs 299
 
74 t00mlabs 300
 
4 t00mlabs 301
    def show_home_page(self, *args):
302
        notebook = self.gui.get_widget('notebook')
303
        notebook.set_current_page(0)
304
 
74 t00mlabs 305
 
4 t00mlabs 306
    def show_settings_page(self, *args):
101 t00mlabs 307
        sapnoteview = self.gui.get_widget('viewmenu')
4 t00mlabs 308
        sapnoteview.set_view('settings')
83 t00mlabs 309
        notebook = self.gui.get_widget('mainbox')
310
        notebook.set_current_page(5)
4 t00mlabs 311
 
74 t00mlabs 312
 
313
    def show_stats_page(self, *args):
101 t00mlabs 314
        sapnoteview = self.gui.get_widget('viewmenu')
74 t00mlabs 315
        sapnoteview.set_view('stats')
316
        notebook = self.gui.get_widget('notebook')
317
        notebook.set_current_page(4)
318
 
319
 
4 t00mlabs 320
    def show_browser_page(self, *args):
321
        notebook = self.gui.get_widget('notebook')
322
        notebook.set_current_page(1)
323
 
324
 
74 t00mlabs 325
    def hide_props_window(self):
326
        hpnnotes = self.gui.get_widget('hpnNotesManager')
327
        boxprops = self.gui.get_widget('boxPropsWidget')
328
        size = hpnnotes.get_allocation()
4 t00mlabs 329
 
74 t00mlabs 330
        boxprops.set_no_show_all(True)
331
        boxprops.hide()
332
        hpnnotes.set_position(size.width)
4 t00mlabs 333
 
74 t00mlabs 334
 
335
    def show_props_window(self):
336
        hpnnotes = self.gui.get_widget('hpnNotesManager')
337
        boxprops = self.gui.get_widget('boxPropsWidget')
338
        size = hpnnotes.get_allocation()
339
 
340
        boxprops.set_no_show_all(False)
341
        boxprops.show_all()
342
        hpnnotes.show_all()
343
        hpnnotes.set_position(size.width/5*3)
344
 
345
 
346
    def switch_props_window(self, *args):
347
        tgbprops = self.gui.get_widget('tgbShowManage')
348
 
349
        if tgbprops.get_active():
350
            self.show_props_window()
351
        else:
352
            self.hide_props_window()
353
 
354
 
4 t00mlabs 355
    def setup_widgets(self):
137 t00mlabs 356
        # Mainbox
142 t00mlabs 357
        mainbox = self.gui.add_widget('mainbox', Gtk.VBox())
137 t00mlabs 358
        mainbox.set_hexpand(True)
359
        paned = self.gui.add_widget('paned', Gtk.HPaned())
178 t00m 360
        paned.set_property('margin-bottom', 6)
361
        paned.set_wide_handle(False)
164 t00m 362
        paned.set_position(300)
82 t00mlabs 363
 
137 t00mlabs 364
        # Paned
365
        ## Left view
166 t00m 366
        box = self.gui.add_widget('boxMenuView', Gtk.VBox())
367
        box.set_property('margin-left', 6)
368
        box.set_property('margin-right', 6)
176 t00m 369
        box.set_property('margin-bottom', 0)
179 t00m 370
        # ~ box.set_hexpand(True)
166 t00m 371
 
372
        ### Toolbar
373
        toolbar = Gtk.Toolbar()
374
        toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
175 t00m 375
        # ~ toolbar.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("Gray"))
179 t00m 376
        # ~ toolbar.set_hexpand(True)
175 t00m 377
        # ~ toolbar.set_property('margin-bottom', 6)
166 t00m 378
 
379
        #### Filter entry tool
380
        tool = Gtk.ToolItem.new()
381
 
382
        hbox = Gtk.HBox()
383
        viewfilter = self.gui.add_widget('viewfilter', Gtk.Entry())
178 t00m 384
        viewfilter.connect('activate', self.cb.filter_viewmenu)
175 t00m 385
 
386
        icon = self.im.get_pixbuf_icon('basico-refresh')
387
        viewfilter.set_icon_from_pixbuf(Gtk.EntryIconPosition.PRIMARY, icon)
388
        viewfilter.set_icon_sensitive(Gtk.EntryIconPosition.PRIMARY, True)
389
        viewfilter.set_icon_tooltip_markup (Gtk.EntryIconPosition.PRIMARY, "Refresh and collapse")
390
 
391
        icon = self.im.get_pixbuf_icon('basico-filter')
392
        viewfilter.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, icon)
393
        viewfilter.set_icon_sensitive(Gtk.EntryIconPosition.SECONDARY, True)
394
        viewfilter.set_icon_tooltip_markup (Gtk.EntryIconPosition.SECONDARY, "Click here to expand the tree")
395
        viewfilter.set_placeholder_text("Filter this view...")
396
 
397
        def on_icon_pressed(entry, icon_pos, event):
398
            if icon_pos == Gtk.EntryIconPosition.PRIMARY:
399
                viewmenu = self.gui.get_widget('viewmenu')
400
                viewmenu.refresh()
401
            elif icon_pos == Gtk.EntryIconPosition.SECONDARY:
402
                self.cb.expand_menuview()
403
 
404
        viewfilter.connect("icon-press", on_icon_pressed)
405
 
166 t00m 406
        hbox.pack_start(viewfilter, True, True, 0)
407
        tool.add(hbox)
408
        tool.set_expand(True)
409
        toolbar.insert(tool, -1)
410
 
411
        box.pack_start(toolbar, False, False, 0)
412
 
413
        #### View treeview
137 t00mlabs 414
        scr = Gtk.ScrolledWindow()
415
        scr.set_hexpand(True)
416
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
164 t00m 417
        scr.set_shadow_type(Gtk.ShadowType.IN)
137 t00mlabs 418
        vwp = Gtk.Viewport()
419
        vwp.set_hexpand(True)
420
        viewsbox = self.gui.add_widget('viewsbox', Gtk.Box())
421
        viewsbox.set_hexpand(True)
422
        vwp.add(viewsbox)
423
        scr.add(vwp)
166 t00m 424
        box.pack_start(scr, True, True, 0)
137 t00mlabs 425
        paned.add1(box)
82 t00mlabs 426
 
137 t00mlabs 427
        ## Right view
168 t00m 428
        box = self.gui.add_widget('boxVisor', Gtk.VBox())
137 t00mlabs 429
        box.set_hexpand(True)
168 t00m 430
 
431
        boxtoolbar = self.gui.add_widget('boxtoolbar', Gtk.HBox())
432
        box.pack_start(boxtoolbar, False, False, 0)
433
 
137 t00mlabs 434
        scr = self.gui.add_widget('scrVisor', Gtk.ScrolledWindow())
178 t00m 435
        # ~ scr.set_shadow_type(Gtk.ShadowType.IN)
137 t00mlabs 436
        scr.set_hexpand(True)
437
        scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
438
        vwp = Gtk.Viewport()
439
        vwp.set_hexpand(True)
440
        notesbox = self.gui.add_widget('notesbox', Gtk.Box())
441
        notesbox.set_hexpand(True)
168 t00m 442
        notesbox.set_vexpand(True)
137 t00mlabs 443
        vwp.add(notesbox)
444
        scr.add(vwp)
168 t00m 445
        box.pack_start(scr, True, True, 0)
137 t00mlabs 446
        paned.add2(box)
142 t00mlabs 447
        mainbox.pack_start(paned, True, True, 0)
82 t00mlabs 448
 
162 t00m 449
        # Statusbar
142 t00mlabs 450
        statusbar = self.gui.add_widget('statusbar', Statusbar(self.controller))
451
        mainbox.pack_start(statusbar, False, False, 0)
452
 
137 t00mlabs 453
        self.add(mainbox)
454
        self.show_all()
82 t00mlabs 455
 
141 t00mlabs 456
        # Finally, activate Workplace
457
        self.controller.get_service('Workplace')
82 t00mlabs 458
 
137 t00mlabs 459
 
460
 
74 t00mlabs 461
    def setup_props_window(self):
462
        imgtitle = self.gui.get_widget('imgPropsTitle')
463
        icon = self.im.get_icon('fingerprint', 48, 48)
464
        imgtitle.set_from_pixbuf (icon)
465
        model = Gtk.TreeStore(str, str)
466
        trvprops = self.gui.add_widget('trvprops', Gtk.TreeView())
467
        trvprops.set_model(model)
468
 
469
        # Property
470
        renderer = Gtk.CellRendererText()
471
        renderer.set_alignment(1.0, 0.5)
472
        column = Gtk.TreeViewColumn('Property', renderer, markup=0)
473
        column.set_visible(True)
474
        column.set_expand(False)
475
        column.set_clickable(True)
476
        column.set_sort_indicator(True)
477
        trvprops.append_column(column)
478
 
479
        # Value
480
        renderer = Gtk.CellRendererText()
481
        renderer.set_alignment(0.0, 0.5)
482
        column = Gtk.TreeViewColumn('Value', renderer, markup=1)
483
        column.set_visible(True)
484
        column.set_expand(True)
485
        column.set_clickable(True)
486
        column.set_sort_indicator(True)
487
        trvprops.append_column(column)
488
        trvprops.show_all()
489
 
490
        trvprops.set_headers_visible(True)
491
        trvprops.set_enable_search(True)
492
        trvprops.set_grid_lines(Gtk.TreeViewGridLines.NONE)
493
        trvprops.set_search_column(1)
494
        #~ trvprops.connect('row-activated', self.double_click)
495
        selection = trvprops.get_selection()
496
        selection.set_mode(Gtk.SelectionMode.SINGLE)
497
        #~ trvprops.set_search_entry(self.pname)
498
 
499
        container = self.gui.get_widget('boxProps')
500
        self.gui.swap_widget(container, trvprops)
501
 
502
    def set_notes_manager_pane_position(self, pane, rectangle):
133 t00mlabs 503
        #~ self.controller.debug(type(pane.get_allocation()))
74 t00mlabs 504
        position = rectangle.width/5*3
505
        pane.set_position(position)
133 t00mlabs 506
        self.debug("Pane position: %s" % position)
74 t00mlabs 507
 
508
 
4 t00mlabs 509
    def __completion_func(self, completion, key, iter):
510
        model = completion.get_model()
511
        text = model.get_value(iter, 0)
512
        if key.upper() in text.upper():
513
            return True
514
        return False
515
 
516
 
517
    def setup_combobox_completions(self, key):
518
        model = Gtk.ListStore(str)
519
        search = self.gui.get_widget("stySearchInfo")
520
        completion = Gtk.EntryCompletion()
521
        completion.set_model(model)
522
        completion.set_text_column(0)
523
        completion.set_match_func(self.__completion_func)
524
        search.set_completion(completion)
525
 
74 t00mlabs 526
        stats = self.db.get_stats()
4 t00mlabs 527
 
528
        try:
529
            items = list(stats[key])
530
            items.sort()
531
            for item in items:
532
                model.append([item])
533
        except:
534
            pass
535
 
536
 
537
    def cb_combobox_changed(self, combobox):
538
        model = combobox.get_model()
539
        treeiter = combobox.get_active_iter()
540
        key = model[treeiter][0]
541
        self.gui.set_key('cmbvalue', key)
542
        self.setup_combobox_completions(key)
543
 
544
 
74 t00mlabs 545
    def setup_combobox_search(self):
546
        combobox = self.gui.get_widget('cmbSearchInfo')
4 t00mlabs 547
        model = Gtk.TreeStore(str, str)
548
        combobox.set_model(model)
549
 
550
        ## key
551
        cell = Gtk.CellRendererText()
552
        cell.set_visible(False)
553
        combobox.pack_start(cell, True)
554
        combobox.add_attribute(cell, 'text', 0)
555
 
556
        ## value
557
        cell = Gtk.CellRendererText()
558
        cell.set_alignment(0.0, 0.5)
559
        combobox.pack_start(cell, expand=False)
560
        combobox.add_attribute(cell, 'markup', 1)
561
        combobox.connect('changed', self.cb_combobox_changed)
562
 
101 t00mlabs 563
        model.append(None, ['search', 'Search in all database'])
564
        model.append(None, ['project', 'Filter by project name'])
565
        model.append(None, ['task', 'Filter by task name'])
566
        model.append(None, ['component', 'Filter by component'])
567
        model.append(None, ['category', 'Filter by category'])
568
        model.append(None, ['type', 'Filter by type'])
569
        model.append(None, ['id', 'Filter by Id'])
570
        model.append(None, ['title', 'Filter by title'])
571
        model.append(None, ['priority', 'Filter by priority'])
572
        model.append(None, ['version', 'Filter by version'])
4 t00mlabs 573
        #~ model.append(None, ['released', 'Filter by release date'])
574
 
575
        combobox.set_active(0)
576
 
577
 
578
    def get_services(self):
579
        """Load services to be used in this class
580
        """
581
        self.gui = self.controller.get_service("GUI")
582
        self.app = self.gui.get_app()
74 t00mlabs 583
        self.db = self.controller.get_service("DB")
4 t00mlabs 584
        self.uif = self.controller.get_service("UIF")
585
        self.prefs = self.controller.get_service("Settings")
586
        self.im = self.controller.get_service('IM')
587
        self.cb = self.controller.get_service('Callbacks')
141 t00mlabs 588
        #~ self.workplace = self.controller.get_service('Workplace')
4 t00mlabs 589
 
590
 
591
    def swap_widget(self, container, combobox):
592
        """Shortcut to GUI.swap_widget method
593
        """
594
        self.gui.swap_widget(container, combobox)