Subversion Repositories basico

Rev

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