Subversion Repositories basico

Rev

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