Subversion Repositories basico

Compare Revisions

Ignore whitespace Rev 245 → Rev 246

/branches/BR-0.3/basico/widgets/wdg_annot.py
1,32 → 1,28
#!/usr/bin/python
"""
# -*- coding: utf-8 -*-
# File: annotation.py
# File: wdg_annot.py
# Author: Tomás Vírseda
# License: GPL v3
# Description: Annotation Widget
"""
 
import os
import json
import uuid
import glob
from os.path import sep as SEP
from cgi import escape
 
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import Pango
from basico.core.mod_env import LPATH
 
from basico.core.mod_env import ROOT, USER_DIR, APP, LPATH, GPATH, FILE
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
 
 
class AnnotationWidget(Gtk.VBox):
"""
Annotation Widget
"""
def __init__(self, app, sid='0000000000'):
Gtk.VBox.__init__(self)
self.app = app
self.log = app.log
self.sid = sid
self.get_services()
self.__setup()
35,13 → 31,13
def get_services(self):
"""Load services to be used in this class
"""
self.gui = self.app.get_service("GUI")
self.im = self.app.get_service("IM")
self.uif = self.app.get_service("UIF")
self.clts = self.app.get_service('Collections')
self.cb = self.app.get_service('Callbacks')
self.annot = self.app.get_service('Annotation')
self.utils = self.app.get_service('Utils')
self.srvgui = self.app.get_service("GUI")
self.srvicm = self.app.get_service("IM")
self.srvuif = self.app.get_service("UIF")
self.srvclt = self.app.get_service('Collections')
self.srvclb = self.app.get_service('Callbacks')
self.srvant = self.app.get_service('Annotation')
self.srvutl = self.app.get_service('Utils')
 
 
def __setup(self):
52,7 → 48,7
self.set_vexpand(True)
 
# Annotation container (body)
self.container_body = self.gui.add_widget('gtk_vbox_annotation_container', Gtk.VBox())
self.container_body = self.srvgui.add_widget('gtk_vbox_annotation_container', Gtk.VBox())
self.container_body.set_border_width(3)
self.pack_start(self.container_body, True, True, 3)
 
63,10 → 59,10
 
def __setup_header(self):
# Annotation Header
container = self.gui.get_widget('gtk_vbox_annotation_container')
container = self.srvgui.get_widget('gtk_vbox_annotation_container')
header = Gtk.VBox()
hbox = Gtk.HBox()
title = self.gui.add_widget('gtk_label_annotation_sid', Gtk.Label())
title = self.srvgui.add_widget('gtk_label_annotation_sid', Gtk.Label())
if self.sid == '0000000000':
title.set_markup('<big><b>Annotation</b></big>')
else:
76,7 → 72,7
a_lbl_aid.set_property('xalign', 1.0)
a_lbl_aid.modify_font(Pango.FontDescription('Monospace 10'))
a_lbl_aid.set_markup('<b>Annotation Id:</b>')
a_aid = self.gui.add_widget('gtk_label_aid', Gtk.Label())
a_aid = self.srvgui.add_widget('gtk_label_aid', Gtk.Label())
a_aid.set_property('xalign', 1.0)
a_aid.set_selectable(True)
a_aid.modify_font(Pango.FontDescription('Monospace 10'))
87,7 → 83,7
header.pack_start(hbox, False, False, 0)
 
# Timestamp
a_wdg_human_timestamp = self.gui.add_widget('gtk_label_human_timestamp', Gtk.Label())
a_wdg_human_timestamp = self.srvgui.add_widget('gtk_label_human_timestamp', Gtk.Label())
a_wdg_human_timestamp.modify_font(Pango.FontDescription('Monospace 10'))
a_wdg_human_timestamp.set_xalign(0.0)
header.pack_start(a_wdg_human_timestamp, True, True, 0)
103,9 → 99,9
# Hidden metadata
hhbox = Gtk.HBox()
 
a_timestamp = self.gui.add_widget('gtk_label_timestamp', Gtk.Label(self.utils.timestamp()))
a_timestamp = self.srvgui.add_widget('gtk_label_timestamp', Gtk.Label(self.srvutl.timestamp()))
a_timestamp.set_sensitive(False)
self.uif.set_widget_visibility('gtk_label_timestamp', False)
self.srvuif.set_widget_visibility('gtk_label_timestamp', False)
hhbox.pack_start(a_timestamp, False, False, 0)
vbox.pack_start(hhbox, False, False, 0)
 
119,7 → 115,7
vboxr.set_vexpand(True)
 
# Title
a_title = self.gui.add_widget('gtk_entry_annotation_title', Gtk.Entry())
a_title = self.srvgui.add_widget('gtk_entry_annotation_title', Gtk.Entry())
a_title.set_placeholder_text("Type a title here...")
a_title.modify_font(Pango.FontDescription('Monospace 10'))
vboxl.pack_start(a_title, False, False, 0)
131,14 → 127,14
scroller.set_shadow_type(Gtk.ShadowType.IN)
scroller.set_hexpand(True)
scroller.set_vexpand(True)
a_text = self.gui.add_widget('gtk_textview_annotation_text', Gtk.TextView())
a_text = self.srvgui.add_widget('gtk_textview_annotation_text', Gtk.TextView())
a_text.set_wrap_mode(Gtk.WrapMode.WORD)
a_text.modify_font(Pango.FontDescription('Monospace 10'))
a_text.set_vexpand(True)
a_text.set_left_margin (6)
a_text.set_top_margin (6)
a_text.set_right_margin (6)
a_text.set_bottom_margin (6)
a_text.set_left_margin(6)
a_text.set_top_margin(6)
a_text.set_right_margin(6)
a_text.set_bottom_margin(6)
a_textbuffer = Gtk.TextBuffer()
a_textbuffer.set_text('')
a_text.set_buffer(a_textbuffer)
153,15 → 149,15
a_type_lbl.set_xalign(1.0)
# ~ vboxr.pack_start(a_type_lbl, False, False, 0)
a_type_model = Gtk.ListStore(str)
self.gui.add_widget('annotation_type_FIXME', a_type_model.append(['FIXME']))
active = self.gui.add_widget('annotation_type_Note', a_type_model.append(['Note']))
self.gui.add_widget('annotation_type_Procedure', a_type_model.append(['Procedure']))
self.gui.add_widget('annotation_type_Snippet', a_type_model.append(['Snippet']))
self.gui.add_widget('annotation_type_Template', a_type_model.append(['Template']))
self.gui.add_widget('annotation_type_TODO', a_type_model.append(['TODO']))
self.srvgui.add_widget('annotation_type_FIXME', a_type_model.append(['FIXME']))
active = self.srvgui.add_widget('annotation_type_Note', a_type_model.append(['Note']))
self.srvgui.add_widget('annotation_type_Procedure', a_type_model.append(['Procedure']))
self.srvgui.add_widget('annotation_type_Snippet', a_type_model.append(['Snippet']))
self.srvgui.add_widget('annotation_type_Template', a_type_model.append(['Template']))
self.srvgui.add_widget('annotation_type_TODO', a_type_model.append(['TODO']))
a_type = Gtk.ComboBox.new_with_model(a_type_model)
a_type.set_active_iter(active)
self.gui.add_widget('gtk_combobox_annotation_type', a_type)
self.srvgui.add_widget('gtk_combobox_annotation_type', a_type)
renderer_type = Gtk.CellRendererText()
a_type.pack_start(renderer_type, True)
a_type.add_attribute(renderer_type, "text", 0)
174,7 → 170,7
 
 
 
# ~ calendar = self.gui.add_widget('gtk_calendar_annotation_timestamp', Gtk.Calendar())
# ~ calendar = self.srvgui.add_widget('gtk_calendar_annotation_timestamp', Gtk.Calendar())
# ~ calendar.modify_font(Pango.FontDescription('Monospace 8'))
# ~ hbox.pack_start(calendar, False, False, 0)
 
183,12 → 179,12
hbox = Gtk.HBox()
 
## url entry
a_link = self.gui.add_widget('gtk_entry_annotation_link', Gtk.Entry())
a_link = self.srvgui.add_widget('gtk_entry_annotation_link', Gtk.Entry())
a_link.set_placeholder_text("Type a url here...")
hbox.pack_start(a_link, True, True, 3)
 
## url button
a_link_button = self.gui.add_widget('gtk_link_button_annotation_link', Gtk.LinkButton())
a_link_button = self.srvgui.add_widget('gtk_link_button_annotation_link', Gtk.LinkButton())
a_link_button.set_relief(Gtk.ReliefStyle.NORMAL)
a_link_button.set_label('Visit')
hbox.pack_start(a_link_button, False, False, 3)
195,18 → 191,18
 
# url type
a_link_type_model = Gtk.ListStore(str)
self.gui.add_widget('annotation_link_type_Intranet', a_link_type_model.append(['Intranet']))
self.gui.add_widget('annotation_link_type_SAP Blog', a_link_type_model.append(['SAP Blog']))
self.gui.add_widget('annotation_link_type_SAP Document', a_link_type_model.append(['SAP Document']))
self.gui.add_widget('annotation_link_type_SAP Help', a_link_type_model.append(['SAP Help']))
self.gui.add_widget('annotation_link_type_SAP Incident', a_link_type_model.append(['SAP Incident']))
self.gui.add_widget('annotation_link_type_SAP Questions and Answers', a_link_type_model.append(['SAP Questions and Answers']))
self.gui.add_widget('annotation_link_type_SAP Wiki', a_link_type_model.append(['SAP Wiki']))
self.srvgui.add_widget('annotation_link_type_Intranet', a_link_type_model.append(['Intranet']))
self.srvgui.add_widget('annotation_link_type_SAP Blog', a_link_type_model.append(['SAP Blog']))
self.srvgui.add_widget('annotation_link_type_SAP Document', a_link_type_model.append(['SAP Document']))
self.srvgui.add_widget('annotation_link_type_SAP Help', a_link_type_model.append(['SAP Help']))
self.srvgui.add_widget('annotation_link_type_SAP Incident', a_link_type_model.append(['SAP Incident']))
self.srvgui.add_widget('annotation_link_type_SAP Questions and Answers', a_link_type_model.append(['SAP Questions and Answers']))
self.srvgui.add_widget('annotation_link_type_SAP Wiki', a_link_type_model.append(['SAP Wiki']))
# ~ 'Knowledge Base Search'
active = self.gui.add_widget('annotation_link_type_Website', a_link_type_model.append(['Website']))
active = self.srvgui.add_widget('annotation_link_type_Website', a_link_type_model.append(['Website']))
a_link_type = Gtk.ComboBox.new_with_model(a_link_type_model)
a_link_type.set_active_iter(active)
self.gui.add_widget('gtk_combobox_annotation_link_type', a_link_type)
self.srvgui.add_widget('gtk_combobox_annotation_link_type', a_link_type)
renderer_text = Gtk.CellRendererText()
a_link_type.pack_start(renderer_text, True)
a_link_type.add_attribute(renderer_text, "text", 0)
222,15 → 218,15
def __setup_footer(self):
# Buttons Accept/Cancel
hbox = Gtk.HBox()
accept = self.gui.add_widget('gtk_button_accept_annotation', Gtk.Button('Accept'))
accept.connect('clicked', self.cb.action_annotation_accept, self.sid)
accept = self.srvgui.add_widget('gtk_button_accept_annotation', Gtk.Button('Accept'))
accept.connect('clicked', self.srvclb.action_annotation_accept, self.sid)
accept.set_property('always-show-image', True)
icon = self.im.get_new_image_icon('basico-check-accept', 24, 24)
icon = self.srvicm.get_new_image_icon('basico-check-accept', 24, 24)
accept.set_image(icon)
cancel = self.gui.add_widget('gtk_button_cancel_annotation', Gtk.Button('Cancel'))
cancel.connect('clicked', self.cb.action_annotation_cancel)
cancel = self.srvgui.add_widget('gtk_button_cancel_annotation', Gtk.Button('Cancel'))
cancel.connect('clicked', self.srvclb.action_annotation_cancel)
cancel.set_property('always-show-image', True)
icon = self.im.get_new_image_icon('basico-check-cancel', 24, 24)
icon = self.srvicm.get_new_image_icon('basico-check-cancel', 24, 24)
cancel.set_image(icon)
hbox.pack_start(accept, True, False, 3)
hbox.pack_start(cancel, True, False, 3)
238,19 → 234,28
 
 
def set_aid_to_widget(self, aid):
a_aid = self.gui.get_widget('gtk_label_aid')
"""
C:237, 4: Missing method docstring (missing-docstring)
"""
a_aid = self.srvgui.get_widget('gtk_label_aid')
a_aid.set_text(aid)
 
 
def get_aid_from_widget(self):
a_aid = self.gui.get_widget('gtk_label_aid')
"""
C:237, 4: Missing method docstring (missing-docstring)
"""
a_aid = self.srvgui.get_widget('gtk_label_aid')
return a_aid.get_text()
 
 
def set_metadata_to_widget(self, aid, action):
"""
C:237, 4: Missing method docstring (missing-docstring)
"""
self.set_aid_to_widget(aid)
sid = self.annot.get_sid(aid)
title = self.gui.get_widget('gtk_label_annotation_sid')
sid = self.srvant.get_sid(aid)
title = self.srvgui.get_widget('gtk_label_annotation_sid')
if sid == '0000000000':
title.set_markup('<big><b>Annotation</b></big>')
else:
259,45 → 264,47
if action == 'create':
pass
elif action == 'edit':
annotation = self.annot.get_metadata_from_file(aid)
annotation = self.srvant.get_metadata_from_file(aid)
if annotation is not None:
ANNOTATION_FILE_CONTENT = LPATH['ANNOTATIONS'] + aid + '.adoc'
timestamp = self.utils.get_datetime(annotation['timestamp'])
a_wdg_aid = self.gui.get_widget('gtk_label_aid')
a_wdg_timestamp = self.gui.get_widget('gtk_label_timestamp')
a_wdg_title = self.gui.get_widget('gtk_entry_annotation_title')
a_wdg_type = self.gui.get_widget('gtk_combobox_annotation_type')
a_wdg_human_timestamp = self.gui.get_widget('gtk_label_human_timestamp')
a_wdg_text = self.gui.get_widget('gtk_textview_annotation_text')
a_wdg_link = self.gui.get_widget('gtk_entry_annotation_link')
a_wdg_link_button = self.gui.get_widget('gtk_link_button_annotation_link')
a_wdg_link_type = self.gui.get_widget('gtk_combobox_annotation_link_type')
# ~ a_wdg_cal = self.gui.get_widget('gtk_calendar_annotation_timestamp')
a_wdg_aid = self.srvgui.get_widget('gtk_label_aid')
a_wdg_timestamp = self.srvgui.get_widget('gtk_label_timestamp')
a_wdg_title = self.srvgui.get_widget('gtk_entry_annotation_title')
a_wdg_type = self.srvgui.get_widget('gtk_combobox_annotation_type')
a_wdg_human_timestamp = self.srvgui.get_widget('gtk_label_human_timestamp')
a_wdg_text = self.srvgui.get_widget('gtk_textview_annotation_text')
a_wdg_link = self.srvgui.get_widget('gtk_entry_annotation_link')
a_wdg_link_button = self.srvgui.get_widget('gtk_link_button_annotation_link')
a_wdg_link_type = self.srvgui.get_widget('gtk_combobox_annotation_link_type')
# ~ a_wdg_cal = self.srvgui.get_widget('gtk_calendar_annotation_timestamp')
 
a_wdg_aid.set_text(annotation['aid'])
# ~ a_wdg_timestamp.set_text(self.utils.timestamp())
# ~ a_wdg_timestamp.set_text(self.srvutl.timestamp())
a_wdg_timestamp.set_text(annotation['timestamp'])
a_wdg_title.set_text(annotation['title'])
a_wdg_type.set_active_iter(self.gui.get_widget('annotation_type_%s' % annotation['type']))
self.uif.set_textview_text(a_wdg_text, open(ANNOTATION_FILE_CONTENT).read())
a_wdg_type.set_active_iter(self.srvgui.get_widget('annotation_type_%s' % annotation['type']))
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'])
a_wdg_link_type.set_active_iter(self.gui.get_widget('annotation_link_type_%s' % annotation['link_type']))
human_timestamp = self.utils.get_human_date_from_timestamp(annotation['timestamp'])
a_wdg_link_type.set_active_iter(self.srvgui.get_widget('annotation_link_type_%s' % annotation['link_type']))
human_timestamp = self.srvutl.get_human_date_from_timestamp(annotation['timestamp'])
a_wdg_human_timestamp.set_text(human_timestamp)
# ~ a_wdg_cal.select_month(timestamp.month-1, timestamp.year)
# ~ a_wdg_cal.select_day(timestamp.day)
 
 
def get_metadata_from_widget(self, aid):
def get_metadata_from_widget(self):
"""
C:237, 4: Missing method docstring (missing-docstring)
"""
annotation = {}
a_wdg_aid = self.gui.get_widget('gtk_label_aid')
a_wdg_timestamp = self.gui.get_widget('gtk_label_timestamp')
a_wdg_title = self.gui.get_widget('gtk_entry_annotation_title')
a_wdg_type = self.gui.get_widget('gtk_combobox_annotation_type')
a_wdg_text = self.gui.get_widget('gtk_textview_annotation_text')
a_wdg_link = self.gui.get_widget('gtk_entry_annotation_link')
a_wdg_link_type = self.gui.get_widget('gtk_combobox_annotation_link_type')
a_wdg_aid = self.srvgui.get_widget('gtk_label_aid')
a_wdg_timestamp = self.srvgui.get_widget('gtk_label_timestamp')
a_wdg_title = self.srvgui.get_widget('gtk_entry_annotation_title')
a_wdg_type = self.srvgui.get_widget('gtk_combobox_annotation_type')
a_wdg_text = self.srvgui.get_widget('gtk_textview_annotation_text')
a_wdg_link = self.srvgui.get_widget('gtk_entry_annotation_link')
a_wdg_link_type = self.srvgui.get_widget('gtk_combobox_annotation_link_type')
 
annotation['aid'] = a_wdg_aid.get_text()
annotation['timestamp'] = a_wdg_timestamp.get_text()
304,9 → 311,9
annotation['title'] = a_wdg_title.get_text()
annotation['component'] = 'Annotation'
annotation['category'] = ''
annotation['type'] = self.uif.get_combobox_text(a_wdg_type, 0)
annotation['content'] = self.uif.get_textview_text(a_wdg_text)
annotation['type'] = self.srvuif.get_combobox_text(a_wdg_type, 0)
annotation['content'] = self.srvuif.get_textview_text(a_wdg_text)
annotation['link'] = a_wdg_link.get_text()
annotation['link_type'] = self.uif.get_combobox_text(a_wdg_link_type, 0)
annotation['link_type'] = self.srvuif.get_combobox_text(a_wdg_link_type, 0)
 
return annotation