Subversion Repositories basico

Rev

Rev 402 | Go to most recent revision | 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
        self.log.debug("      Key val, name: %s - %s", event.keyval, Gdk.keyval_name(event.keyval))
325
 
326
 
340 t00mlabs 327
    def __setup_header(self):
328
        # Annotation Header
329
        container = self.srvgui.get_widget('gtk_vbox_annotation_container')
330
        header = Gtk.VBox()
364 t00mlabs 331
 
332
        # Editor's toolbar
348 t00mlabs 333
        toolbar = AnnotationToolbar(self.app, self.sid)
334
        header.pack_start(toolbar, False, False, 0)
340 t00mlabs 335
        hbox = Gtk.HBox()
336
        a_lbl_aid = Gtk.Label()
337
        a_lbl_aid.set_property('xalign', 1.0)
338
        a_lbl_aid.modify_font(Pango.FontDescription('Monospace 10'))
339
        a_lbl_aid.set_markup('<b>Annotation Id:</b>')
340
        a_aid = self.srvgui.add_widget('gtk_label_aid', Gtk.Label())
341
        a_aid.set_property('xalign', 1.0)
342
        a_aid.set_selectable(True)
343
        a_aid.modify_font(Pango.FontDescription('Monospace 10'))
344
        separator = Gtk.Separator()
345
        hbox.pack_start(a_lbl_aid, False, False, 0)
346
        hbox.pack_start(a_aid, False, False, 0)
348 t00mlabs 347
        hbox.set_no_show_all(True)
348
        hbox.hide()
349
        # ~ header.pack_start(hbox, False, False, 0)
350
        # ~ header.pack_start(a_wdg_human_timestamp, True, True, 0)
346 t00mlabs 351
        # ~ header.pack_start(separator, False, False, 3)
340 t00mlabs 352
        header.show_all()
353
        container.pack_start(header, False, False, 0)
354
 
355
 
356
    def __setup_body(self):
364 t00mlabs 357
        stack_switcher = self.srvgui.get_widget('stack_switcher_annotation')
358
        stack_annotation = self.srvgui.get_widget('stack_annotation')
359
        stack_annotation.connect('notify::visible-child', self.stack_changed)
360
        self.container_body.add(stack_annotation)
361
 
366 t00mlabs 362
        # Add Annotation preview stack
394 t00mlabs 363
        preview = self.widget_annotation_preview()
366 t00mlabs 364
        stack_annotation.add_titled(preview, "preview", "Preview annotation")
365
        stack_annotation.child_set_property (preview, "icon-name", "basico-preview")
380 t00mlabs 366
 
364 t00mlabs 367
        # Add Annotation editor stack
394 t00mlabs 368
        editor = self.widget_annotation_editor()
364 t00mlabs 369
        stack_annotation.add_titled(editor, "editor", "Edit annotation")
370
        stack_annotation.child_set_property (editor, "icon-name", "basico-drafts")
371
 
367 t00mlabs 372
        # Add Annotation properties stack
390 t00mlabs 373
        # ~ properties = self.annotation_properties()
374
        # ~ stack_annotation.add_titled(properties, "properties", "Edit properties")
375
        # ~ stack_annotation.child_set_property (properties, "icon-name", "basico-tags")
380 t00mlabs 376
 
377
 
378
 
394 t00mlabs 379
    def set_visible_stack(self, stack_name='editor'):
380 t00mlabs 380
        self.srvuif.set_widget_visibility('stack_annotation', True)
367 t00mlabs 381
        stack = self.srvgui.get_widget('stack_annotation')
380 t00mlabs 382
        stack.set_visible_child_name(stack_name)
364 t00mlabs 383
        if stack_name == 'preview':
365 t00mlabs 384
            self.preview()
367 t00mlabs 385
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_category', False)
386
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_type', False)
380 t00mlabs 387
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_priority', False)
388
            self.srvuif.set_widget_visibility('gtk_button_annotation_toolbar_attachment', False)
390 t00mlabs 389
            self.srvuif.set_widget_visibility('gtk_entry_annotation_scope', False)
399 t00mlabs 390
            self.srvuif.set_widget_visibility('gtk_switch_annotation_template', False)
407 t00mlabs 391
            self.srvuif.set_widget_visibility('annotation_footer_buttons', False)
399 t00mlabs 392
            self.srvuif.set_widget_visibility('gtk_label_annotation_sid', True)
367 t00mlabs 393
        elif stack_name == 'properties':
394
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_category', False)
395
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_type', False)
396
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_priority', False)
380 t00mlabs 397
            self.srvuif.set_widget_visibility('gtk_button_annotation_toolbar_attachment', False)
390 t00mlabs 398
            self.srvuif.set_widget_visibility('gtk_entry_annotation_scope', False)
399 t00mlabs 399
            self.srvuif.set_widget_visibility('gtk_switch_annotation_template', False)
407 t00mlabs 400
            self.srvuif.set_widget_visibility('annotation_footer_buttons', False)
399 t00mlabs 401
            self.srvuif.set_widget_visibility('gtk_label_annotation_sid', False)
367 t00mlabs 402
        elif stack_name == 'editor':
403
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_category', True)
404
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_type', True)
405
            self.srvuif.set_widget_visibility('gtk_combobox_annotation_priority', True)
406
            self.srvuif.set_widget_visibility('gtk_button_annotation_toolbar_attachment', True)
390 t00mlabs 407
            self.srvuif.set_widget_visibility('gtk_entry_annotation_scope', True)
399 t00mlabs 408
            self.srvuif.set_widget_visibility('gtk_switch_annotation_template', True)
407 t00mlabs 409
            self.srvuif.set_widget_visibility('annotation_footer_buttons', True)
399 t00mlabs 410
            self.srvuif.set_widget_visibility('gtk_label_annotation_sid', False)
364 t00mlabs 411
 
380 t00mlabs 412
 
394 t00mlabs 413
    def widget_annotation_preview(self):
364 t00mlabs 414
        browser = self.srvgui.add_widget('annotation_browser', BasicoBrowser(self.app))
415
        return browser
416
 
394 t00mlabs 417
 
418
    def widget_annotation_properties(self):
367 t00mlabs 419
        properties = self.srvgui.add_widget('annotation_properties', Gtk.Label('Properties'))
420
        return properties
421
 
380 t00mlabs 422
 
394 t00mlabs 423
    def widget_annotation_editor(self):
340 t00mlabs 424
        vbox = Gtk.VBox()
425
 
426
        # Hidden metadata
427
        hhbox = Gtk.HBox()
428
 
429
        a_timestamp = self.srvgui.add_widget('gtk_label_timestamp', Gtk.Label(self.srvutl.timestamp()))
430
        a_timestamp.set_sensitive(False)
431
        self.srvuif.set_widget_visibility('gtk_label_timestamp', False)
432
        hhbox.pack_start(a_timestamp, False, False, 0)
433
        vbox.pack_start(hhbox, False, False, 0)
434
 
435
 
436
        # Main hbox
437
        mhbox = Gtk.HBox()
438
 
439
        vboxl = Gtk.VBox()
440
        vboxl.set_vexpand(True)
441
        vboxr = Gtk.VBox()
442
        vboxr.set_vexpand(True)
443
 
444
        # Title
445
        a_title = self.srvgui.add_widget('gtk_entry_annotation_title', Gtk.Entry())
446
        a_title.set_placeholder_text("Type a title here...")
447
        a_title.modify_font(Pango.FontDescription('Monospace 10'))
448
        vboxl.pack_start(a_title, False, False, 0)
449
 
450
        # Text
451
        scroller = Gtk.ScrolledWindow()
393 t00mlabs 452
        scroller.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
340 t00mlabs 453
        scroller.set_shadow_type(Gtk.ShadowType.IN)
454
        scroller.set_hexpand(True)
380 t00mlabs 455
        scroller.set_vexpand(True)
342 t00mlabs 456
        a_text = self.srvgui.add_widget('gtk_textview_annotation_text', GtkSource.View.new_with_buffer(GtkSource.Buffer()))
340 t00mlabs 457
        a_text.set_wrap_mode(Gtk.WrapMode.WORD)
458
        a_text.modify_font(Pango.FontDescription('Monospace 10'))
459
        a_text.set_vexpand(True)
460
        a_text.set_left_margin(6)
461
        a_text.set_top_margin(6)
462
        a_text.set_right_margin(6)
463
        a_text.set_bottom_margin(6)
342 t00mlabs 464
        a_text.set_show_line_marks(True)
465
        a_text.set_show_line_numbers(True)
466
        a_text.set_highlight_current_line(True)
467
        a_textbuffer = a_text.get_buffer()
340 t00mlabs 468
        a_textbuffer.set_text('')
469
        scroller.add(a_text)
470
        vboxl.pack_start(scroller, True, True, 3)
471
 
393 t00mlabs 472
        # Scope entry
473
        hbox_scope = Gtk.HBox()
474
        completion = Gtk.EntryCompletion()
475
        completion.set_match_func(self.completion_match_func)
476
        completion_model = Gtk.ListStore(str)
477
        completion.set_model(completion_model)
478
        completion.set_text_column(0)
479
        completion.set_inline_completion(True)
480
        completion.set_inline_selection(True)
481
        scope = self.srvgui.add_widget('gtk_entry_annotation_scope', Gtk.Entry())
482
        scope.set_completion(completion)
483
        scope.connect('activate', self.scope_activated)
484
 
485
        max_width = 0
486
        for title in self.srvclt.get_collections_name():
487
            if len(title) > max_width:
488
                max_width = len(title)
489
            completion_model.append([title])
490
 
491
        scope.set_width_chars(max_width)
492
        scope.set_placeholder_text('Scope')
493
 
494
        ## Separator
495
        separator = Gtk.SeparatorToolItem.new()
496
        separator.set_draw(False)
497
        separator.set_expand(False)
498
 
499
        hbox_scope.pack_start(scope, False, False, 0)
500
        hbox_scope.pack_start(separator, True, True, 0)
501
 
502
 
503
        # SAP Products entry
504
        hbox_product = Gtk.HBox()
505
        completion = Gtk.EntryCompletion()
506
        completion.set_match_func(self.completion_match_func)
507
        completion_model = Gtk.ListStore(str)
508
        completion.set_model(completion_model)
509
        completion.set_text_column(0)
510
        completion.set_inline_completion(True)
511
        completion.set_inline_selection(True)
512
        product = self.srvgui.add_widget('gtk_entry_annotation_product', Gtk.Entry())
513
        product.set_completion(completion)
514
        product.connect('activate', self.product_activated)
515
 
516
        lproducts = open(FILE['L_SAP_PRODUCTS'], 'r').readlines()
517
        max_width = 0
518
        for title in lproducts:
519
            if len(title) > max_width:
520
                max_width = len(title)
521
            completion_model.append([title.strip()])
522
 
523
        product.set_width_chars(max_width)
524
        product.set_placeholder_text('Product')
525
 
526
        ## Separator
527
        separator = Gtk.SeparatorToolItem.new()
528
        separator.set_draw(False)
529
        separator.set_expand(True)
530
 
531
        hbox_product.pack_start(product, False, False, 0)
532
        hbox_product.pack_start(separator, True, True, 0)
533
        vboxl.pack_start(hbox_scope, False, False, 3)
534
        vboxl.pack_start(hbox_product, False, False, 3)
535
        # ~ hbox_scope.pack_start(vbox_product, False, False, 0)
536
        # ~ vboxl.pack_start(hbox_scope, True, True, 3)
537
 
538
        # Tags entry
539
 
340 t00mlabs 540
        # Url
393 t00mlabs 541
        hbox_url = Gtk.HBox()
340 t00mlabs 542
 
543
        ## url entry
544
        a_link = self.srvgui.add_widget('gtk_entry_annotation_link', Gtk.Entry())
393 t00mlabs 545
        a_link.set_width_chars(80)
340 t00mlabs 546
        a_link.set_placeholder_text("Type a url here...")
393 t00mlabs 547
        hbox_url.pack_start(a_link, False, False, 0)
340 t00mlabs 548
 
549
        ## url button
550
        a_link_button = self.srvgui.add_widget('gtk_link_button_annotation_link', Gtk.LinkButton())
551
        a_link_button.set_relief(Gtk.ReliefStyle.NORMAL)
552
        a_link_button.set_label('Visit')
393 t00mlabs 553
        hbox_url.pack_start(a_link_button, False, False, 0)
340 t00mlabs 554
 
555
        # url type
556
        a_link_type_model = Gtk.ListStore(str)
557
        self.srvgui.add_widget('annotation_link_type_Intranet', a_link_type_model.append(['Intranet']))
558
        self.srvgui.add_widget('annotation_link_type_SAP Blog', a_link_type_model.append(['SAP Blog']))
559
        self.srvgui.add_widget('annotation_link_type_SAP Document', a_link_type_model.append(['SAP Document']))
560
        self.srvgui.add_widget('annotation_link_type_SAP Help', a_link_type_model.append(['SAP Help']))
561
        self.srvgui.add_widget('annotation_link_type_SAP Incident', a_link_type_model.append(['SAP Incident']))
562
        self.srvgui.add_widget('annotation_link_type_SAP Questions and Answers', a_link_type_model.append(['SAP Questions and Answers']))
563
        self.srvgui.add_widget('annotation_link_type_SAP Wiki', a_link_type_model.append(['SAP Wiki']))
564
        active = self.srvgui.add_widget('annotation_link_type_Website', a_link_type_model.append(['Website']))
565
        a_link_type = Gtk.ComboBox.new_with_model(a_link_type_model)
566
        a_link_type.set_active_iter(active)
567
        self.srvgui.add_widget('gtk_combobox_annotation_link_type', a_link_type)
568
        renderer_text = Gtk.CellRendererText()
569
        a_link_type.pack_start(renderer_text, True)
570
        a_link_type.add_attribute(renderer_text, "text", 0)
393 t00mlabs 571
        hbox_url.pack_start(a_link_type, False, False, 0)
572
        vboxl.pack_start(hbox_url, False, False, 3)
340 t00mlabs 573
 
393 t00mlabs 574
        mhbox.pack_start(vboxl, True, True, 0)
340 t00mlabs 575
        mhbox.pack_start(vboxr, False, False, 0)
393 t00mlabs 576
        vbox.pack_start(mhbox, True, True, 0)
364 t00mlabs 577
        return vbox
340 t00mlabs 578
 
579
 
380 t00mlabs 580
 
340 t00mlabs 581
    def __setup_footer(self):
582
        # Buttons Accept/Cancel
583
        hbox = Gtk.HBox()
407 t00mlabs 584
        self.srvgui.add_widget('annotation_footer_buttons', hbox)
340 t00mlabs 585
        accept = self.srvgui.add_widget('gtk_button_accept_annotation', Gtk.Button('Accept'))
586
        accept.connect('clicked', self.srvclb.action_annotation_accept, self.sid)
587
        accept.set_property('always-show-image', True)
588
        icon = self.srvicm.get_new_image_icon('basico-check-accept', 24, 24)
589
        accept.set_image(icon)
590
        cancel = self.srvgui.add_widget('gtk_button_cancel_annotation', Gtk.Button('Cancel'))
591
        cancel.connect('clicked', self.srvclb.action_annotation_cancel)
592
        cancel.set_property('always-show-image', True)
593
        icon = self.srvicm.get_new_image_icon('basico-check-cancel', 24, 24)
594
        cancel.set_image(icon)
595
        hbox.pack_start(accept, True, False, 3)
596
        hbox.pack_start(cancel, True, False, 3)
597
        self.pack_start(hbox, False, False, 3)
598
 
599
 
600
    def set_aid_to_widget(self, aid):
601
        """
602
        C:237, 4: Missing method docstring (missing-docstring)
603
        """
604
        a_aid = self.srvgui.get_widget('gtk_label_aid')
605
        a_aid.set_text(aid)
606
 
607
 
608
    def get_aid_from_widget(self):
609
        """
610
        C:237, 4: Missing method docstring (missing-docstring)
611
        """
612
        a_aid = self.srvgui.get_widget('gtk_label_aid')
613
        return a_aid.get_text()
614
 
615
 
365 t00mlabs 616
 
361 t00mlabs 617
    def set_metadata_to_widget(self, aid, action='edit'):
340 t00mlabs 618
        """
619
        C:237, 4: Missing method docstring (missing-docstring)
620
        """
621
        self.set_aid_to_widget(aid)
622
        sid = self.srvant.get_sid(aid)
623
        title = self.srvgui.get_widget('gtk_label_annotation_sid')
399 t00mlabs 624
        # ~ if sid == '0000000000':
625
            # ~ title.set_markup('<big><b>Annotation</b></big>')
626
 
627
        # ~ else:
628
            # ~ title.set_markup('<big><b>Annotation for SAP Note %s</b></big>' % str(int(sid)))
629
 
630
 
631
        if action == 'create':
340 t00mlabs 632
            self.srvuif.statusbar_msg("Creating new annotation")
399 t00mlabs 633
        elif action == 'edit' or action == 'preview':
340 t00mlabs 634
            self.srvuif.statusbar_msg("Creating/Editing new annotation for SAP Note %s" % str(int(sid)))
351 t00mlabs 635
            annotation = self.srvant.get_metadata_from_aid(aid)
340 t00mlabs 636
            if annotation is not None:
637
                ANNOTATION_FILE_CONTENT = LPATH['ANNOTATIONS'] + aid + '.adoc'
399 t00mlabs 638
                a_wdg_icon = self.srvgui.get_widget('gtk_box_annotation_icon')
340 t00mlabs 639
                a_wdg_aid = self.srvgui.get_widget('gtk_label_aid')
640
                a_wdg_timestamp = self.srvgui.get_widget('gtk_label_timestamp')
641
                a_wdg_title = self.srvgui.get_widget('gtk_entry_annotation_title')
642
                a_wdg_type = self.srvgui.get_widget('gtk_combobox_annotation_type')
643
                a_wdg_category = self.srvgui.get_widget('gtk_combobox_annotation_category')
644
                a_wdg_priority = self.srvgui.get_widget('gtk_combobox_annotation_priority')
389 t00mlabs 645
                a_wdg_scope = self.srvgui.get_widget('gtk_entry_annotation_scope')
394 t00mlabs 646
                a_wdg_product = self.srvgui.get_widget('gtk_entry_annotation_product')
340 t00mlabs 647
                a_wdg_human_timestamp = self.srvgui.get_widget('gtk_label_human_timestamp')
351 t00mlabs 648
                a_wdg_timestamp_created = self.srvgui.get_widget('gtk_label_timestamp_created')
340 t00mlabs 649
                a_wdg_text = self.srvgui.get_widget('gtk_textview_annotation_text')
650
                a_wdg_link = self.srvgui.get_widget('gtk_entry_annotation_link')
651
                a_wdg_link_button = self.srvgui.get_widget('gtk_link_button_annotation_link')
652
                a_wdg_link_type = self.srvgui.get_widget('gtk_combobox_annotation_link_type')
653
 
402 t00mlabs 654
                title.set_markup("<big><b>%s - </b>%s</big>" % (annotation['Type'], annotation['Title']))
340 t00mlabs 655
                a_wdg_aid.set_text(annotation['AID'])
399 t00mlabs 656
                icon = self.srvicm.get_new_image_icon('basico-annotation-type-%s' % annotation['Type'].lower())
657
                self.srvgui.swap_widget(a_wdg_icon, icon)
340 t00mlabs 658
                a_wdg_timestamp.set_text(annotation['Timestamp'])
659
                a_wdg_title.set_text(html.escape(annotation['Title']))
380 t00mlabs 660
 
340 t00mlabs 661
                a_wdg_type.set_active_iter(self.srvgui.get_widget('annotation_type_%s' % annotation['Type']))
380 t00mlabs 662
 
340 t00mlabs 663
                try:
664
                    a_wdg_category.set_active_iter(self.srvgui.get_widget('annotation_category_%s' % annotation['Category']))
665
                except:
666
                    a_wdg_category.set_active_iter(self.srvgui.get_widget('annotation_category_Inbox'))
667
 
668
                try:
669
                    a_wdg_priority.set_active_iter(self.srvgui.get_widget('annotation_priority_%s' % annotation['Priority']))
670
                except:
671
                    a_wdg_priority.set_active_iter(self.srvgui.get_widget('annotation_priority_Normal'))
380 t00mlabs 672
 
389 t00mlabs 673
                try:
674
                    a_wdg_scope.set_text(annotation['Scope'])
675
                except:
676
                    a_wdg_scope.set_text('')
388 t00mlabs 677
 
394 t00mlabs 678
                try:
679
                    a_wdg_product.set_text(annotation['Product'])
680
                except:
681
                    a_wdg_product.set_text('')
682
 
340 t00mlabs 683
                self.srvuif.set_textview_text(a_wdg_text, open(ANNOTATION_FILE_CONTENT).read())
684
                a_wdg_link.set_text(annotation['Link'])
685
                a_wdg_link_button.set_uri(annotation['Link'])
686
                a_wdg_link_type.set_active_iter(self.srvgui.get_widget('annotation_link_type_%s' % annotation['LinkType']))
687
                human_timestamp = self.srvutl.get_human_date_from_timestamp(annotation['Timestamp'])
348 t00mlabs 688
                a_wdg_human_timestamp.set_markup('<b>%s</b>' % human_timestamp)
351 t00mlabs 689
                a_wdg_timestamp_created.set_text(annotation['Created'])
340 t00mlabs 690
 
691
 
692
    def get_metadata_from_widget(self):
693
        """
380 t00mlabs 694
        C:237, 4: Missing method docstring (missing-docstring)
340 t00mlabs 695
        """
696
        annotation = {}
697
        a_wdg_aid = self.srvgui.get_widget('gtk_label_aid')
698
        a_wdg_timestamp = self.srvgui.get_widget('gtk_label_timestamp')
351 t00mlabs 699
        a_wdg_timestamp_created = self.srvgui.get_widget('gtk_label_timestamp_created')
340 t00mlabs 700
        a_wdg_title = self.srvgui.get_widget('gtk_entry_annotation_title')
701
        a_wdg_type = self.srvgui.get_widget('gtk_combobox_annotation_type')
702
        a_wdg_category = self.srvgui.get_widget('gtk_combobox_annotation_category')
703
        a_wdg_priority = self.srvgui.get_widget('gtk_combobox_annotation_priority')
389 t00mlabs 704
        a_wdg_scope = self.srvgui.get_widget('gtk_entry_annotation_scope')
394 t00mlabs 705
        a_wdg_product = self.srvgui.get_widget('gtk_entry_annotation_product')
340 t00mlabs 706
        a_wdg_text = self.srvgui.get_widget('gtk_textview_annotation_text')
707
        a_wdg_link = self.srvgui.get_widget('gtk_entry_annotation_link')
708
        a_wdg_link_type = self.srvgui.get_widget('gtk_combobox_annotation_link_type')
709
 
710
        annotation['AID'] = a_wdg_aid.get_text()
711
        annotation['Timestamp'] = a_wdg_timestamp.get_text()
351 t00mlabs 712
        annotation['Created'] = a_wdg_timestamp_created.get_text()
340 t00mlabs 713
        annotation['Title'] = a_wdg_title.get_text()
714
        annotation['Component'] = 'Annotation'
715
        annotation['Type'] = self.srvuif.get_combobox_text(a_wdg_type, 1)
716
        annotation['Category'] = self.srvuif.get_combobox_text(a_wdg_category, 1)
717
        annotation['Priority'] = self.srvuif.get_combobox_text(a_wdg_priority, 1)
395 t00mlabs 718
        scope = a_wdg_scope.get_text()
719
        annotation['Scope'] = scope.strip()
720
        product = a_wdg_product.get_text()
721
        annotation['Product'] = product.strip()
340 t00mlabs 722
        annotation['Content'] = self.srvuif.get_textview_text(a_wdg_text)
723
        annotation['Link'] = a_wdg_link.get_text()
724
        annotation['LinkType'] = self.srvuif.get_combobox_text(a_wdg_link_type, 0)
725
 
726
        return annotation
365 t00mlabs 727
 
728
 
389 t00mlabs 729
    def clear(self):
730
        a_wdg_timestamp = self.srvgui.get_widget('gtk_label_human_timestamp')
731
        a_wdg_timestamp_created = self.srvgui.get_widget('gtk_label_timestamp_created')
732
        a_wdg_title = self.srvgui.get_widget('gtk_entry_annotation_title')
733
        a_wdg_type = self.srvgui.get_widget('gtk_combobox_annotation_type')
734
        a_wdg_text = self.srvgui.get_widget('gtk_textview_annotation_text')
735
        a_wdg_link = self.srvgui.get_widget('gtk_entry_annotation_link')
736
        a_wdg_link_button = self.srvgui.get_widget('gtk_link_button_annotation_link')
737
        a_wdg_link_type = self.srvgui.get_widget('gtk_combobox_annotation_link_type')
738
        a_wdg_scope = self.srvgui.get_widget('gtk_entry_annotation_scope')
394 t00mlabs 739
        a_wdg_product = self.srvgui.get_widget('gtk_entry_annotation_scope')
389 t00mlabs 740
 
741
        a_wdg_timestamp.set_text('')
742
        a_wdg_timestamp_created.set_text('')
743
        a_wdg_title.set_text('')
744
        a_wdg_scope.set_text('')
394 t00mlabs 745
        a_wdg_product.set_text('')
389 t00mlabs 746
        textbuffer = a_wdg_text.get_buffer()
747
        textbuffer.set_text('')
748
        a_wdg_link.set_text('')
749
        a_wdg_link_button.set_uri('')
750
 
751
 
380 t00mlabs 752
    def stack_changed(self, stack, gparam):
388 t00mlabs 753
        paned = self.srvgui.get_widget('gtk_hpaned')
754
        pos = paned.get_position()
755
        self.srvgui.set_key_value('current_paned_position', pos)
756
        paned.set_position(0)
380 t00mlabs 757
        visible_stack_name = stack.get_visible_child_name()
400 t00mlabs 758
        # ~ self.log.debug("Annotation Stack changed to: %s", visible_stack_name)
386 t00mlabs 759
        self.set_visible_stack(visible_stack_name)
380 t00mlabs 760
 
761
 
365 t00mlabs 762
    def preview(self):
763
        aid = self.get_aid_from_widget()
400 t00mlabs 764
        # ~ self.log.debug("Previewing aid: %s", aid)
386 t00mlabs 765
        if len(aid) == 0:
766
            return
767
 
370 t00mlabs 768
        atype = self.srvant.get_metadata_value(aid, 'Type')
389 t00mlabs 769
        if atype is None:
393 t00mlabs 770
            raise
389 t00mlabs 771
            return
772
 
365 t00mlabs 773
        browser = self.srvgui.get_widget('annotation_browser')
367 t00mlabs 774
        # ~ self.log.debug("Execute asciidoc for current annotation: %s", self.sid)
369 t00mlabs 775
        try:
370 t00mlabs 776
            if atype == 'Bookmark':
777
                alink = self.srvant.get_metadata_value(aid, 'Link')
778
                if len(alink) > 0:
779
                    browser.load_url(alink)
780
            else:
399 t00mlabs 781
                tpath = self.srvacd.get_target_path(aid)
782
                if not os.path.exists(tpath):
783
                    target = self.srvacd.generate_preview(aid)
784
                else:
785
                    spath = self.srvacd.get_source_path(aid)
786
                    smtime = self.srvutl.get_file_modification_date(spath)
787
                    tmtime = self.srvutl.get_file_modification_date(tpath)
788
                    # ~ self.log.debug("%s; %s", spath, smtime)
789
                    # ~ self.log.debug("%s; %s", tpath, tmtime)
790
                    if tmtime < smtime:
791
                        target = self.srvacd.generate_preview(aid)
400 t00mlabs 792
                        # ~ self.log.debug("Preview generated")
399 t00mlabs 793
                    else:
794
                        target = "file://" + tpath
400 t00mlabs 795
                        # ~ self.log.debug("Using cache for preview")
370 t00mlabs 796
                browser.load_url(html.escape(target))
399 t00mlabs 797
        except Exception as error:
798
            self.log.error(error)
369 t00mlabs 799
            self.log.debug("Showing editor instead preview")
800
            stack_annotation = self.srvgui.get_widget('stack_annotation')
380 t00mlabs 801
            self.set_visible_stack('editor')
367 t00mlabs 802
        # ~ self.log.debug("Load preview from %s", target)
393 t00mlabs 803
 
804
 
805
    def completion_match_func(self, completion, key, iter):
806
        model = completion.get_model()
807
        text = model.get_value(iter, 0)
808
        if key.upper() in text.upper():
809
            return True
810
        return False
811
 
812
 
813
    def scope_activated(self, entry):
814
        scope_text = entry.get_text()
815
        cid = self.srvclt.get_cid_by_name(scope_text)
816
        if cid is None:
817
            for title in self.srvclt.get_collections_name():
818
                if scope_text.upper() in title.upper():
819
                    entry.set_text(title)
820
        else:
821
            entry.set_text(scope_text)
822
 
399 t00mlabs 823
 
393 t00mlabs 824
    def product_activated(self, entry):
825
        pass