Subversion Repositories basico

Compare Revisions

Ignore whitespace Rev 379 → Rev 380

/branches/BR-0.4/basico/services/srv_annotations.py
47,9 → 47,9
with open(filename, 'w') as fa:
json.dump(metadata, fa)
self.log.debug("Fixed annotation with AID: %s", metadata['AID'])
 
def gen_aid(self, sid):
 
def gen_aid(self, sid='0000000000'):
'''
Generate new annotation id
'''
57,7 → 57,7
 
 
def create(self, annotation):
ANNOTATION_FILE_METADATA = LPATH['ANNOTATIONS'] + annotation['AID'] + '.json'
ANNOTATION_FILE_METADATA = LPATH['ANNOTATIONS'] + annotation['AID'] + '.json'
ANNOTATION_FILE_CONTENT = LPATH['ANNOTATIONS'] + annotation['AID'] + '.adoc'
annotation['Timestamp'] = self.srvutl.timestamp()
annotation['Created'] = self.srvutl.timestamp()
82,7 → 82,7
for key in metadata:
annotation[key] = metadata[key]
annotation['Timestamp'] = self.srvutl.timestamp()
 
# Write annotation metadata
with open(ANNOTATION_FILE_METADATA, 'w') as fa:
json.dump(annotation, fa)
96,7 → 96,7
ANNOTATION_FILE_METADATA = LPATH['ANNOTATIONS'] + aid + '.json'
annotation = self.get_metadata_from_file(ANNOTATION_FILE_METADATA)
annotation['Timestamp'] = self.srvutl.timestamp()
 
# Write annotation metadata
with open(ANNOTATION_FILE_METADATA, 'w') as fa:
json.dump(annotation, fa)
103,10 → 103,10
 
title = self.get_title(annotation['AID'])
self.log.info("Annotation '%s' (%s) updated" % (title, annotation['AID']))
 
 
def update(self, annotation):
ANNOTATION_FILE_METADATA = LPATH['ANNOTATIONS'] + annotation['AID'] + '.json'
ANNOTATION_FILE_METADATA = LPATH['ANNOTATIONS'] + annotation['AID'] + '.json'
ANNOTATION_FILE_CONTENT = LPATH['ANNOTATIONS'] + annotation['AID'] + '.adoc'
 
annotation['Timestamp'] = self.srvutl.timestamp()
184,7 → 184,7
metadata = self.get_metadata_from_aid(aid)
return metadata[key]
 
 
def is_valid(self, aid):
ANNOTATION_FILE = LPATH['ANNOTATIONS'] + aid + '.json'
valid = os.path.exists(ANNOTATION_FILE)
/branches/BR-0.4/basico/services/srv_callbacks.py
357,23 → 357,30
self.srvutl.browse("file://%s" % FILE['HELP_INDEX'])
 
 
def gui_annotation_widget_show(self, widget, sid='0000000000', action='create'):
def gui_annotation_widget_show(self, aid, action='create'):
widget_annotation = self.srvgui.get_widget('widget_annotation')
# ~ stack_annotation = self.srvgui.get_widget('stack_annotation')
widget = self.srvgui.get_widget('gtk_label_timestamp_created')
vpaned = self.srvgui.get_widget('gtk_vpaned_visor')
vpaned.set_position(0)
 
if action == 'create':
self.gui_annotation_widget_clear()
aid = self.srvant.gen_aid(sid)
if aid == '':
aid = self.srvant.gen_aid()
else:
sid = aid
aid = self.srvant.gen_aid(sid)
widget_annotation.set_visible_stack('editor')
elif action == 'edit':
aid = sid
widget_annotation.set_visible_stack('editor')
elif action == 'preview':
widget_annotation.set_visible_stack('preview')
 
self.log.debug("%s %s", action, aid)
widget_annotation.set_metadata_to_widget(aid, action)
stack_annotation = self.srvgui.get_widget('stack_annotation')
stack_annotation.set_visible_child_name('editor')
self.srvuif.set_widget_visibility('gtk_vbox_container_annotations', True)
widget.grab_focus()
self.srvuif.grab_focus()
 
 
def gui_show_popover(self, button, popover):
605,10 → 612,22
window.unfullscreen()
 
 
def action_annotation_create(self):
self.gui_annotation_widget_show('', 'create')
 
 
def action_annotation_create_for_sapnote(self, sid):
self.gui_annotation_widget_show(sid, 'create')
 
 
def action_annotation_edit(self, aid):
self.gui_annotation_widget_show(None, aid, 'edit')
self.gui_annotation_widget_show(aid, 'edit')
 
 
def action_annotation_preview(self, aid):
self.gui_annotation_widget_show(aid, 'preview')
 
 
def action_annotation_duplicate(self, *args):
self.log.debug("ACTION-DUPLICATE: %s" % args)
 
1045,3 → 1064,4
 
def copy_text_to_clipboard(self, widget, text):
self.srvuif.copy_text_to_clipboard(text)
self.srvuif.grab_focus()
/branches/BR-0.4/basico/services/srv_uif.py
245,8 → 245,11
 
 
def grab_focus(self):
popover = self.srvgui.get_key_value('LAST_POPOVER')
popover.popdown()
try:
popover = self.srvgui.get_key_value('LAST_POPOVER')
popover.popdown()
except:
pass
 
 
def action_collection_copy_to_clipboard(self, button):
/branches/BR-0.4/basico/widgets/wdg_annot.py
9,7 → 9,7
 
import html
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
gi.require_version('Pango', '1.0')
gi.require_version('GdkPixbuf', '2.0')
36,7 → 36,7
self.pack_start(self.tool_bar, False, True, 0)
self.tool_bar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
self.tool_bar.set_property('margin-bottom', 0)
 
# Task Category button
tool = Gtk.ToolItem()
a_category_model = Gtk.ListStore(Pixbuf, str)
43,7 → 43,7
a_category = Gtk.ComboBox.new_with_model(a_category_model)
a_category.set_tooltip_markup('<b>Choose a category</b>')
self.srvgui.add_widget('gtk_combobox_annotation_category', a_category)
 
renderer = Gtk.CellRendererPixbuf()
a_category.pack_start(renderer, False)
a_category.add_attribute(renderer, "pixbuf", 0)
53,13 → 53,13
 
icon = self.srvicm.get_pixbuf_icon('basico-inbox', 24, 24)
active = self.srvgui.add_widget('annotation_category_Inbox', a_category_model.append([icon, 'Inbox']))
 
icon = self.srvicm.get_pixbuf_icon('basico-drafts', 24, 24)
self.srvgui.add_widget('annotation_category_Drafts', a_category_model.append([icon, 'Drafts']))
 
icon = self.srvicm.get_pixbuf_icon('basico-archived', 24, 24)
self.srvgui.add_widget('annotation_category_Archived', a_category_model.append([icon, 'Archived']))
 
a_category.set_active_iter(active)
hbox = Gtk.HBox()
hbox.pack_start(a_category, False, False, 0)
101,11 → 101,11
a_priority = Gtk.ComboBox.new_with_model(a_priority_model)
a_priority.set_tooltip_markup('<b>Choose a priority</b>')
self.srvgui.add_widget('gtk_combobox_annotation_priority', a_priority)
 
renderer = Gtk.CellRendererPixbuf()
a_priority.pack_start(renderer, False)
a_priority.add_attribute(renderer, "pixbuf", 0)
 
renderer = Gtk.CellRendererText()
a_priority.pack_start(renderer, True)
a_priority.add_attribute(renderer, "text", 1)
118,13 → 118,13
 
icon = self.srvicm.get_pixbuf_icon('basico-annotation-priority-low', 24, 24)
self.srvgui.add_widget('annotation_priority_Low', a_priority_model.append([icon, 'Low']))
 
a_priority.set_active_iter(active)
hbox = Gtk.HBox()
hbox.pack_start(a_priority, False, False, 0)
tool.add(hbox)
self.tool_bar.insert(tool, -1)
 
# Separator
tool = self.srvuif.get_toolbar_separator(False, False)
self.tool_bar.insert(tool, -1)
140,7 → 140,7
# Separator
tool = self.srvuif.get_toolbar_separator(False, True)
self.tool_bar.insert(tool, -1)
 
# Title
tool = Gtk.ToolItem()
# ~ vbox = Gtk.VBox()
163,7 → 163,7
tool.set_no_show_all(True)
tool.hide()
self.tool_bar.insert(tool, -1)
 
# Timestamp updated
tool = Gtk.ToolItem()
tool.set_expand(False)
205,7 → 205,7
# Separator
tool = self.srvuif.get_toolbar_separator(False, False)
self.tool_bar.insert(tool, -1)
 
# Maximize toggle button
tool = Gtk.ToolItem()
tool.set_expand(False)
250,7 → 250,7
self.__setup()
# ~ self.stack_changed()
 
 
def get_services(self):
"""Load services to be used in this class
"""
262,8 → 262,8
self.srvant = self.get_service('Annotation')
self.srvutl = self.get_service('Utils')
self.srvacd = self.get_service('Asciidoctor')
 
 
def __setup(self):
# Setup Widget properties
self.set_property('margin-left', 3)
319,12 → 319,12
# ~ hpaned = self.srvgui.get_widget('gtk_hpaned')
# ~ hpaned.set_position(0)
# ~ self.log.debug("HPaned position: %d", hpaned.get_position())
 
# Add Annotation preview stack
preview = self.annotation_preview()
stack_annotation.add_titled(preview, "preview", "Preview annotation")
stack_annotation.child_set_property (preview, "icon-name", "basico-preview")
 
# Add Annotation editor stack
editor = self.annotation_editor()
stack_annotation.add_titled(editor, "editor", "Edit annotation")
334,33 → 334,34
properties = self.annotation_properties()
stack_annotation.add_titled(properties, "properties", "Edit properties")
stack_annotation.child_set_property (properties, "icon-name", "basico-tags")
stack_annotation.set_visible_child_name('editor')
 
self.set_visible_stack('editor')
# ~ stack_annotation.set_visible_child_full('editor', Gtk.StackTransitionType.CROSSFADE)
# ~ stack_annotation.set_property('visible-child', editor)
def stack_changed(self, *args):
 
 
def set_visible_stack(self, stack_name='preview'):
self.srvuif.set_widget_visibility('stack_annotation', True)
stack = self.srvgui.get_widget('stack_annotation')
stack_name = stack.get_visible_child_name()
stack.set_visible_child_name(stack_name)
if stack_name == 'preview':
self.preview()
self.srvuif.set_widget_visibility('gtk_combobox_annotation_category', False)
self.srvuif.set_widget_visibility('gtk_combobox_annotation_type', False)
self.srvuif.set_widget_visibility('gtk_combobox_annotation_priority', False)
self.srvuif.set_widget_visibility('gtk_button_annotation_toolbar_attachment', False)
self.srvuif.set_widget_visibility('gtk_combobox_annotation_priority', False)
self.srvuif.set_widget_visibility('gtk_button_annotation_toolbar_attachment', False)
elif stack_name == 'properties':
self.srvuif.set_widget_visibility('gtk_combobox_annotation_category', False)
self.srvuif.set_widget_visibility('gtk_combobox_annotation_type', False)
self.srvuif.set_widget_visibility('gtk_combobox_annotation_priority', False)
self.srvuif.set_widget_visibility('gtk_button_annotation_toolbar_attachment', False)
self.srvuif.set_widget_visibility('gtk_button_annotation_toolbar_attachment', False)
elif stack_name == 'editor':
self.srvuif.set_widget_visibility('gtk_combobox_annotation_category', True)
self.srvuif.set_widget_visibility('gtk_combobox_annotation_type', True)
self.srvuif.set_widget_visibility('gtk_combobox_annotation_priority', True)
self.srvuif.set_widget_visibility('gtk_button_annotation_toolbar_attachment', True)
 
 
def annotation_preview(self):
browser = self.srvgui.add_widget('annotation_browser', BasicoBrowser(self.app))
return browser
369,7 → 370,7
properties = self.srvgui.add_widget('annotation_properties', Gtk.Label('Properties'))
return properties
 
 
def annotation_editor(self):
vbox = Gtk.VBox()
 
402,7 → 403,7
scroller.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
scroller.set_shadow_type(Gtk.ShadowType.IN)
scroller.set_hexpand(True)
scroller.set_vexpand(True)
scroller.set_vexpand(True)
a_text = self.srvgui.add_widget('gtk_textview_annotation_text', GtkSource.View.new_with_buffer(GtkSource.Buffer()))
a_text.set_wrap_mode(Gtk.WrapMode.WORD)
a_text.modify_font(Pango.FontDescription('Monospace 10'))
456,9 → 457,9
mhbox.pack_start(vboxr, False, False, 0)
vbox.pack_start(mhbox, True, True, 3)
return vbox
 
 
 
def __setup_footer(self):
# Buttons Accept/Cancel
hbox = Gtk.HBox()
530,9 → 531,9
a_wdg_aid.set_text(annotation['AID'])
a_wdg_timestamp.set_text(annotation['Timestamp'])
a_wdg_title.set_text(html.escape(annotation['Title']))
 
a_wdg_type.set_active_iter(self.srvgui.get_widget('annotation_type_%s' % annotation['Type']))
 
try:
a_wdg_category.set_active_iter(self.srvgui.get_widget('annotation_category_%s' % annotation['Category']))
except:
542,7 → 543,7
a_wdg_priority.set_active_iter(self.srvgui.get_widget('annotation_priority_%s' % annotation['Priority']))
except:
a_wdg_priority.set_active_iter(self.srvgui.get_widget('annotation_priority_Normal'))
 
self.srvuif.set_textview_text(a_wdg_text, open(ANNOTATION_FILE_CONTENT).read())
a_wdg_link.set_text(annotation['Link'])
a_wdg_link_button.set_uri(annotation['Link'])
550,13 → 551,13
human_timestamp = self.srvutl.get_human_date_from_timestamp(annotation['Timestamp'])
a_wdg_human_timestamp.set_markup('<b>%s</b>' % human_timestamp)
a_wdg_timestamp_created.set_text(annotation['Created'])
self.stack_changed()
# ~ self.stack_changed()
# ~ self.preview()
 
 
def get_metadata_from_widget(self):
"""
C:237, 4: Missing method docstring (missing-docstring)
C:237, 4: Missing method docstring (missing-docstring)
"""
annotation = {}
a_wdg_aid = self.srvgui.get_widget('gtk_label_aid')
585,6 → 586,15
return annotation
 
 
def stack_changed(self, stack, gparam):
visible_stack_name = stack.get_visible_child_name()
if visible_stack_name == 'preview':
try:
self.preview()
except:
pass
 
 
def preview(self):
aid = self.get_aid_from_widget()
atype = self.srvant.get_metadata_value(aid, 'Type')
601,5 → 611,5
except:
self.log.debug("Showing editor instead preview")
stack_annotation = self.srvgui.get_widget('stack_annotation')
stack_annotation.set_visible_child_name('editor')
self.set_visible_stack('editor')
# ~ self.log.debug("Load preview from %s", target)
/branches/BR-0.4/basico/widgets/wdg_visor_annotations.py
645,6 → 645,14
self.srvuif.set_widget_visibility('gtk_label_total_notes', True)
 
 
def clb_preview(self, button, aid):
self.srvclb.action_annotation_preview(aid)
 
 
def clb_edit(self, button, aid):
self.srvclb.action_annotation_edit(aid)
 
 
def row_double_click(self, treeview, row, col):
try:
selection = treeview.get_selection()
657,7 → 665,7
if is_valid:
fullscreen_annotation = self.srvgui.get_widget('gtk_togglebutton_maximize_annotation_widget')
fullscreen_annotation.set_active(True)
self.srvclb.action_annotation_edit(aid)
self.srvclb.action_annotation_preview(aid)
else:
# ~ aid = None
self.srvuif.set_widget_visibility('gtk_vbox_container_annotations', True)
707,11 → 715,12
button.set_relief(Gtk.ReliefStyle.NONE)
hbox = Gtk.HBox()
icon = self.srvicm.get_new_image_icon(icon_name, 24, 24)
lbltext = Gtk.Label()
lbltext.set_xalign(0.0)
lbltext.set_markup('%s' % text)
hbox.pack_start(icon, False, False, 3)
hbox.pack_start(lbltext, True, True, 3)
if len(text) > 0:
lbltext = Gtk.Label()
lbltext.set_xalign(0.0)
lbltext.set_markup('%s' % text)
hbox.pack_start(lbltext, True, True, 3)
button.add(hbox)
return button
 
718,21 → 727,25
if component == 'Annotation':
box = Gtk.Box(spacing = 3, orientation="vertical")
 
button = get_popover_button("<b>Select all</b>", 'basico-check-all')
button.show_all()
hbox_sel = Gtk.HBox()
button = get_popover_button("", 'basico-check-all')
button.set_tooltip_markup("Select all")
button.connect('clicked', self.select_all, True)
box.pack_start(button, False, False, 0)
hbox_sel.pack_start(button, True, False, 0)
 
button = get_popover_button("<b>Select none</b>", 'basico-check-none')
button.show_all()
button = get_popover_button("", 'basico-check-none')
button.set_tooltip_markup("Select none")
button.connect('clicked', self.select_all, False)
box.pack_start(button, False, False, 0)
hbox_sel.pack_start(button, True, False, 0)
 
button = get_popover_button("<b>Invert selection</b>", 'basico-check-invert')
button.show_all()
button = get_popover_button("", 'basico-check-invert')
button.set_tooltip_markup("Invert selection")
button.connect('clicked', self.select_all, None)
box.pack_start(button, False, False, 0)
hbox_sel.pack_start(button, True, False, 0)
 
box.pack_start(hbox_sel, False, False, 0)
box.show_all()
 
if len(self.rows_toggled()) > 0:
separator = Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL)
box.pack_start(separator, False, False, 0)
754,22 → 767,22
# Popover button "Jump to SAP Note"
if sid != '0000000000':
# Jump to SAP Note
button = get_popover_button("Jump to SAP Note %d" % int(sid), 'basico-jump-sapnote')
button = get_popover_button("<b>Jump</b> to SAP Note %d" % int(sid), 'basico-jump-sapnote')
button.show_all()
button.connect('clicked', self.srvclb.gui_jump_to_sapnote, sid)
box.pack_start(button, False, False, 0)
 
button = get_popover_button("Preview annotation", 'basico-preview')
button = get_popover_button("<b>Preview</b> annotation", 'basico-preview')
button.show_all()
# ~ button.connect('clicked', self.srvclb.duplicate_sapnote, aid)
button.connect('clicked', self.clb_preview, aid)
box.pack_start(button, False, False, 0)
 
button = get_popover_button("Edit annotation", 'basico-edit')
button = get_popover_button("<b>Edit</b> annotation", 'basico-edit')
button.show_all()
# ~ button.connect('clicked', self.srvclb.duplicate_sapnote, aid)
button.connect('clicked', self.clb_edit, aid)
box.pack_start(button, False, False, 0)
 
button = get_popover_button("Duplicate annotation", 'basico-copy-paste')
button = get_popover_button("<b>Duplicate</b> annotation", 'basico-copy-paste')
button.show_all()
# ~ button.connect('clicked', self.srvclb.duplicate_sapnote, aid)
box.pack_start(button, False, False, 0)
/branches/BR-0.4/basico/widgets/wdg_visor_sapnotes.py
34,7 → 34,7
class SAPNotesVisor(BasicoWidget, Gtk.Box):
def __init__(self, app):
super().__init__(app, __class__.__name__)
Gtk.Box.__init__(self, app)
Gtk.Box.__init__(self, app)
self.get_services()
self.bag = []
self.icons = {}
487,7 → 487,7
attachment['Created']
)
self.model.append(pid, node)
 
self.treeview.set_model(self.sorted_model)
self.update_total_sapnotes_count()
self.show_widgets()
523,6 → 523,10
self.srvclb.gui_show_popover(None, popover)
 
 
def clb_create_annotation(self, button, sid):
self.srvclb.action_annotation_create_for_sapnote(sid)
 
 
def build_popover(self, sid, popover, component):
box = Gtk.Box(spacing = 3, orientation="vertical")
isid = int(sid)
557,7 → 561,7
# Popover button "Add an annotation"
button = get_popover_button("<b>Add an annotation</b> to SAP Note %d" % isid, 'basico-annotation')
button.show_all()
button.connect('clicked', self.srvclb.gui_annotation_widget_show, sid, 'create')
button.connect('clicked', self.clb_create_annotation, sid)
box.pack_start(button, False, False, 0)
 
# Popover button "Add attachments"
565,7 → 569,7
button.show_all()
button.connect('clicked', self.srvclb.gui_attachment_add_to_sapnote, sid)
box.pack_start(button, False, False, 0)
 
# Popover button "Open SAP Note"
button = get_popover_button("<b>Browse</b> SAP Note %d" % isid, 'basico-browse')
button.connect('clicked', self.srvclb.sapnote_browse, sid)
/branches/BR-0.4/basico/widgets/wdg_visor_toolbar.py
48,7 → 48,7
tool.set_icon_name('basico-annotation')
tool.set_tooltip_markup('<b>Create a new annotation (not linked to any SAP Note)</b>')
popover = self.srvgui.add_widget('gtk_popover_annotation', Gtk.Popover.new(tool))
tool.connect('clicked', self.srvclb.gui_annotation_widget_show)
tool.connect('clicked', self.clb_create_annotation)
self.tool_bar.insert(tool, -1)
 
# Attachment button
152,3 → 152,7
if key.upper() in text.upper():
return True
return False
 
 
def clb_create_annotation(self, button):
self.srvclb.action_annotation_create()