Subversion Repositories basico

Rev

Rev 4 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4 Rev 74
Line 6... Line 6...
6
# Description: UI and related callbacks service
6
# Description: UI and related callbacks service
7
7
8
import os
8
import os
9
import csv
9
import csv
10
import json
10
import json
-
 
11
import time
-
 
12
import glob
-
 
13
from os.path import basename
-
 
14
from datetime import datetime
11
15
12
import gi
16
import gi
13
gi.require_version('Gtk', '3.0')
17
gi.require_version('Gtk', '3.0')
14
gi.require_version('WebKit', '3.0')
18
gi.require_version('WebKit', '3.0')
15
from gi.repository import Gtk
19
from gi.repository import Gtk
16
from gi.repository import Gio
20
from gi.repository import Gio
17
from gi.repository import Pango
21
from gi.repository import Pango
18
from gi.repository.GdkPixbuf import Pixbuf
22
from gi.repository.GdkPixbuf import Pixbuf
19
from gi.repository import WebKit
23
from gi.repository import WebKit
-
 
24
-
 
25
from concurrent.futures import ThreadPoolExecutor as Executor
20
26
21
from .service import Service
27
from .service import Service
22
28
23
PROPKEYS = ['tasks', 'id', 'title', 'type', 'componentkey', 'componenttxt',
-
 
24
            'category', 'version', 'priority', 'language', 'releaseon',
-
 
25
            'bookmark']
-
 
-
 
29
SEP = os.path.sep
-
 
30
-
 
31
# PROPKEYS = CSV headers. SAP Note metadata
-
 
32
PROPKEYS = ['id', 'title', 'type', 'componentkey',
-
 
33
            'componenttxt', 'category', 'priority', 'releaseon',
-
 
34
            'language', 'version']
-
 
35
-
 
36
# Extend PROPKEYS with custom basico metadata
-
 
37
PROPKEYS.extend (['Tasks', 'Bookmark'])
26
38
27
class Callback(Service):
39
class Callback(Service):
28
    def initialize(self):
40
    def initialize(self):
29
        self.log.debug("Loading UI Callbacks")
-
 
30
        self.get_services()
41
        self.get_services()
31
42
32
    def get_services(self):
43
    def get_services(self):
33
        self.gui = self.app.get_service('GUI')
44
        self.gui = self.app.get_service('GUI')
34
        self.uif = self.app.get_service("UIF")
45
        self.uif = self.app.get_service("UIF")
35
        self.sap = self.app.get_service('SAP')
46
        self.sap = self.app.get_service('SAP')
36
        self.tasks = self.app.get_service('Tasks')
47
        self.tasks = self.app.get_service('Tasks')
37
        self.alert = self.app.get_service('Notify')
48
        self.alert = self.app.get_service('Notify')
38
        self.stats = self.app.get_service('Stats')
-
 
-
 
49
        #~ self.stats = self.app.get_service('Stats')
-
 
50
        self.utils = self.app.get_service('Utils')
39
51
40
    def execute_action(self, *args):
52
    def execute_action(self, *args):
41
        action = args[0]
53
        action = args[0]
42
        action_name = action.get_name()
54
        action_name = action.get_name()
43
        try:
55
        try:
Line 48... Line 60...
48
            self.log.error("Callback for action '%s' not registered" % action_name)
60
            self.log.error("Callback for action '%s' not registered" % action_name)
49
            raise
61
            raise
50
62
51
63
52
    def actions_browse(self, *args):
64
    def actions_browse(self, *args):
-
 
65
        SAP_NOTE_URL = self.sap.get_config_value('CNF_SAP_NOTE_URL')
53
        sapnoteview = self.gui.get_widget('sapnoteview')
66
        sapnoteview = self.gui.get_widget('sapnoteview')
54
        sapnotes = list(sapnoteview.get_selected_notes())
-
 
55
        #~ sapnotes.sort()
-
 
56
        try:
-
 
57
            self.sap.browse_notes(sapnotes)
-
 
58
        except: pass
-
 
-
 
67
        sapnotes = sapnoteview.get_selected_notes()
-
 
68
        lurl = []
-
 
69
        for sid in sapnotes:
-
 
70
            url = SAP_NOTE_URL % sid
-
 
71
            lurl.append(url)
-
 
72
            self.log.debug("Browsing SAP Note %s" % sid)
-
 
73
        self.utils.browse(lurl)
59
74
60
75
61
    def actions_other_delete(self, *args):
76
    def actions_other_delete(self, *args):
-
 
77
        db = self.get_service('DB')
62
        sapnoteview = self.gui.get_widget('sapnoteview')
78
        sapnoteview = self.gui.get_widget('sapnoteview')
63
        sapnotes = list(sapnoteview.get_selected_notes())
-
 
-
 
79
        sapnotes = sapnoteview.get_selected_notes()
64
        sapnotes.sort()
80
        sapnotes.sort()
65
        winroot = self.gui.get_widget('mainwinow')
81
        winroot = self.gui.get_widget('mainwinow')
66
82
67
        dialog = Gtk.MessageDialog(winroot, 0, Gtk.MessageType.WARNING,
83
        dialog = Gtk.MessageDialog(winroot, 0, Gtk.MessageType.WARNING,
68
            Gtk.ButtonsType.OK_CANCEL, "Are you sure?")
84
            Gtk.ButtonsType.OK_CANCEL, "Are you sure?")
Line 72... Line 88...
72
        dialog.format_secondary_text(
88
        dialog.format_secondary_text(
73
            "These SAP Notes will be deleted:\n%s" % ', '.join(sapnotes))
89
            "These SAP Notes will be deleted:\n%s" % ', '.join(sapnotes))
74
90
75
        response = dialog.run()
91
        response = dialog.run()
76
        if response == Gtk.ResponseType.OK:
92
        if response == Gtk.ResponseType.OK:
-
 
93
            db = self.get_service('DB')
77
            sapnotes = sapnoteview.get_selected_notes()
94
            sapnotes = sapnoteview.get_selected_notes()
78
            for sapnote in sapnotes:
95
            for sapnote in sapnotes:
79
                self.sap.delete_sapnote(sapnote)
-
 
-
 
96
                db.delete(sapnote)
80
            self.search_notes()
97
            self.search_notes()
81
            self.refresh_view()
98
            self.refresh_view()
82
            self.alert.show('Delete', 'Selected SAP Notes deleted', 'information')
99
            self.alert.show('Delete', 'Selected SAP Notes deleted', 'information')
83
            self.log.info("Selected SAP Notes deleted")
100
            self.log.info("Selected SAP Notes deleted")
84
            self.sap.save_notes()
-
 
-
 
101
            db.save_notes()
85
        elif response == Gtk.ResponseType.CANCEL:
102
        elif response == Gtk.ResponseType.CANCEL:
86
            self.alert.show('Delete', 'Delete action canceled by user', 'warning')
103
            self.alert.show('Delete', 'Delete action canceled by user', 'warning')
87
            self.log.info("Delete action canceled by user")
104
            self.log.info("Delete action canceled by user")
88
105
89
        dialog.destroy()
106
        dialog.destroy()
90
107
91
        return response
108
        return response
-
 
109
-
 
110
-
 
111
    def show_properties(self, *args):
-
 
112
        notebook = self.gui.get_widget('ntbOperations')
-
 
113
        toggle = self.gui.get_widget('tgbShowManage')
-
 
114
        notebook.set_current_page(0)
-
 
115
        toggle.set_active(True)
92
116
93
117
94
    def actions_manage_tasks(self, *args):
118
    def actions_manage_tasks(self, *args):
95
        sapnoteview = self.gui.get_widget('sapnoteview')
-
 
96
        try:
-
 
97
            sapnotes = list(sapnoteview.get_selected_notes())
-
 
98
        except:
-
 
99
            sapnote = ''
-
 
100
        self.tasks.show_window(sapnotes)
-
 
-
 
119
        #~ sapnoteview = self.gui.get_widget('sapnoteview')
-
 
120
        #~ try:
-
 
121
            #~ sapnotes = sapnoteview.get_selected_notes()
-
 
122
        #~ except:
-
 
123
            #~ sapnote = ''
-
 
124
        self.tasks.show_window(active=True)
101
125
-
 
126
-
 
127
    def link_tasks_to_sapnotes(self, *args):
-
 
128
        sapnoteview = self.gui.get_widget('sapnoteview')
-
 
129
        sapnotes = sapnoteview.get_selected_notes()
-
 
130
        tasks = self.tasks.get_selected()
-
 
131
        self.sap.link_to_task(sapnotes, tasks)
102
132
103
    def actions_bookmark(self, *args):
133
    def actions_bookmark(self, *args):
-
 
134
        db = self.get_service('DB')
104
        sapnoteview = self.gui.get_widget('sapnoteview')
135
        sapnoteview = self.gui.get_widget('sapnoteview')
105
        sapnotes = list(sapnoteview.get_selected_notes())
-
 
-
 
136
        sapnotes = sapnoteview.get_selected_notes()
-
 
137
        self.log.debug("Action bookmark triggered for SAP Notes: %s" % sapnotes)
106
        view = sapnoteview.get_view()
138
        view = sapnoteview.get_view()
107
        self.sap.set_bookmark(sapnotes)
139
        self.sap.set_bookmark(sapnotes)
108
        self.sap.save_notes()
-
 
-
 
140
        db.save_notes()
109
        self.refresh_view(view=view)
141
        self.refresh_view(view=view)
110
        self.alert.show('Bookmarks', 'Selected SAP Notes bookmarked', 'information')
142
        self.alert.show('Bookmarks', 'Selected SAP Notes bookmarked', 'information')
111
143
112
144
113
    def actions_unbookmark(self, *args):
145
    def actions_unbookmark(self, *args):
-
 
146
        db = self.get_service('DB')
114
        sapnoteview = self.gui.get_widget('sapnoteview')
147
        sapnoteview = self.gui.get_widget('sapnoteview')
115
        sapnotes = list(sapnoteview.get_selected_notes())
-
 
-
 
148
        sapnotes = sapnoteview.get_selected_notes()
-
 
149
        self.log.debug("Action unbookmark triggered for SAP Notes: %s" % sapnotes)
116
        self.sap.set_no_bookmark(sapnotes)
150
        self.sap.set_no_bookmark(sapnotes)
117
        self.sap.save_notes()
-
 
-
 
151
        db.save_notes()
118
        self.refresh_view(view='bookmarks')
152
        self.refresh_view(view='bookmarks')
119
        self.alert.show('Bookmarks', 'Selected SAP Notes unbookmarked', 'information')
153
        self.alert.show('Bookmarks', 'Selected SAP Notes unbookmarked', 'information')
120
154
121
155
122
    def actions_export_csv(self, *args):
156
    def actions_export_csv(self, *args):
-
 
157
        db = self.get_service('DB')
123
        rootwin = self.gui.get_widget('mainwndow')
158
        rootwin = self.gui.get_widget('mainwndow')
124
        sapnoteview = self.gui.get_widget('sapnoteview')
159
        sapnoteview = self.gui.get_widget('sapnoteview')
125
        sapnotes = list(sapnoteview.get_selected_notes())
-
 
-
 
160
        sapnotes = sapnoteview.get_selected_notes()
126
        dialog = Gtk.FileChooserDialog("Save file", rootwin,
161
        dialog = Gtk.FileChooserDialog("Save file", rootwin,
127
            Gtk.FileChooserAction.SAVE,
162
            Gtk.FileChooserAction.SAVE,
128
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
163
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
129
                 Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
164
                 Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
130
        response = dialog.run()
165
        response = dialog.run()
131
166
132
        if response == Gtk.ResponseType.OK:
167
        if response == Gtk.ResponseType.OK:
133
            export_path = dialog.get_filename()
168
            export_path = dialog.get_filename()
134
            writer = csv.writer(open(export_path, 'w'), delimiter=';', quoting=csv.QUOTE_ALL)
169
            writer = csv.writer(open(export_path, 'w'), delimiter=';', quoting=csv.QUOTE_ALL)
135
            csvrow = []
170
            csvrow = []
-
 
171
136
            for key in PROPKEYS:
172
            for key in PROPKEYS:
137
                csvrow.append(key)
-
 
-
 
173
                csvrow.append(key.capitalize())
138
            writer.writerow(csvrow)
174
            writer.writerow(csvrow)
139
            for sapnote in sapnotes:
-
 
-
 
175
-
 
176
            for tid in sapnotes:
-
 
177
                sid = "0"*(10 - len(tid)) + tid
-
 
178
                self.log.debug("Exporting SAP Note %s to CSV file" % sid)
140
                csvrow = []
179
                csvrow = []
141
                props = self.sap.get_node(sapnote)
-
 
-
 
180
                props = db.get_sapnote_metadata(sid)
-
 
181
142
                for prop in PROPKEYS:
182
                for prop in PROPKEYS:
143
                    if prop == 'tasks':
183
                    if prop == 'tasks':
144
                        tasks = ', '.join(props[prop])
184
                        tasks = ', '.join(props[prop])
145
                        csvrow.append(tasks)
185
                        csvrow.append(tasks)
146
                    else:
186
                    else:
Line 155... Line 195...
155
195
156
196
157
    def actions_export_txt(self, *args):
197
    def actions_export_txt(self, *args):
158
        rootwin = self.gui.get_widget('mainwndow')
198
        rootwin = self.gui.get_widget('mainwndow')
159
        sapnoteview = self.gui.get_widget('sapnoteview')
199
        sapnoteview = self.gui.get_widget('sapnoteview')
160
        sapnotes = list(sapnoteview.get_selected_notes())
-
 
-
 
200
        sapnotes = sapnoteview.get_selected_notes()
161
        dialog = Gtk.FileChooserDialog("Save file", rootwin,
201
        dialog = Gtk.FileChooserDialog("Save file", rootwin,
162
            Gtk.FileChooserAction.SAVE,
202
            Gtk.FileChooserAction.SAVE,
163
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
203
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
164
                 Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
204
                 Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
165
        response = dialog.run()
205
        response = dialog.run()
Line 175... Line 215...
175
            self.alert.show('Export', 'Export canceled by user', 'warning')
215
            self.alert.show('Export', 'Export canceled by user', 'warning')
176
            self.log.info("Export canceled by user")
216
            self.log.info("Export canceled by user")
177
        dialog.destroy()
217
        dialog.destroy()
178
218
179
219
180
    def actions_export_bco(self, *args):
-
 
-
 
220
    def actions_export_json(self, *args):
-
 
221
        db = self.get_service('DB')
181
        rootwin = self.gui.get_widget('mainwndow')
222
        rootwin = self.gui.get_widget('mainwndow')
182
        sapnoteview = self.gui.get_widget('sapnoteview')
223
        sapnoteview = self.gui.get_widget('sapnoteview')
183
        sapnotes = list(sapnoteview.get_selected_notes())
-
 
-
 
224
        sapnotes = sapnoteview.get_selected_notes()
184
        dialog = Gtk.FileChooserDialog("Save file", rootwin,
225
        dialog = Gtk.FileChooserDialog("Save file", rootwin,
185
            Gtk.FileChooserAction.SAVE,
-
 
-
 
226
            Gtk.FileChooserAction.SELECT_FOLDER,
186
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
227
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
187
                 Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
228
                 Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
188
        response = dialog.run()
229
        response = dialog.run()
189
230
190
        if response == Gtk.ResponseType.OK:
231
        if response == Gtk.ResponseType.OK:
191
            export_path = dialog.get_filename()
232
            export_path = dialog.get_filename()
192
            bag = {}
233
            bag = {}
193
            for sid in sapnotes:
-
 
194
                sapnote = self.sap.get_node(sid)
-
 
-
 
234
            for tid in sapnotes:
-
 
235
                sid = "0"*(10 - len(tid)) + tid
-
 
236
                sapnote = db.get_sapnote_metadata(sid)
195
                bag[sid] = sapnote
237
                bag[sid] = sapnote
196
            self.sap.save_notes(export_path, bag)
-
 
197
            self.alert.show('Export', 'Selected SAP Notes exported successfully to BCO format', 'information')
-
 
198
            self.log.info("Selected SAP Notes exported to BCO format: %s" % export_path)
-
 
-
 
238
            now = datetime.now()
-
 
239
            target = export_path + SEP + 'basico-%s.json' % now.strftime("%Y%m%d_%H%M%S")
-
 
240
            db.export_basico_package(bag, target)
-
 
241
            self.alert.show('Export', 'Selected SAP Notes exported successfully to JSON format', 'information')
-
 
242
            self.log.info("Selected SAP Notes exported to JSON: %s" % target)
199
        else:
243
        else:
200
            self.alert.show('Export', 'Export canceled by user', 'warning')
244
            self.alert.show('Export', 'Export canceled by user', 'warning')
201
            self.log.info("Export canceled by user")
245
            self.log.info("Export canceled by user")
202
        dialog.destroy()
246
        dialog.destroy()
203
247
-
 
248
-
 
249
    def actions_import_json(self, *args):
-
 
250
        self.import_notes_from_file()
-
 
251
        #~ db = self.get_service('DB')
-
 
252
        #~ rootwin = self.gui.get_widget('mainwndow')
-
 
253
        #~ sapnoteview = self.gui.get_widget('sapnoteview')
-
 
254
        #~ sapnotes = sapnoteview.get_selected_notes()
-
 
255
        #~ dialog = Gtk.FileChooserDialog("Select Basico JSON file", rootwin,
-
 
256
            #~ Gtk.FileChooserAction.OPEN,
-
 
257
                #~ (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
-
 
258
                 #~ Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
-
 
259
        #~ response = dialog.run()
-
 
260
-
 
261
        #~ if response == Gtk.ResponseType.OK:
-
 
262
            #~ source = dialog.get_filename()
-
 
263
            #~ try:
-
 
264
                #~ with open(source, 'r') as fp:
-
 
265
                    #~ bag = json.load(fp)
-
 
266
                    #~ db.import(bag)
-
 
267
                    #~ self.log.debug ("Imported %d notes" % len(bag))
-
 
268
            #~ except Exception as error:
-
 
269
                #~ self.log.info("SAP Notes database not found. Creating a new one")
-
 
270
                #~ self.save_notes()
-
 
271
-
 
272
            #~ self.alert.show('Export', 'Selected SAP Notes exported successfully to JSON format', 'information')
-
 
273
            #~ self.log.info("Selected SAP Notes exported to JSON: %s" % target)
-
 
274
        #~ else:
-
 
275
            #~ self.alert.show('Export', 'Export canceled by user', 'warning')
-
 
276
            #~ self.log.info("Export canceled by user")
-
 
277
        #~ dialog.destroy()
-
 
278
-
 
279
-
 
280
-
 
281
    def actions_import_launchpad(self, *args):
-
 
282
        self.show_addsapnotes_dialog()
204
283
205
284
206
    def set_search_filter_key(self, key):
285
    def set_search_filter_key(self, key):
207
        self.gui.set_key('cmbvalue', key)
286
        self.gui.set_key('cmbvalue', key)
208
287
Line 215... Line 294...
215
        searchentry = self.gui.get_widget("stySearchInfo")
294
        searchentry = self.gui.get_widget("stySearchInfo")
216
        searchentry.set_text(term)
295
        searchentry.set_text(term)
217
296
218
297
219
    def search_notes(self, *args):
298
    def search_notes(self, *args):
-
 
299
        db = self.get_service('DB')
220
        searchentry = self.gui.get_widget("stySearchInfo")
300
        searchentry = self.gui.get_widget("stySearchInfo")
221
        cmbvalue = self.gui.get_key('cmbvalue')
301
        cmbvalue = self.gui.get_key('cmbvalue')
222
        self.log.debug("Searching in %s" % cmbvalue)
-
 
-
 
302
        self.log.debug("Serch term: %s" % cmbvalue)
223
        try:
303
        try:
224
            term = searchentry.get_text()
304
            term = searchentry.get_text()
225
        except:
305
        except:
226
            term = ''
306
            term = ''
227
        self.log.debug("Looking for '%s'" % term)
-
 
-
 
307
228
        sapnoteview = self.gui.get_widget('sapnoteview')
308
        sapnoteview = self.gui.get_widget('sapnoteview')
229
        sapnotes = self.sap.get_notes()
-
 
-
 
309
        sapnotes = db.get_notes()
230
        found = {}
310
        found = {}
231
311
232
        if len(term) == 0:
312
        if len(term) == 0:
233
            self.current_notes = found = sapnotes
313
            self.current_notes = found = sapnotes
234
            sapnoteview.populate(found)
314
            sapnoteview.populate(found)
235
            sapnoteview.collapse()
315
            sapnoteview.collapse()
-
 
316
            self.log.debug("Displaying all database")
236
            return
317
            return
237
318
-
 
319
        self.log.debug("Looking for '%s'" % term)
238
        if cmbvalue == 'search':
320
        if cmbvalue == 'search':
239
            for sid in sapnotes:
321
            for sid in sapnotes:
240
                if term.upper() in sapnotes[sid]['title'].upper():
322
                if term.upper() in sapnotes[sid]['title'].upper():
241
                   found[sid] = sapnotes[sid]
323
                   found[sid] = sapnotes[sid]
242
        elif cmbvalue == 'project':
324
        elif cmbvalue == 'project':
Line 246... Line 328...
246
                    for project in projects:
328
                    for project in projects:
247
                        if term.upper() in project.upper():
329
                        if term.upper() in project.upper():
248
                           found[sid] = sapnotes[sid]
330
                           found[sid] = sapnotes[sid]
249
                except: pass
331
                except: pass
250
        elif cmbvalue == 'task':
332
        elif cmbvalue == 'task':
251
            #~ self.log.debug(sapnotes)
-
 
252
            for sid in sapnotes:
333
            for sid in sapnotes:
253
                try:
334
                try:
254
                    tasks = sapnotes[sid]['tasks']
335
                    tasks = sapnotes[sid]['tasks']
255
                    for task in tasks:
336
                    for task in tasks:
256
                        if term.upper() in task.upper():
337
                        if term.upper() in task.upper():
257
                           found[sid] = sapnotes[sid]
338
                           found[sid] = sapnotes[sid]
-
 
339
                except: pass
-
 
340
        elif cmbvalue == 'title':
-
 
341
            for sid in sapnotes:
-
 
342
                try:
-
 
343
                    title = sapnotes[sid]['title']
-
 
344
                    if term.upper() in title.upper():
-
 
345
                       found[sid] = sapnotes[sid]
-
 
346
                except: pass
-
 
347
        elif cmbvalue == 'priority':
-
 
348
            for sid in sapnotes:
-
 
349
                try:
-
 
350
                    priority = sapnotes[sid]['priority']
-
 
351
                    if term.upper() in priority.upper():
-
 
352
                       found[sid] = sapnotes[sid]
258
                except: pass
353
                except: pass
259
        elif cmbvalue == 'component':
354
        elif cmbvalue == 'component':
260
            for sid in sapnotes:
355
            for sid in sapnotes:
261
                if term.upper() in sapnotes[sid]['componentkey'].upper():
356
                if term.upper() in sapnotes[sid]['componentkey'].upper():
262
                   found[sid] = sapnotes[sid]
357
                   found[sid] = sapnotes[sid]
263
                #~ if term.upper() in sapnotes[sid]['componenttxt'].upper():
-
 
264
                   #~ found[sid] = sapnotes[sid]
-
 
265
        elif cmbvalue == 'category':
358
        elif cmbvalue == 'category':
266
            for sid in sapnotes:
359
            for sid in sapnotes:
267
                if term.upper() in sapnotes[sid]['category'].upper():
360
                if term.upper() in sapnotes[sid]['category'].upper():
268
                   found[sid] = sapnotes[sid]
361
                   found[sid] = sapnotes[sid]
269
        elif cmbvalue == 'type':
362
        elif cmbvalue == 'type':
Line 276... Line 369...
276
                   found[sid] = sapnotes[sid]
369
                   found[sid] = sapnotes[sid]
277
        elif cmbvalue == 'id':
370
        elif cmbvalue == 'id':
278
            for sid in sapnotes:
371
            for sid in sapnotes:
279
                if term in sid:
372
                if term in sid:
280
                   found[sid] = sapnotes[sid]
373
                   found[sid] = sapnotes[sid]
281
        #~ elif cmbvalue == 'released':
-
 
282
            #~ for sid in sapnotes:
-
 
283
                #~ self.log.debug(sapnotes[sid]['reldate'].upper())
-
 
284
                #~ self.log.debug(sapnotes[sid]['releaseon'].upper())
-
 
285
                #~ if term.upper() in sapnotes[sid]['releaseon'].upper():
-
 
286
                   #~ found[sid] = sapnotes[sid]
-
 
287
            #~ Exact match
-
 
288
            #~ sid = "0"*(10 - len(term)) + term
-
 
289
            #~ self.log.debug("SAP Note id: %s" % sid)
-
 
290
            #~ found[sid] = sapnotes[sid]
-
 
291
        self.log.info("Term: '%s' (%d results)" % (term, len(found)))
374
        self.log.info("Term: '%s' (%d results)" % (term, len(found)))
292
        #~ if len(found) == 0:
-
 
293
            #~ found['XXXXXXXXXX'] = None
-
 
294
        self.current_notes = found
375
        self.current_notes = found
295
        self.log.debug("Current Notes: %d" % len(self.current_notes))
376
        self.log.debug("Current Notes: %d" % len(self.current_notes))
296
        sapnoteview.populate(found)
377
        sapnoteview.populate(found)
297
        #~ sapnoteview.expand()
-
 
298
        #~ self.refresh_view()
-
 
299
378
-
 
379
-
 
380
    #~ def import_notes(self, entry):
-
 
381
        #~ ntbimport = self.gui.get_widget('ntbAddSAPNotes')
-
 
382
        #~ imptype = ntbimport.get_current_page() # 0 -> Download, 1 -> Import from file
-
 
383
        #~ if imptype == 0:
-
 
384
            #~ self.import_notes_from_sapnet()
-
 
385
        #~ elif imptype == 1:
-
 
386
            #~ self.import_notes_from_file()
300
387
301
    def import_notes(self, entry):
388
    def import_notes(self, entry):
302
        ntbimport = self.gui.get_widget('ntbAddSAPNotes')
-
 
303
        imptype = ntbimport.get_current_page() # 0 -> Download, 1 -> Import from file
-
 
304
        #~ self.log.debug(imptype)
-
 
305
        if imptype == 0:
-
 
306
            self.import_notes_from_sapnet()
-
 
307
        elif imptype == 1:
-
 
308
            self.import_notes_from_file()
-
 
-
 
389
        self.import_notes_from_sapnet()
309
390
310
391
311
    def import_notes_from_file(self):
392
    def import_notes_from_file(self):
-
 
393
        db = self.get_service('DB')
312
        notebook = self.gui.get_widget('notebook')
394
        notebook = self.gui.get_widget('notebook')
313
        winroot = self.gui.get_widget('mainwinow')
-
 
314
        filechooser = self.gui.get_widget('fcwImportNotes')
-
 
315
        import_path = filechooser.get_filename()
-
 
316
        #~ self.log.debug(import_path)
-
 
317
        try:
-
 
318
            with open(import_path, 'r') as fp:
-
 
319
                bag = json.load(fp)
-
 
320
                self.sap.import_sapnotes(bag)
-
 
321
                self.log.info ("Imported %d notes from %s" % (len(bag), import_path))
-
 
-
 
395
        rootwin = self.gui.get_widget('mainwinow')
-
 
396
-
 
397
        dialog = Gtk.FileChooserDialog("Select Basico JSON file", rootwin,
-
 
398
            Gtk.FileChooserAction.OPEN,
-
 
399
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
-
 
400
                 Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
-
 
401
        response = dialog.run()
-
 
402
-
 
403
        if response == Gtk.ResponseType.OK:
-
 
404
            source = dialog.get_filename()
-
 
405
            try:
-
 
406
                with open(source, 'r') as fp:
-
 
407
                    bag = json.load(fp)
-
 
408
                    db.import_sapnotes(bag)
-
 
409
                    self.log.info ("Imported %d notes from %s" % (len(bag), source))
-
 
410
            except Exception as error:
-
 
411
                self.log.info("SAP Notes database not found. Creating a new one")
-
 
412
                self.save_notes()
322
            sapnoteview = self.gui.get_widget('sapnoteview')
413
            sapnoteview = self.gui.get_widget('sapnoteview')
323
            self.current_notes = bag
414
            self.current_notes = bag
324
            sapnoteview.populate(bag)
415
            sapnoteview.populate(bag)
325
            self.sap.save_notes()
-
 
-
 
416
            db.save_notes()
326
            self.refresh_view()
417
            self.refresh_view()
327
            switch = self.gui.get_widget('schSelectNotesAllNone')
418
            switch = self.gui.get_widget('schSelectNotesAllNone')
328
            sapnoteview.select_all_none(switch, True)
419
            sapnoteview.select_all_none(switch, True)
329
            sapnoteview.select_all_none(switch, False)
420
            sapnoteview.select_all_none(switch, False)
330
            sapnoteview.expand_all()
421
            sapnoteview.expand_all()
331
        except Exception as error:
-
 
-
 
422
        else:
332
            self.alert.show('Import', 'Nothing imported', 'error')
423
            self.alert.show('Import', 'Nothing imported', 'error')
333
            self.log.warning("SAP Notes not found")
-
 
334
-
 
335
-
 
-
 
424
            self.log.debug("Nothing imported")
-
 
425
        dialog.destroy()
336
426
337
    def import_notes_from_sapnet(self):
427
    def import_notes_from_sapnet(self):
-
 
428
        db = self.get_service('DB')
-
 
429
        driver = self.get_service('Driver')
-
 
430
338
        notebook = self.gui.get_widget('notebook')
431
        notebook = self.gui.get_widget('notebook')
339
        winroot = self.gui.get_widget('mainwinow')
432
        winroot = self.gui.get_widget('mainwinow')
340
        sapnotes = []
433
        sapnotes = []
341
        bag = set()
434
        bag = set()
342
        txtnotes = self.gui.get_widget('txtSAPNotes')
435
        txtnotes = self.gui.get_widget('txtSAPNotes')
343
        textbuffer = txtnotes.get_buffer()
436
        textbuffer = txtnotes.get_buffer()
344
        istart, iend = textbuffer.get_bounds()
437
        istart, iend = textbuffer.get_bounds()
345
        lines = textbuffer.get_text(istart, iend, False)
438
        lines = textbuffer.get_text(istart, iend, False)
346
439
347
        lines = lines.replace(',', '\n')
-
 
348
        sapnotes.extend(lines.split('\n'))
-
 
-
 
440
        lines = lines.replace(' ', ',')
-
 
441
        lines = lines.replace('\n', ',')
-
 
442
        sapnotes.extend(lines.split(','))
349
443
350
        for sapnote in sapnotes:
444
        for sapnote in sapnotes:
351
            if len(sapnote.strip()) > 0:
445
            if len(sapnote.strip()) > 0:
352
                bag.add(sapnote.strip())
446
                bag.add(sapnote.strip())
353
447
354
        self.log.debug("%d SAP Notes to be downloaded: %s" % (len(bag), ', '.join(list(bag))))
448
        self.log.debug("%d SAP Notes to be downloaded: %s" % (len(bag), ', '.join(list(bag))))
355
-
 
356
        driver = self.sap.connect()
-
 
357
        if driver is None:
-
 
358
            dialog = Gtk.MessageDialog(winroot, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Task canceled")
-
 
359
            dialog.format_secondary_text("No suitable webdriver found. Check preferences.")
-
 
360
            dialog.run()
-
 
361
            dialog.destroy()
-
 
362
449
363
        resnotes = {}
450
        resnotes = {}
364
        for sapnote in bag:
-
 
365
            rc = self.sap.download_note(sapnote, driver)
-
 
366
            resnotes[sapnote] = rc
-
 
367
        self.sap.build_stats()
-
 
368
        self.sap.logout(driver)
-
 
-
 
451
-
 
452
        self.sap.start_fetching(len(bag))
-
 
453
        dlbag = {}
-
 
454
-
 
455
        # FIXME: max_workers = 1 = Threads disabled
-
 
456
        with Executor(max_workers=1) as exe:
-
 
457
            jobs = []
-
 
458
            for sapnote in bag:
-
 
459
                job = exe.submit(self.sap.fetch, sapnote)
-
 
460
                jobs.append(job)
-
 
461
-
 
462
            for job in jobs:
-
 
463
                rc, sapnote = job.result()
-
 
464
                self.log.debug("\tRC SAP Note %s: %s" % (sapnote, rc))
-
 
465
                resnotes[sapnote] = rc
-
 
466
                time.sleep(0.1)
-
 
467
-
 
468
        driver.close()
-
 
469
        self.sap.stop_fetching()
-
 
470
        db.save_notes()
-
 
471
        db.build_stats()
369
472
370
        textbuffer.set_text("")
473
        textbuffer.set_text("")
371
        self.log.info("Task completed.")
474
        self.log.info("Task completed.")
372
        notebook.set_current_page(0)
475
        notebook.set_current_page(0)
373
        dialog = Gtk.MessageDialog(winroot, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Task completed")
476
        dialog = Gtk.MessageDialog(winroot, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Task completed")
Line 381... Line 484...
381
            else:
484
            else:
382
                ko += 1
485
                ko += 1
383
        msgrc += "Downloaded: %d\nErroneus: %d" % (ok, ko)
486
        msgrc += "Downloaded: %d\nErroneus: %d" % (ok, ko)
384
        self.alert.show('Download', msgrc, 'information')
487
        self.alert.show('Download', msgrc, 'information')
385
        dlbag = {}
488
        dlbag = {}
386
        mysapnotes = self.sap.get_notes()
-
 
-
 
489
        mysapnotes = db.get_notes()
387
        erroneus = set()
490
        erroneus = set()
388
        for sid in bag:
491
        for sid in bag:
389
            sid = "0"*(10 - len(sid)) + sid
492
            sid = "0"*(10 - len(sid)) + sid
390
            try:
493
            try:
391
                dlbag[sid] = mysapnotes[sid]
494
                dlbag[sid] = mysapnotes[sid]
392
            except Exception as error:
495
            except Exception as error:
393
                self.log.error(error)
496
                self.log.error(error)
394
                erroneus.add(sid)
497
                erroneus.add(sid)
395
        #~ self.log.error(erroneus)
-
 
-
 
498
396
        sapnoteview = self.gui.get_widget('sapnoteview')
499
        sapnoteview = self.gui.get_widget('sapnoteview')
397
        self.current_notes = dlbag
500
        self.current_notes = dlbag
-
 
501
        #~ self.refresh_view()
-
 
502
        self.refresh_and_clear_view()
398
        sapnoteview.populate(dlbag)
503
        sapnoteview.populate(dlbag)
399
        self.refresh_view()
-
 
400
        sapnoteview.expand_all()
504
        sapnoteview.expand_all()
-
 
505
        boxMenu = self.gui.get_widget('boxMenu')
-
 
506
        boxMenu.show_all()
401
507
402
508
403
    def stop_dl_notes(self, *args):
509
    def stop_dl_notes(self, *args):
404
        notebook = self.gui.get_widget('notebook')
510
        notebook = self.gui.get_widget('notebook')
405
        txtSAPNotes = self.gui.get_widget('txtSAPNotes')
511
        txtSAPNotes = self.gui.get_widget('txtSAPNotes')
406
        buffer = txtSAPNotes.get_buffer()
512
        buffer = txtSAPNotes.get_buffer()
407
        buffer.set_text("")
513
        buffer.set_text("")
408
        notebook.set_current_page(0)
514
        notebook.set_current_page(0)
409
        self.refresh_view()
515
        self.refresh_view()
410
        self.alert.show('Download', 'Action canceled by user', 'warning')
-
 
-
 
516
        #~ self.alert.show('Download', 'Action canceled by user', 'warning')
-
 
517
        boxMenu = self.gui.get_widget('boxMenu')
-
 
518
        boxMenu.show_all()
-
 
519
        self.refresh_and_clear_view()
-
 
520
-
 
521
-
 
522
    def rebuild_database(self, *args):
-
 
523
        self.log.debug("Rebuild database...")
-
 
524
-
 
525
        db = self.get_service('DB')
-
 
526
        DB_DIR = self.get_var('DB', 'local')
-
 
527
-
 
528
        #~ FSAPNOTE = DB_DIR + sid + '.xml'
-
 
529
        #~ if path is None:
-
 
530
            #~ path = DB_DIR
-
 
531
-
 
532
        files = glob.glob("%s%s*.xml" % (DB_DIR, SEP))
-
 
533
        sap = self.app.get_service('SAP')
-
 
534
        for filename in files:
-
 
535
            self.log.debug("Filename: %s" % filename)
-
 
536
            sid = basename(filename)[0:-4]
-
 
537
            self.log.debug("SAP Note Id: %s" % sid)
-
 
538
-
 
539
            valid = False
-
 
540
            if db.is_stored(sid):
-
 
541
                self.log.debug("\tSAP Note %s will be analyzed again" % sid)
-
 
542
                content = db.get_sapnote_content(sid)
-
 
543
                sapnote = sap.analyze_sapnote_metadata(sid, content)
-
 
544
                if len(sapnote) > 0:
-
 
545
                    db = self.get_service('DB')
-
 
546
                    db.add(sapnote)
-
 
547
                    db.store(sid, content)
-
 
548
                    valid = True
-
 
549
-
 
550
        self.refresh_view()
411
551
412
    def refresh_and_clear_view(self, *args):
552
    def refresh_and_clear_view(self, *args):
413
        switch = self.gui.get_widget('schSelectNotesAllNone')
553
        switch = self.gui.get_widget('schSelectNotesAllNone')
414
        sapnoteview = self.gui.get_widget('sapnoteview')
554
        sapnoteview = self.gui.get_widget('sapnoteview')
415
        self.set_search_filter_key('search')
555
        self.set_search_filter_key('search')
416
        self.set_search_term('')
556
        self.set_search_term('')
417
        self.search_notes()
557
        self.search_notes()
418
        self.refresh_view()
558
        self.refresh_view()
419
        sapnoteview.select_all_none(switch, False)
559
        sapnoteview.select_all_none(switch, False)
420
        sapnoteview.collapse()
560
        sapnoteview.collapse()
-
 
561
421
562
422
    def refresh_view(self, action=None, callback=None, view=None):
563
    def refresh_view(self, action=None, callback=None, view=None):
423
        window = self.gui.get_widget('mainwindow')
564
        window = self.gui.get_widget('mainwindow')
424
        sapnoteview = self.gui.get_widget('sapnoteview')
565
        sapnoteview = self.gui.get_widget('sapnoteview')
425
        switch = self.gui.get_widget('schExpandCollapse')
-
 
426
        active = switch.get_active()
-
 
-
 
566
        switch_expand = self.gui.get_widget('schExpandCollapse')
-
 
567
        switch_select = self.gui.get_widget('schSelectNotesAllNone')
-
 
568
        #~ active_ = switch.get_active()
-
 
569
427
        if view is not None:
570
        if view is not None:
428
            viewlabel = self.gui.get_widget('lblViewCurrent')
571
            viewlabel = self.gui.get_widget('lblViewCurrent')
429
            name = "<span size='20000'><b>%-10s</b></span>" % view.capitalize()
572
            name = "<span size='20000'><b>%-10s</b></span>" % view.capitalize()
430
            viewlabel.set_markup(name)
573
            viewlabel.set_markup(name)
431
            sapnoteview = self.gui.get_widget('sapnoteview')
-
 
432
            old_view = sapnoteview.get_view()
-
 
433
            sapnoteview.set_view(view)
-
 
434
            #~ self.log.debug("switching view from %s to %s" % (old_view, view))
-
 
435
            #~ sapnoteview.populate(self.current_notes)
-
 
436
            self.search_notes()
-
 
437
        #~ sapnoteview.expand_collapse(switch, active)
-
 
438
        sapnoteview.set_view(view)
574
        sapnoteview.set_view(view)
-
 
575
        self.search_notes()
-
 
576
        switch_expand.set_active(True)
-
 
577
        switch_expand.set_active(False)
-
 
578
        switch_select.set_active(False)
-
 
579
        switch_select.set_active(True)
-
 
580
        switch_select.set_active(False)
439
        window.show_home_page()
581
        window.show_home_page()
-
 
582
-
 
583
-
 
584
    def setup_menu_import(self):
-
 
585
        sapnoteview = self.gui.get_widget('sapnoteview')
-
 
586
        view = sapnoteview.get_view()
-
 
587
-
 
588
        ### ACTIONS POPOVER
-
 
589
        app = self.gui.get_app()
-
 
590
-
 
591
        ## Action Menu
-
 
592
        actions_menu = Gio.Menu()
-
 
593
-
 
594
        # Import submenu
-
 
595
        #~ actions_import_submenu = Gio.Menu()
-
 
596
        # Import Basico Package
-
 
597
        actions_menu.append_item(self.uif.create_item('Import Basico Package', 'app.actions-import-basico', 'document-open'))
-
 
598
        #~ app.add_action(self.uif.create_action("actions-import-basico"))
-
 
599
-
 
600
        # Import from JSON file
-
 
601
        actions_menu.append_item(self.uif.create_item('Import JSON file', 'app.actions-import-json', 'document-open'))
-
 
602
        app.add_action(self.uif.create_action("actions-import-json"))
-
 
603
-
 
604
        #~ Import from SAP Launchpad
-
 
605
        actions_menu.append_item(self.uif.create_item('Import SAP Notes from SAP Launchpad', 'app.actions-import-launchpad', 'download'))
-
 
606
        app.add_action(self.uif.create_action("actions-import-launchpad"))
-
 
607
-
 
608
        #~ actions_menu.append_submenu('Import', actions_import_submenu)
-
 
609
-
 
610
        # MnuButton valid with any modern version of Gtk (?> 3.10)
-
 
611
        btnactions = self.gui.get_widget('mnuBtnImport')
-
 
612
        btnactions.set_always_show_image(True)
-
 
613
        btnactions.set_property("use-popover", True)
-
 
614
        btnactions.set_menu_model(actions_menu)
440
615
441
616
442
    def setup_menu_actions(self):
617
    def setup_menu_actions(self):
443
        sapnoteview = self.gui.get_widget('sapnoteview')
618
        sapnoteview = self.gui.get_widget('sapnoteview')
444
        view = sapnoteview.get_view()
619
        view = sapnoteview.get_view()
445
        #~ self.log.debug("View: %s" % view)
-
 
-
 
620
446
        ### ACTIONS POPOVER
621
        ### ACTIONS POPOVER
447
        app = self.gui.get_app()
622
        app = self.gui.get_app()
448
623
449
        ## Action Menu
624
        ## Action Menu
450
        actions_menu = Gio.Menu()
625
        actions_menu = Gio.Menu()
Line 466... Line 641...
466
        actions_menu.append_item(self.uif.create_item('Manage tasks', 'app.actions-manage-tasks', 'tasks'))
641
        actions_menu.append_item(self.uif.create_item('Manage tasks', 'app.actions-manage-tasks', 'tasks'))
467
        app.add_action(self.uif.create_action("actions-manage-tasks"))
642
        app.add_action(self.uif.create_action("actions-manage-tasks"))
468
643
469
        # Export submenu
644
        # Export submenu
470
        actions_export_submenu = Gio.Menu()
645
        actions_export_submenu = Gio.Menu()
-
 
646
-
 
647
        #~ Export to JSON
-
 
648
        actions_export_submenu.append_item(self.uif.create_item('Export as JSON', 'app.actions-export-json', 'document-save'))
-
 
649
        app.add_action(self.uif.create_action("actions-export-json"))
471
        #~ Export to CSV
650
        #~ Export to CSV
472
        actions_export_submenu.append_item(self.uif.create_item('Export as CSV', 'app.actions-export-csv', 'document-save'))
651
        actions_export_submenu.append_item(self.uif.create_item('Export as CSV', 'app.actions-export-csv', 'document-save'))
473
        app.add_action(self.uif.create_action("actions-export-csv"))
652
        app.add_action(self.uif.create_action("actions-export-csv"))
474
        #~ Export to TXT
653
        #~ Export to TXT
475
        actions_export_submenu.append_item(self.uif.create_item('Export to plaint text', 'app.actions-export-txt', 'document-save'))
654
        actions_export_submenu.append_item(self.uif.create_item('Export to plaint text', 'app.actions-export-txt', 'document-save'))
476
        app.add_action(self.uif.create_action("actions-export-txt"))
655
        app.add_action(self.uif.create_action("actions-export-txt"))
477
        #~ Export to BCO
656
        #~ Export to BCO
478
        actions_export_submenu.append_item(self.uif.create_item('Export as Basico Package Object (BCO)', 'app.actions-export-bco', 'document-save'))
-
 
479
        app.add_action(self.uif.create_action("actions-export-bco"))
-
 
-
 
657
        #~ actions_export_submenu.append_item(self.uif.create_item('Export as Basico Package Object (BCO)', 'app.actions-export-bco', 'document-save'))
-
 
658
        #~ app.add_action(self.uif.create_action("actions-export-bco"))
480
        actions_menu.append_submenu('Export', actions_export_submenu)
659
        actions_menu.append_submenu('Export', actions_export_submenu)
481
        #~ actions_menu.append_section('Export', actions_export_submenu)
660
        #~ actions_menu.append_section('Export', actions_export_submenu)
482
661
483
        # Refresh SAP Notes
662
        # Refresh SAP Notes
484
        #~ actions_menu.append_item(self.uif.create_item('Refresh selected SAP Notes', 'app.actions-other-refresh', 'refresh'))
663
        #~ actions_menu.append_item(self.uif.create_item('Refresh selected SAP Notes', 'app.actions-other-refresh', 'refresh'))
Line 491... Line 670...
491
        # MnuButton valid with any modern version of Gtk (?> 3.10)
670
        # MnuButton valid with any modern version of Gtk (?> 3.10)
492
        btnactions = self.gui.get_widget('mnuBtnActions')
671
        btnactions = self.gui.get_widget('mnuBtnActions')
493
        btnactions.set_always_show_image(True)
672
        btnactions.set_always_show_image(True)
494
        btnactions.set_property("use-popover", True)
673
        btnactions.set_property("use-popover", True)
495
        btnactions.set_menu_model(actions_menu)
674
        btnactions.set_menu_model(actions_menu)
-
 
675
-
 
676
-
 
677
    def show_addsapnotes_dialog(self, *args):
-
 
678
        sapnoteview = self.gui.get_widget('sapnoteview')
-
 
679
        sapnoteview.set_view('download')
-
 
680
        notebook = self.gui.get_widget('notebook')
-
 
681
        boxMenu = self.gui.get_widget('boxMenu')
-
 
682
        boxMenu.hide()
-
 
683
        notebook.set_current_page(1)
-
 
684
-
 
685
-
 
686
    def default_preferences(self, *args):
-
 
687
        prefs = self.get_service('Settings')
-
 
688
        gui = self.get_service('GUI')
-
 
689
        settings = prefs.get_default_settings()
-
 
690
        for key in settings:
-
 
691
            widget = gui.get_widget(key)
-
 
692
            widget.set_text(str(settings[key]))
-
 
693
-
 
694
        self.config[self.section] = settings
-
 
695
        self.save_config()
-
 
696
        self.log.debug("Settings reverted to default")
496
697
497
698
498
    def apply_preferences(self, *args):
699
    def apply_preferences(self, *args):
499
        self.sap.apply_preferences()
700
        self.sap.apply_preferences()
500
        notebook = self.gui.get_widget('notebook')
701
        notebook = self.gui.get_widget('notebook')
Line 507... Line 708...
507
        statsviewer = self.gui.get_widget('scrStatsViewer')
708
        statsviewer = self.gui.get_widget('scrStatsViewer')
508
        view = WebKit.WebView()
709
        view = WebKit.WebView()
509
        chart = self.stats.build_pie_maincomp()
710
        chart = self.stats.build_pie_maincomp()
510
        view.load_string(chart, 'text/html', 'UTF-8','/')
711
        view.load_string(chart, 'text/html', 'UTF-8','/')
511
        self.gui.swap_widget(statsviewer, view)
712
        self.gui.swap_widget(statsviewer, view)
-
 
713
512
714
513
    def update_categories_stats(self, *args):
715
    def update_categories_stats(self, *args):
514
        statsviewer = self.gui.get_widget('scrStatsViewer')
716
        statsviewer = self.gui.get_widget('scrStatsViewer')
515
        view = WebKit.WebView()
717
        view = WebKit.WebView()
516
        chart = self.stats.build_pie_categories()
718
        chart = self.stats.build_pie_categories()
517
        view.load_string(chart, 'text/html', 'UTF-8','/')
719
        view.load_string(chart, 'text/html', 'UTF-8','/')
518
        self.gui.swap_widget(statsviewer, view)
720
        self.gui.swap_widget(statsviewer, view)
-
 
721
-
 
722
-
 
723
    def check_task_link_button_status(self):
-
 
724
        tasks = self.get_service('Tasks')
-
 
725
        button = self.gui.get_widget('btnLinkTasksApply')
-
 
726
        sapnoteview = self.gui.get_widget('sapnoteview')
-
 
727
-
 
728
        tasks_selected = len(tasks.get_selected()) > 0
-
 
729
        notes_selected = len(sapnoteview.get_selected_notes()) > 0
-
 
730
        if  tasks_selected and notes_selected:
-
 
731
            #~ button.set_no_show_all(False)
-
 
732
            #~ button.show_all()
-
 
733
            button.set_sensitive(True)
-
 
734
            self.log.debug("Task link button enabled")
-
 
735
        else:
-
 
736
            #~ button.hide()
-
 
737
            #~ button.set_no_show_all(True)
-
 
738
            button.set_sensitive(False)
-
 
739
            self.log.debug("Task link button disabled")
519
740
520
741
521
    def test(self, *args):
742
    def test(self, *args):
522
        self.log.debug(args)
743
        self.log.debug(args)
523
744