Subversion Repositories basico

Rev

Rev 407 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
340 t00mlabs 1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
"""
4
# File: wdg_annot.py
5
# Author: Tomás Vírseda
6
# License: GPL v3
7
# Description: Annotation Widget
8
"""
9
 
399 t00mlabs 10
import os
340 t00mlabs 11
import html
12
import gi
380 t00mlabs 13
gi.require_version('Gtk', '3.0')
342 t00mlabs 14
gi.require_version('Gdk', '3.0')
15
gi.require_version('Pango', '1.0')
16
gi.require_version('GdkPixbuf', '2.0')
17
gi.require_version('GtkSource', '3.0')
407 t00mlabs 18
from gi.repository import Gdk
340 t00mlabs 19
from gi.repository import Gtk
20
from gi.repository import Pango
21
from gi.repository.GdkPixbuf import Pixbuf
342 t00mlabs 22
from gi.repository import GtkSource
393 t00mlabs 23
from basico.core.mod_env import LPATH, ATYPES, FILE
340 t00mlabs 24
from basico.core.mod_wdg import BasicoWidget
364 t00mlabs 25
from basico.widgets.wdg_browser import BasicoBrowser
340 t00mlabs 26
 
27
 
348 t00mlabs 28
class AnnotationToolbar(BasicoWidget, Gtk.HBox):
29
    def __init__(self, app, sid='0000000000'):
30
        super().__init__(app, __class__.__name__)
31
        Gtk.Box.__init__(self)
32
        self.sid = sid
33
        self.get_services()
34
        self.set_homogeneous(False)
388 t00mlabs 35
        self.setup()
352 t00mlabs 36
 
398 t00mlabs 37
 
388 t00mlabs 38
    def setup(self):
352 t00mlabs 39
        # Toolbar
390 t00mlabs 40
        self.toolbar = Gtk.Toolbar()
41
        self.pack_start(self.toolbar, False, True, 0)
42
        self.toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
43
        self.toolbar.set_property('margin-bottom', 0)
380 t00mlabs 44
 
399 t00mlabs 45
        # Annotation icon
46
        tool = self.srvgui.add_widget('gtk_tool_annotation_icon', Gtk.ToolItem())
47
        box = self.srvgui.add_widget('gtk_box_annotation_icon', Gtk.Box())
48
        tool.add(box)
49
        self.toolbar.insert(tool, -1)
50
 
51
        # Separator
52
        tool = self.srvuif.get_toolbar_separator(False, False)
53
        self.toolbar.insert(tool, -1)
54
 
55
        # Title
56
        tool = Gtk.ToolItem()
57
        # ~ vbox = Gtk.VBox()
58
        title = self.srvgui.add_widget('gtk_label_annotation_sid', Gtk.Label())
59
        title.set_selectable(True)
60
        if self.sid == '0000000000':
61
            title.set_markup('<small><b>Annotation</b></small>')
62
        else:
63
            title.set_markup('<small><b>Annotation for SAP Note %s</b></small>' % str(int(self.sid)))
64
        title.set_xalign(0.5)
65
        tool.add(title)
66
        self.toolbar.insert(tool, -1)
67
 
348 t00mlabs 68
        # Task Category button
69
        tool = Gtk.ToolItem()
70
        a_category_model = Gtk.ListStore(Pixbuf, str)
71
        a_category = Gtk.ComboBox.new_with_model(a_category_model)
364 t00mlabs 72
        a_category.set_tooltip_markup('<b>Choose a category</b>')
348 t00mlabs 73
        self.srvgui.add_widget('gtk_combobox_annotation_category', a_category)
380 t00mlabs 74
 
348 t00mlabs 75
        renderer = Gtk.CellRendererPixbuf()
76
        a_category.pack_start(renderer, False)
77
        a_category.add_attribute(renderer, "pixbuf", 0)
78
        renderer = Gtk.CellRendererText()
79
        a_category.pack_start(renderer, True)
80
        a_category.add_attribute(renderer, "text", 1)
81
 
388 t00mlabs 82
        icon = self.srvicm.get_pixbuf_icon('basico-inbox', 18, 18)
348 t00mlabs 83
        active = self.srvgui.add_widget('annotation_category_Inbox', a_category_model.append([icon, 'Inbox']))
380 t00mlabs 84
 
388 t00mlabs 85
        icon = self.srvicm.get_pixbuf_icon('basico-drafts', 18, 18)
348 t00mlabs 86
        self.srvgui.add_widget('annotation_category_Drafts', a_category_model.append([icon, 'Drafts']))
87
 
388 t00mlabs 88
        icon = self.srvicm.get_pixbuf_icon('basico-archived', 18, 18)
348 t00mlabs 89
        self.srvgui.add_widget('annotation_category_Archived', a_category_model.append([icon, 'Archived']))
380 t00mlabs 90
 
348 t00mlabs 91
        a_category.set_active_iter(active)
350 t00mlabs 92
        hbox = Gtk.HBox()
93
        hbox.pack_start(a_category, False, False, 0)
94
        tool.add(hbox)
390 t00mlabs 95
        self.toolbar.insert(tool, -1)
348 t00mlabs 96
 
350 t00mlabs 97
        # Separator
364 t00mlabs 98
        tool = self.srvuif.get_toolbar_separator(False, False)
390 t00mlabs 99
        self.toolbar.insert(tool, -1)
350 t00mlabs 100
 
364 t00mlabs 101
        # Annotation Type button
348 t00mlabs 102
        tool = Gtk.ToolItem()
103
        a_type_model = Gtk.ListStore(Pixbuf, str)
104
        a_type = Gtk.ComboBox.new_with_model(a_type_model)
364 t00mlabs 105
        a_type.set_tooltip_markup('<b>Choose a type</b>')
348 t00mlabs 106
        self.srvgui.add_widget('gtk_combobox_annotation_type', a_type)
107
        renderer = Gtk.CellRendererPixbuf()
108
        a_type.pack_start(renderer, False)
109
        a_type.add_attribute(renderer, "pixbuf", 0)
110
        renderer = Gtk.CellRendererText()
111
        a_type.pack_start(renderer, True)
112
        a_type.add_attribute(renderer, "text", 1)
113
        for item in ATYPES:
388 t00mlabs 114
            icon = self.srvicm.get_pixbuf_icon('basico-annotation-type-%s' % item.lower(), 18, 18)
348 t00mlabs 115
            active = self.srvgui.add_widget('annotation_type_%s' % item.title(), a_type_model.append([icon, '%s' % item.title()]))
116
        a_type.set_active_iter(active)
350 t00mlabs 117
        hbox = Gtk.HBox()
118
        hbox.pack_start(a_type, False, False, 0)
119
        tool.add(hbox)
390 t00mlabs 120
        self.toolbar.insert(tool, -1)
348 t00mlabs 121
 
350 t00mlabs 122
        # Separator
364 t00mlabs 123
        tool = self.srvuif.get_toolbar_separator(False, False)
390 t00mlabs 124
        self.toolbar.insert(tool, -1)
350 t00mlabs 125
 
348 t00mlabs 126
        # Task Priority button
127
        tool = Gtk.ToolItem()
128
        a_priority_model = Gtk.ListStore(Pixbuf, str)
129
        a_priority = Gtk.ComboBox.new_with_model(a_priority_model)
364 t00mlabs 130
        a_priority.set_tooltip_markup('<b>Choose a priority</b>')
348 t00mlabs 131
        self.srvgui.add_widget('gtk_combobox_annotation_priority', a_priority)
380 t00mlabs 132
 
348 t00mlabs 133
        renderer = Gtk.CellRendererPixbuf()
134
        a_priority.pack_start(renderer, False)
135
        a_priority.add_attribute(renderer, "pixbuf", 0)
380 t00mlabs 136
 
348 t00mlabs 137
        renderer = Gtk.CellRendererText()
138
        a_priority.pack_start(renderer, True)
139
        a_priority.add_attribute(renderer, "text", 1)
140
 
388 t00mlabs 141
        icon = self.srvicm.get_pixbuf_icon('basico-annotation-priority-high', 18, 18)
348 t00mlabs 142
        self.srvgui.add_widget('annotation_priority_High', a_priority_model.append([icon, 'High']))
143
 
388 t00mlabs 144
        icon = self.srvicm.get_pixbuf_icon('basico-annotation-priority-normal', 18, 18)
348 t00mlabs 145
        active = self.srvgui.add_widget('annotation_priority_Normal', a_priority_model.append([icon, 'Normal']))
146
 
388 t00mlabs 147
        icon = self.srvicm.get_pixbuf_icon('basico-annotation-priority-low', 18, 18)
348 t00mlabs 148
        self.srvgui.add_widget('annotation_priority_Low', a_priority_model.append([icon, 'Low']))
380 t00mlabs 149
 
348 t00mlabs 150
        a_priority.set_active_iter(active)
350 t00mlabs 151
        hbox = Gtk.HBox()
152
        hbox.pack_start(a_priority, False, False, 0)
153
        tool.add(hbox)
390 t00mlabs 154
        self.toolbar.insert(tool, -1)
380 t00mlabs 155
 
348 t00mlabs 156
        # Separator
364 t00mlabs 157
        tool = self.srvuif.get_toolbar_separator(False, False)
390 t00mlabs 158
        self.toolbar.insert(tool, -1)
353 t00mlabs 159
 
398 t00mlabs 160
        # Is template?
161
        hbox = Gtk.HBox()
162
        tool = Gtk.ToolItem()
399 t00mlabs 163
        icon = self.srvicm.get_new_image_icon('basico-annotation-type-template', 18, 18)
398 t00mlabs 164
        switch = self.srvgui.add_widget('gtk_switch_annotation_template', Gtk.ToggleButton())
402 t00mlabs 165
        switch.set_tooltip_markup('<b>Toggle to mark this annotation as a template</b>')
398 t00mlabs 166
        # ~ switch.connect('state-set', callback)
167
        label = Gtk.Label()
168
        label.set_markup('<b>Template?</b>')
169
        hbox.pack_start(icon, False, False, 3)
402 t00mlabs 170
        # ~ hbox.pack_start(label, False, False, 3)
398 t00mlabs 171
        switch.add(hbox)
172
        tool.add(switch)
173
        self.toolbar.insert(tool, -1)
174
 
175
        # Separator
176
        tool = self.srvuif.get_toolbar_separator(False, False)
177
        self.toolbar.insert(tool, -1)
178
 
353 t00mlabs 179
        # Attachment button
367 t00mlabs 180
        tool = self.srvgui.add_widget('gtk_button_annotation_toolbar_attachment', Gtk.ToolButton())
364 t00mlabs 181
        tool.set_tooltip_markup('<b>Attach file(s) to this annotation</b>')
353 t00mlabs 182
        tool.set_icon_name('basico-attachment')
367 t00mlabs 183
        # ~ popover = self.srvgui.add_widget('gtk_button_annotation_toolbar_attachment', Gtk.Popover.new(tool))
360 t00mlabs 184
        tool.connect('clicked', self.srvclb.gui_attachment_add_to_annotation)
390 t00mlabs 185
        self.toolbar.insert(tool, -1)
353 t00mlabs 186
 
187
        # Separator
364 t00mlabs 188
        tool = self.srvuif.get_toolbar_separator(False, True)
390 t00mlabs 189
        self.toolbar.insert(tool, -1)
380 t00mlabs 190
 
351 t00mlabs 191
        # Timestamp created
192
        tool = Gtk.ToolItem()
193
        tool.set_expand(False)
194
        a_wdg_timestamp_created = self.srvgui.add_widget('gtk_label_timestamp_created', Gtk.Label())
195
        a_wdg_timestamp_created.modify_font(Pango.FontDescription('Monospace 10'))
196
        a_wdg_timestamp_created.set_xalign(0.5)
197
        tool.add(a_wdg_timestamp_created)
198
        tool.set_no_show_all(True)
199
        tool.hide()
390 t00mlabs 200
        self.toolbar.insert(tool, -1)
380 t00mlabs 201
 
351 t00mlabs 202
        # Timestamp updated
203
        tool = Gtk.ToolItem()
204
        tool.set_expand(False)
348 t00mlabs 205
        a_wdg_human_timestamp = self.srvgui.add_widget('gtk_label_human_timestamp', Gtk.Label())
206
        a_wdg_human_timestamp.modify_font(Pango.FontDescription('Monospace 10'))
207
        a_wdg_human_timestamp.set_xalign(0.5)
208
        tool.add(a_wdg_human_timestamp)
364 t00mlabs 209
        tool.set_no_show_all(True)
210
        tool.hide()
390 t00mlabs 211
        self.toolbar.insert(tool, -1)
364 t00mlabs 212
 
213
        # Annotation Stack Switcher
214
        tool = Gtk.ToolItem()
399 t00mlabs 215
        tool.set_is_important(True)
216
        tool.set_visible_vertical(True)
217
        tool.set_visible_horizontal(True)
364 t00mlabs 218
        stack_switcher = self.srvgui.add_widget('stack_switcher_annotation', Gtk.StackSwitcher())
219
        stack_switcher.set_property('icon-size', 3)
220
        stack = self.srvgui.add_widget('stack_annotation', Gtk.Stack())
221
        stack_switcher.set_stack(stack)
222
        tool.add(stack_switcher)
390 t00mlabs 223
        self.toolbar.insert(tool, -1)
364 t00mlabs 224
 
225
        # Separator
226
        tool = self.srvuif.get_toolbar_separator(False, False)
390 t00mlabs 227
        self.toolbar.insert(tool, -1)
367 t00mlabs 228
 
229
        # Arrow UP
230
        tool = self.srvgui.add_widget('gtk_button_annotation_toolbar_previous_item', Gtk.ToolButton())
407 t00mlabs 231
        # ~ icon = self.srvicm.get_new_image_icon('basico-arrow-up')
232
        # ~ tool.add(icon)
233
        # ~ tool.set_expand(False)
234
        # ~ tool.set_visible_horizontal(True)
235
        # ~ tool.set_visible_vertical(True)
236
        # ~ tool.set_is_important(True)
367 t00mlabs 237
        tool.set_tooltip_markup('<b>Previous annotation</b>')
238
        tool.set_icon_name('basico-arrow-up')
239
        tool.connect('clicked', self.srvclb.gui_annotation_previous_row)
390 t00mlabs 240
        self.toolbar.insert(tool, -1)
367 t00mlabs 241
 
242
        # Arrow DOWN
243
        tool = self.srvgui.add_widget('gtk_button_annotation_toolbar_next_item', Gtk.ToolButton())
407 t00mlabs 244
        # ~ icon = self.srvicm.get_new_image_icon('basico-arrow-down')
245
        # ~ tool.add(icon)
246
        # ~ tool.set_visible_vertical(True)
247
        # ~ tool.set_visible_horizontal(True)
248
        # ~ tool.set_is_important(True)
249
        # ~ tool.set_expand(False)
367 t00mlabs 250
        tool.set_tooltip_markup('<b>Next annotation</b>')
251
        tool.set_icon_name('basico-arrow-down')
252
        tool.connect('clicked', self.srvclb.gui_annotation_next_row)
390 t00mlabs 253
        self.toolbar.insert(tool, -1)
367 t00mlabs 254
 
407 t00mlabs 255
        # ~ # Separator
256
        # ~ tool = self.srvuif.get_toolbar_separator(False, False)
257
        # ~ self.toolbar.insert(tool, -1)
380 t00mlabs 258
 
348 t00mlabs 259
        # Toolbar initial settings
260
        self.set_visible(True)
261
        self.set_no_show_all(False)
390 t00mlabs 262
        self.toolbar.set_hexpand(True)
348 t00mlabs 263
 
264
 
265
    def get_services(self):
266
        self.srvgui = self.get_service("GUI")
267
        self.srvclb = self.get_service('Callbacks')
268
        self.srvsap = self.get_service('SAP')
269
        self.srvicm = self.get_service('IM')
270
        self.srvstg = self.get_service('Settings')
271
        self.srvdtb = self.get_service('DB')
272
        self.srvuif = self.get_service("UIF")
388 t00mlabs 273
        self.srvclt = self.get_service('Collections')
348 t00mlabs 274
 
275
 
276
 
340 t00mlabs 277
class AnnotationWidget(BasicoWidget, Gtk.VBox):
278
    """
279
    Annotation Widget
280
    """
281
    def __init__(self, app, sid='0000000000'):
282
        super().__init__(app, __class__.__name__)
283
        Gtk.VBox.__init__(self)
284
        self.app = app
285
        self.sid = sid
286
        self.get_services()
287
        self.__setup()
288
 
380 t00mlabs 289
 
340 t00mlabs 290
    def get_services(self):
291
        """Load services to be used in this class
292
        """
293
        self.srvgui = self.get_service("GUI")
294
        self.srvicm = self.get_service("IM")
295
        self.srvuif = self.get_service("UIF")
296
        self.srvclt = self.get_service('Collections')
297
        self.srvclb = self.get_service('Callbacks')
298
        self.srvant = self.get_service('Annotation')
299
        self.srvutl = self.get_service('Utils')
365 t00mlabs 300
        self.srvacd = self.get_service('Asciidoctor')
340 t00mlabs 301
 
380 t00mlabs 302
 
340 t00mlabs 303
    def __setup(self):
304
        # Setup Widget properties
305
        self.set_property('margin-left', 3)
306
        self.set_property('margin-right', 3)
307
        self.set_hexpand(True)
308
        self.set_vexpand(True)
309
 
310
        # Annotation container (body)
311
        self.container_body = self.srvgui.add_widget('gtk_vbox_annotation_container', Gtk.VBox())
312
        self.container_body.set_border_width(3)
313
        self.pack_start(self.container_body, True, True, 3)
314
 
315
        self.__setup_header()
316
        self.__setup_body()
317
        self.__setup_footer()
407 t00mlabs 318
        self.connect("key-press-event",self.on_key_press_event)
340 t00mlabs 319
 
320
 
407 t00mlabs 321
    def on_key_press_event(self, widget, event):
322
        if Gdk.keyval_name(event.keyval) == 'Escape':
323
            self.srvclb.action_annotation_cancel()
324
 
340 t00mlabs 325
    def __setup_header(self):
326
        # Annotation Header
327
        container = self.srvgui.get_widget('gtk_vbox_annotation_container')
328
        header = Gtk.VBox()
364 t00mlabs 329
 
330
        # Editor's toolbar
348 t00mlabs 331
        toolbar = AnnotationToolbar(self.app, self.sid)
332
        header.pack_start(toolbar, False, False, 0)
340 t00mlabs 333
        hbox = Gtk.HBox()
334
        a_lbl_aid = Gtk.Label()
335
        a_lbl_aid.set_property('xalign', 1.0)
336
        a_lbl_aid.modify_font(Pango.FontDescription('Monospace 10'))
337
        a_lbl_aid.set_markup('<b>Annotation Id:</b>')
338
        a_aid = self.srvgui.add_widget('gtk_label_aid', Gtk.Label())
339
        a_aid.set_property('xalign', 1.0)
340
        a_aid.set_selectable(True)
341
        a_aid.modify_font(Pango.FontDescription('Monospace 10'))
342
        separator = Gtk.Separator()
343
        hbox.pack_start(a_lbl_aid, False, False, 0)
344
        hbox.pack_start(a_aid, False, False, 0)
348 t00mlabs 345
        hbox.set_no_show_all(True)
346
        hbox.hide()
347
        # ~ header.pack_start(hbox, False, False, 0)
348
        # ~ header.pack_start(a_wdg_human_timestamp, True, True, 0)
346 t00mlabs 349
        # ~ header.pack_start(separator, False, False, 3)
340 t00mlabs 350
        header.show_all()
351
        container.pack_start(header, False, False, 0)
352
 
353
 
354
    def __setup_body(self):
364 t00mlabs 355
        stack_switcher = self.srvgui.get_widget('stack_switcher_annotation')
356
        stack_annotation = self.srvgui.get_widget('stack_annotation')
357
        stack_annotation.connect('notify::visible-child', self.stack_changed)
358
        self.container_body.add(stack_annotation)
359
 
366 t00mlabs 360
        # Add Annotation preview stack
394 t00mlabs 361
        preview = self.widget_annotation_preview()
366 t00mlabs 362
        stack_annotation.add_titled(preview, "preview", "Preview annotation")
363
        stack_annotation.child_set_property (preview, "icon-name", "basico-preview")
380 t00mlabs 364
 
364 t00mlabs 365
        # Add Annotation editor stack
394 t00mlabs 366
        editor = self.widget_annotation_editor()
364 t00mlabs 367
        stack_annotation.add_titled(editor, "editor", "Edit annotation")
368
        stack_annotation.child_set_property (editor, "icon-name", "basico-drafts")
369
 
367 t00mlabs 370
        # Add Annotation properties stack
390 t00mlabs 371
        # ~ properties = self.annotation_properties()
372
        # ~ stack_annotation.add_titled(properties, "properties", "Edit properties")
373
        # ~ stack_annotation.child_set_property (properties, "icon-name", "basico-tags")
380 t00mlabs 374
 
375
 
376
 
394 t00mlabs 377
    def set_visible_stack(self, stack_name='editor'):
380 t00mlabs 378
        self.srvuif.set_widget_visibility('stack_annotation', True)
367 t00mlabs 379
        stack = self.srvgui.get_widget('stack_annotation')
380 t00mlabs 380
        stack.set_visible_child_name(stack_name)
364 t00mlabs 381
        if stack_name == 'preview':
365 t00mlabs 382
            self.preview()
367 t00mlabs 383
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_category', False)
384
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_type', False)
380 t00mlabs 385
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_priority', False)
386
            self.srvuif.set_widget_visibility('gtk_button_annotation_toolbar_attachment', False)
390 t00mlabs 387
            self.srvuif.set_widget_visibility('gtk_entry_annotation_scope', False)
399 t00mlabs 388
            self.srvuif.set_widget_visibility('gtk_switch_annotation_template', False)
407 t00mlabs 389
            self.srvuif.set_widget_visibility('annotation_footer_buttons', False)
399 t00mlabs 390
            self.srvuif.set_widget_visibility('gtk_label_annotation_sid', True)
367 t00mlabs 391
        elif stack_name == 'properties':
392
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_category', False)
393
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_type', False)
394
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_priority', False)
380 t00mlabs 395
            self.srvuif.set_widget_visibility('gtk_button_annotation_toolbar_attachment', False)
390 t00mlabs 396
            self.srvuif.set_widget_visibility('gtk_entry_annotation_scope', False)
399 t00mlabs 397
            self.srvuif.set_widget_visibility('gtk_switch_annotation_template', False)
407 t00mlabs 398
            self.srvuif.set_widget_visibility('annotation_footer_buttons', False)
399 t00mlabs 399
            self.srvuif.set_widget_visibility('gtk_label_annotation_sid', False)
367 t00mlabs 400
        elif stack_name == 'editor':
401
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_category', True)
402
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_type', True)
403
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_priority', True)
404
            self.srvuif.set_widget_visibility('gtk_button_annotation_toolbar_attachment', True)
390 t00mlabs 405
            self.srvuif.set_widget_visibility('gtk_entry_annotation_scope', True)
399 t00mlabs 406
            self.srvuif.set_widget_visibility('gtk_switch_annotation_template', True)
407 t00mlabs 407
            self.srvuif.set_widget_visibility('annotation_footer_buttons', True)
399 t00mlabs 408
            self.srvuif.set_widget_visibility('gtk_label_annotation_sid', False)
364 t00mlabs 409
 
380 t00mlabs 410
 
394 t00mlabs 411
    def widget_annotation_preview(self):
364 t00mlabs 412
        browser = self.srvgui.add_widget('annotation_browser', BasicoBrowser(self.app))
413
        return browser
414
 
394 t00mlabs 415
 
416
    def widget_annotation_properties(self):
367 t00mlabs 417
        properties = self.srvgui.add_widget('annotation_properties', Gtk.Label('Properties'))
418
        return properties
419
 
380 t00mlabs 420
 
394 t00mlabs 421
    def widget_annotation_editor(self):
340 t00mlabs 422
        vbox = Gtk.VBox()
423
 
424
        # Hidden metadata
425
        hhbox = Gtk.HBox()
426
 
427
        a_timestamp = self.srvgui.add_widget('gtk_label_timestamp', Gtk.Label(self.srvutl.timestamp()))
428
        a_timestamp.set_sensitive(False)
429
        self.srvuif.set_widget_visibility('gtk_label_timestamp', False)
430
        hhbox.pack_start(a_timestamp, False, False, 0)
431
        vbox.pack_start(hhbox, False, False, 0)
432
 
433
 
434
        # Main hbox
435
        mhbox = Gtk.HBox()
436
 
437
        vboxl = Gtk.VBox()
438
        vboxl.set_vexpand(True)
439
        vboxr = Gtk.VBox()
440
        vboxr.set_vexpand(True)
441
 
442
        # Title
443
        a_title = self.srvgui.add_widget('gtk_entry_annotation_title', Gtk.Entry())
444
        a_title.set_placeholder_text("Type a title here...")
445
        a_title.modify_font(Pango.FontDescription('Monospace 10'))
446
        vboxl.pack_start(a_title, False, False, 0)
447
 
448
        # Text
449
        scroller = Gtk.ScrolledWindow()
393 t00mlabs 450
        scroller.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
340 t00mlabs 451
        scroller.set_shadow_type(Gtk.ShadowType.IN)
452
        scroller.set_hexpand(True)
380 t00mlabs 453
        scroller.set_vexpand(True)
342 t00mlabs 454
        a_text = self.srvgui.add_widget('gtk_textview_annotation_text', GtkSource.View.new_with_buffer(GtkSource.Buffer()))
340 t00mlabs 455
        a_text.set_wrap_mode(Gtk.WrapMode.WORD)
456
        a_text.modify_font(Pango.FontDescription('Monospace 10'))
457
        a_text.set_vexpand(True)
458
        a_text.set_left_margin(6)
459
        a_text.set_top_margin(6)
460
        a_text.set_right_margin(6)
461
        a_text.set_bottom_margin(6)
342 t00mlabs 462
        a_text.set_show_line_marks(True)
463
        a_text.set_show_line_numbers(True)
464
        a_text.set_highlight_current_line(True)
465
        a_textbuffer = a_text.get_buffer()
340 t00mlabs 466
        a_textbuffer.set_text('')
467
        scroller.add(a_text)
468
        vboxl.pack_start(scroller, True, True, 3)
469
 
393 t00mlabs 470
        # Scope entry
471
        hbox_scope = Gtk.HBox()
472
        completion = Gtk.EntryCompletion()
473
        completion.set_match_func(self.completion_match_func)
474
        completion_model = Gtk.ListStore(str)
475
        completion.set_model(completion_model)
476
        completion.set_text_column(0)
477
        completion.set_inline_completion(True)
478
        completion.set_inline_selection(True)
479
        scope = self.srvgui.add_widget('gtk_entry_annotation_scope', Gtk.Entry())
480
        scope.set_completion(completion)
481
        scope.connect('activate', self.scope_activated)
482
 
483
        max_width = 0
484
        for title in self.srvclt.get_collections_name():
485
            if len(title) > max_width:
486
                max_width = len(title)
487
            completion_model.append([title])
488
 
489
        scope.set_width_chars(max_width)
490
        scope.set_placeholder_text('Scope')
491
 
492
        ## Separator
493
        separator = Gtk.SeparatorToolItem.new()
494
        separator.set_draw(False)
495
        separator.set_expand(False)
496
 
497
        hbox_scope.pack_start(scope, False, False, 0)
498
        hbox_scope.pack_start(separator, True, True, 0)
499
 
500
 
501
        # SAP Products entry
502
        hbox_product = Gtk.HBox()
503
        completion = Gtk.EntryCompletion()
504
        completion.set_match_func(self.completion_match_func)
505
        completion_model = Gtk.ListStore(str)
506
        completion.set_model(completion_model)
507
        completion.set_text_column(0)
508
        completion.set_inline_completion(True)
509
        completion.set_inline_selection(True)
510
        product = self.srvgui.add_widget('gtk_entry_annotation_product', Gtk.Entry())
511
        product.set_completion(completion)
512
        product.connect('activate', self.product_activated)
513
 
514
        lproducts = open(FILE['L_SAP_PRODUCTS'], 'r').readlines()
515
        max_width = 0
516
        for title in lproducts:
517
            if len(title) > max_width:
518
                max_width = len(title)
519
            completion_model.append([title.strip()])
520
 
521
        product.set_width_chars(max_width)
522
        product.set_placeholder_text('Product')
523
 
524
        ## Separator
525
        separator = Gtk.SeparatorToolItem.new()
526
        separator.set_draw(False)
527
        separator.set_expand(True)
528
 
529
        hbox_product.pack_start(product, False, False, 0)
530
        hbox_product.pack_start(separator, True, True, 0)
531
        vboxl.pack_start(hbox_scope, False, False, 3)
532
        vboxl.pack_start(hbox_product, False, False, 3)
533
        # ~ hbox_scope.pack_start(vbox_product, False, False, 0)
534
        # ~ vboxl.pack_start(hbox_scope, True, True, 3)
535
 
536
        # Tags entry
537
 
340 t00mlabs 538
        # Url
393 t00mlabs 539
        hbox_url = Gtk.HBox()
340 t00mlabs 540
 
541
        ## url entry
542
        a_link = self.srvgui.add_widget('gtk_entry_annotation_link', Gtk.Entry())
393 t00mlabs 543
        a_link.set_width_chars(80)
340 t00mlabs 544
        a_link.set_placeholder_text("Type a url here...")
393 t00mlabs 545
        hbox_url.pack_start(a_link, False, False, 0)
340 t00mlabs 546
 
547
        ## url button
548
        a_link_button = self.srvgui.add_widget('gtk_link_button_annotation_link', Gtk.LinkButton())
549
        a_link_button.set_relief(Gtk.ReliefStyle.NORMAL)
550
        a_link_button.set_label('Visit')
393 t00mlabs 551
        hbox_url.pack_start(a_link_button, False, False, 0)
340 t00mlabs 552
 
553
        # url type
554
        a_link_type_model = Gtk.ListStore(str)
555
        self.srvgui.add_widget('annotation_link_type_Intranet', a_link_type_model.append(['Intranet']))
556
        self.srvgui.add_widget('annotation_link_type_SAP Blog', a_link_type_model.append(['SAP Blog']))
557
        self.srvgui.add_widget('annotation_link_type_SAP Document', a_link_type_model.append(['SAP Document']))
558
        self.srvgui.add_widget('annotation_link_type_SAP Help', a_link_type_model.append(['SAP Help']))
559
        self.srvgui.add_widget('annotation_link_type_SAP Incident', a_link_type_model.append(['SAP Incident']))
560
        self.srvgui.add_widget('annotation_link_type_SAP Questions and Answers', a_link_type_model.append(['SAP Questions and Answers']))
561
        self.srvgui.add_widget('annotation_link_type_SAP Wiki', a_link_type_model.append(['SAP Wiki']))
562
        active = self.srvgui.add_widget('annotation_link_type_Website', a_link_type_model.append(['Website']))
563
        a_link_type = Gtk.ComboBox.new_with_model(a_link_type_model)
564
        a_link_type.set_active_iter(active)
565
        self.srvgui.add_widget('gtk_combobox_annotation_link_type', a_link_type)
566
        renderer_text = Gtk.CellRendererText()
567
        a_link_type.pack_start(renderer_text, True)
568
        a_link_type.add_attribute(renderer_text, "text", 0)
393 t00mlabs 569
        hbox_url.pack_start(a_link_type, False, False, 0)
570
        vboxl.pack_start(hbox_url, False, False, 3)
340 t00mlabs 571
 
393 t00mlabs 572
        mhbox.pack_start(vboxl, True, True, 0)
340 t00mlabs 573
        mhbox.pack_start(vboxr, False, False, 0)
393 t00mlabs 574
        vbox.pack_start(mhbox, True, True, 0)
364 t00mlabs 575
        return vbox
340 t00mlabs 576
 
577
 
380 t00mlabs 578
 
340 t00mlabs 579
    def __setup_footer(self):
580
        # Buttons Accept/Cancel
581
        hbox = Gtk.HBox()
407 t00mlabs 582
        self.srvgui.add_widget('annotation_footer_buttons', hbox)
340 t00mlabs 583
        accept = self.srvgui.add_widget('gtk_button_accept_annotation', Gtk.Button('Accept'))
584
        accept.connect('clicked', self.srvclb.action_annotation_accept, self.sid)
585
        accept.set_property('always-show-image', True)
586
        icon = self.srvicm.get_new_image_icon('basico-check-accept', 24, 24)
587
        accept.set_image(icon)
588
        cancel = self.srvgui.add_widget('gtk_button_cancel_annotation', Gtk.Button('Cancel'))
589
        cancel.connect('clicked', self.srvclb.action_annotation_cancel)
590
        cancel.set_property('always-show-image', True)
591
        icon = self.srvicm.get_new_image_icon('basico-check-cancel', 24, 24)
592
        cancel.set_image(icon)
593
        hbox.pack_start(accept, True, False, 3)
594
        hbox.pack_start(cancel, True, False, 3)
595
        self.pack_start(hbox, False, False, 3)
596
 
597
 
598
    def set_aid_to_widget(self, aid):
599
        """
600
        C:237, 4: Missing method docstring (missing-docstring)
601
        """
602
        a_aid = self.srvgui.get_widget('gtk_label_aid')
603
        a_aid.set_text(aid)
604
 
605
 
606
    def get_aid_from_widget(self):
607
        """
608
        C:237, 4: Missing method docstring (missing-docstring)
609
        """
610
        a_aid = self.srvgui.get_widget('gtk_label_aid')
611
        return a_aid.get_text()
612
 
613
 
365 t00mlabs 614
 
361 t00mlabs 615
    def set_metadata_to_widget(self, aid, action='edit'):
340 t00mlabs 616
        """
617
        C:237, 4: Missing method docstring (missing-docstring)
618
        """
619
        self.set_aid_to_widget(aid)
620
        sid = self.srvant.get_sid(aid)
621
        title = self.srvgui.get_widget('gtk_label_annotation_sid')
399 t00mlabs 622
        # ~ if sid == '0000000000':
623
            # ~ title.set_markup('<big><b>Annotation</b></big>')
624
 
625
        # ~ else:
626
            # ~ title.set_markup('<big><b>Annotation for SAP Note %s</b></big>' % str(int(sid)))
627
 
628
 
629
        if action == 'create':
340 t00mlabs 630
            self.srvuif.statusbar_msg("Creating new annotation")
399 t00mlabs 631
        elif action == 'edit' or action == 'preview':
340 t00mlabs 632
            self.srvuif.statusbar_msg("Creating/Editing new annotation for SAP Note %s" % str(int(sid)))
351 t00mlabs 633
            annotation = self.srvant.get_metadata_from_aid(aid)
340 t00mlabs 634
            if annotation is not None:
635
                ANNOTATION_FILE_CONTENT = LPATH['ANNOTATIONS'] + aid + '.adoc'
399 t00mlabs 636
                a_wdg_icon = self.srvgui.get_widget('gtk_box_annotation_icon')
340 t00mlabs 637
                a_wdg_aid = self.srvgui.get_widget('gtk_label_aid')
638
                a_wdg_timestamp = self.srvgui.get_widget('gtk_label_timestamp')
408 t00mlabs 639
                # ~ a_wdg_timestamp_created = self.srvgui.get_widget('gtk_label_timestamp_created')
340 t00mlabs 640
                a_wdg_title = self.srvgui.get_widget('gtk_entry_annotation_title')
641
                a_wdg_type = self.srvgui.get_widget('gtk_combobox_annotation_type')
642
                a_wdg_category = self.srvgui.get_widget('gtk_combobox_annotation_category')
643
                a_wdg_priority = self.srvgui.get_widget('gtk_combobox_annotation_priority')
389 t00mlabs 644
                a_wdg_scope = self.srvgui.get_widget('gtk_entry_annotation_scope')
394 t00mlabs 645
                a_wdg_product = self.srvgui.get_widget('gtk_entry_annotation_product')
340 t00mlabs 646
                a_wdg_human_timestamp = self.srvgui.get_widget('gtk_label_human_timestamp')
351 t00mlabs 647
                a_wdg_timestamp_created = self.srvgui.get_widget('gtk_label_timestamp_created')
340 t00mlabs 648
                a_wdg_text = self.srvgui.get_widget('gtk_textview_annotation_text')
649
                a_wdg_link = self.srvgui.get_widget('gtk_entry_annotation_link')
650
                a_wdg_link_button = self.srvgui.get_widget('gtk_link_button_annotation_link')
651
                a_wdg_link_type = self.srvgui.get_widget('gtk_combobox_annotation_link_type')
652
 
402 t00mlabs 653
                title.set_markup("<big><b>%s - </b>%s</big>" % (annotation['Type'], annotation['Title']))
340 t00mlabs 654
                a_wdg_aid.set_text(annotation['AID'])
399 t00mlabs 655
                icon = self.srvicm.get_new_image_icon('basico-annotation-type-%s' % annotation['Type'].lower())
656
                self.srvgui.swap_widget(a_wdg_icon, icon)
340 t00mlabs 657
                a_wdg_timestamp.set_text(annotation['Timestamp'])
658
                a_wdg_title.set_text(html.escape(annotation['Title']))
380 t00mlabs 659
 
340 t00mlabs 660
                a_wdg_type.set_active_iter(self.srvgui.get_widget('annotation_type_%s' % annotation['Type']))
380 t00mlabs 661
 
340 t00mlabs 662
                try:
663
                    a_wdg_category.set_active_iter(self.srvgui.get_widget('annotation_category_%s' % annotation['Category']))
664
                except:
665
                    a_wdg_category.set_active_iter(self.srvgui.get_widget('annotation_category_Inbox'))
666
 
667
                try:
668
                    a_wdg_priority.set_active_iter(self.srvgui.get_widget('annotation_priority_%s' % annotation['Priority']))
669
                except:
670
                    a_wdg_priority.set_active_iter(self.srvgui.get_widget('annotation_priority_Normal'))
380 t00mlabs 671
 
389 t00mlabs 672
                try:
673
                    a_wdg_scope.set_text(annotation['Scope'])
674
                except:
675
                    a_wdg_scope.set_text('')
388 t00mlabs 676
 
394 t00mlabs 677
                try:
678
                    a_wdg_product.set_text(annotation['Product'])
679
                except:
680
                    a_wdg_product.set_text('')
681
 
340 t00mlabs 682
                self.srvuif.set_textview_text(a_wdg_text, open(ANNOTATION_FILE_CONTENT).read())
683
                a_wdg_link.set_text(annotation['Link'])
684
                a_wdg_link_button.set_uri(annotation['Link'])
685
                a_wdg_link_type.set_active_iter(self.srvgui.get_widget('annotation_link_type_%s' % annotation['LinkType']))
686
                human_timestamp = self.srvutl.get_human_date_from_timestamp(annotation['Timestamp'])
348 t00mlabs 687
                a_wdg_human_timestamp.set_markup('<b>%s</b>' % human_timestamp)
351 t00mlabs 688
                a_wdg_timestamp_created.set_text(annotation['Created'])
340 t00mlabs 689
 
690
 
691
    def get_metadata_from_widget(self):
692
        """
380 t00mlabs 693
        C:237, 4: Missing method docstring (missing-docstring)
340 t00mlabs 694
        """
695
        annotation = {}
696
        a_wdg_aid = self.srvgui.get_widget('gtk_label_aid')
697
        a_wdg_timestamp = self.srvgui.get_widget('gtk_label_timestamp')
351 t00mlabs 698
        a_wdg_timestamp_created = self.srvgui.get_widget('gtk_label_timestamp_created')
340 t00mlabs 699
        a_wdg_title = self.srvgui.get_widget('gtk_entry_annotation_title')
700
        a_wdg_type = self.srvgui.get_widget('gtk_combobox_annotation_type')
701
        a_wdg_category = self.srvgui.get_widget('gtk_combobox_annotation_category')
702
        a_wdg_priority = self.srvgui.get_widget('gtk_combobox_annotation_priority')
389 t00mlabs 703
        a_wdg_scope = self.srvgui.get_widget('gtk_entry_annotation_scope')
394 t00mlabs 704
        a_wdg_product = self.srvgui.get_widget('gtk_entry_annotation_product')
340 t00mlabs 705
        a_wdg_text = self.srvgui.get_widget('gtk_textview_annotation_text')
706
        a_wdg_link = self.srvgui.get_widget('gtk_entry_annotation_link')
707
        a_wdg_link_type = self.srvgui.get_widget('gtk_combobox_annotation_link_type')
708
 
709
        annotation['AID'] = a_wdg_aid.get_text()
710
        annotation['Timestamp'] = a_wdg_timestamp.get_text()
351 t00mlabs 711
        annotation['Created'] = a_wdg_timestamp_created.get_text()
340 t00mlabs 712
        annotation['Title'] = a_wdg_title.get_text()
713
        annotation['Component'] = 'Annotation'
714
        annotation['Type'] = self.srvuif.get_combobox_text(a_wdg_type, 1)
715
        annotation['Category'] = self.srvuif.get_combobox_text(a_wdg_category, 1)
716
        annotation['Priority'] = self.srvuif.get_combobox_text(a_wdg_priority, 1)
395 t00mlabs 717
        scope = a_wdg_scope.get_text()
718
        annotation['Scope'] = scope.strip()
719
        product = a_wdg_product.get_text()
720
        annotation['Product'] = product.strip()
340 t00mlabs 721
        annotation['Content'] = self.srvuif.get_textview_text(a_wdg_text)
722
        annotation['Link'] = a_wdg_link.get_text()
723
        annotation['LinkType'] = self.srvuif.get_combobox_text(a_wdg_link_type, 0)
724
 
725
        return annotation
365 t00mlabs 726
 
727
 
389 t00mlabs 728
    def clear(self):
729
        a_wdg_timestamp = self.srvgui.get_widget('gtk_label_human_timestamp')
730
        a_wdg_timestamp_created = self.srvgui.get_widget('gtk_label_timestamp_created')
731
        a_wdg_title = self.srvgui.get_widget('gtk_entry_annotation_title')
732
        a_wdg_type = self.srvgui.get_widget('gtk_combobox_annotation_type')
733
        a_wdg_text = self.srvgui.get_widget('gtk_textview_annotation_text')
734
        a_wdg_link = self.srvgui.get_widget('gtk_entry_annotation_link')
735
        a_wdg_link_button = self.srvgui.get_widget('gtk_link_button_annotation_link')
736
        a_wdg_link_type = self.srvgui.get_widget('gtk_combobox_annotation_link_type')
737
        a_wdg_scope = self.srvgui.get_widget('gtk_entry_annotation_scope')
394 t00mlabs 738
        a_wdg_product = self.srvgui.get_widget('gtk_entry_annotation_scope')
389 t00mlabs 739
 
740
        a_wdg_timestamp.set_text('')
741
        a_wdg_timestamp_created.set_text('')
742
        a_wdg_title.set_text('')
743
        a_wdg_scope.set_text('')
394 t00mlabs 744
        a_wdg_product.set_text('')
389 t00mlabs 745
        textbuffer = a_wdg_text.get_buffer()
746
        textbuffer.set_text('')
747
        a_wdg_link.set_text('')
748
        a_wdg_link_button.set_uri('')
749
 
750
 
380 t00mlabs 751
    def stack_changed(self, stack, gparam):
388 t00mlabs 752
        paned = self.srvgui.get_widget('gtk_hpaned')
753
        pos = paned.get_position()
754
        self.srvgui.set_key_value('current_paned_position', pos)
755
        paned.set_position(0)
380 t00mlabs 756
        visible_stack_name = stack.get_visible_child_name()
400 t00mlabs 757
        # ~ self.log.debug("Annotation Stack changed to: %s", visible_stack_name)
386 t00mlabs 758
        self.set_visible_stack(visible_stack_name)
380 t00mlabs 759
 
760
 
365 t00mlabs 761
    def preview(self):
408 t00mlabs 762
        visor_annotations = self.srvgui.get_widget('visor_annotations')
763
        aid = visor_annotations.row_current()
764
        # ~ aid = self.get_aid_from_widget()
400 t00mlabs 765
        # ~ self.log.debug("Previewing aid: %s", aid)
386 t00mlabs 766
        if len(aid) == 0:
767
            return
768
 
370 t00mlabs 769
        atype = self.srvant.get_metadata_value(aid, 'Type')
389 t00mlabs 770
        if atype is None:
393 t00mlabs 771
            raise
389 t00mlabs 772
            return
773
 
365 t00mlabs 774
        browser = self.srvgui.get_widget('annotation_browser')
367 t00mlabs 775
        # ~ self.log.debug("Execute asciidoc for current annotation: %s", self.sid)
369 t00mlabs 776
        try:
370 t00mlabs 777
            if atype == 'Bookmark':
778
                alink = self.srvant.get_metadata_value(aid, 'Link')
779
                if len(alink) > 0:
780
                    browser.load_url(alink)
781
            else:
399 t00mlabs 782
                tpath = self.srvacd.get_target_path(aid)
783
                if not os.path.exists(tpath):
784
                    target = self.srvacd.generate_preview(aid)
785
                else:
786
                    spath = self.srvacd.get_source_path(aid)
787
                    smtime = self.srvutl.get_file_modification_date(spath)
788
                    tmtime = self.srvutl.get_file_modification_date(tpath)
789
                    # ~ self.log.debug("%s; %s", spath, smtime)
790
                    # ~ self.log.debug("%s; %s", tpath, tmtime)
791
                    if tmtime < smtime:
792
                        target = self.srvacd.generate_preview(aid)
408 t00mlabs 793
                        self.log.debug("Preview generated")
399 t00mlabs 794
                    else:
795
                        target = "file://" + tpath
408 t00mlabs 796
                        self.log.debug("Using cache for preview")
370 t00mlabs 797
                browser.load_url(html.escape(target))
399 t00mlabs 798
        except Exception as error:
799
            self.log.error(error)
369 t00mlabs 800
            self.log.debug("Showing editor instead preview")
801
            stack_annotation = self.srvgui.get_widget('stack_annotation')
380 t00mlabs 802
            self.set_visible_stack('editor')
367 t00mlabs 803
        # ~ self.log.debug("Load preview from %s", target)
393 t00mlabs 804
 
805
 
806
    def completion_match_func(self, completion, key, iter):
807
        model = completion.get_model()
808
        text = model.get_value(iter, 0)
809
        if key.upper() in text.upper():
810
            return True
811
        return False
812
 
813
 
814
    def scope_activated(self, entry):
815
        scope_text = entry.get_text()
816
        cid = self.srvclt.get_cid_by_name(scope_text)
817
        if cid is None:
818
            for title in self.srvclt.get_collections_name():
819
                if scope_text.upper() in title.upper():
820
                    entry.set_text(title)
821
        else:
822
            entry.set_text(scope_text)
823
 
399 t00mlabs 824
 
393 t00mlabs 825
    def product_activated(self, entry):
826
        pass