Subversion Repositories basico

Rev

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