Subversion Repositories basico

Rev

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