Subversion Repositories basico

Rev

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