Subversion Repositories basico

Compare Revisions

Ignore whitespace Rev 382 → Rev 383

/branches/BR-0.4/basico/services/srv_annotations.py
195,11 → 195,13
 
def get_title(self, aid):
ANNOTATION_FILE = LPATH['ANNOTATIONS'] + aid + '.json'
with open(ANNOTATION_FILE, 'r') as fa:
metadata = json.load(fa)
return escape(metadata['Title'])
try:
with open(ANNOTATION_FILE, 'r') as fa:
metadata = json.load(fa)
return escape(metadata['Title'])
except:
return None
 
 
def get_content_file(self, aid):
return LPATH['ANNOTATIONS'] + aid + '.adoc'
 
/branches/BR-0.4/basico/services/srv_callbacks.py
121,6 → 121,7
self.log.info("Browsing SAP Note %d" % int(sid))
SAP_NOTE_URL = self.srvstg.get('SAP', 'SAP_NOTE_URL')
url = SAP_NOTE_URL % sid
self.srvuif.grab_focus()
self.srvutl.browse(url)
 
 
377,7 → 378,8
elif action == 'preview':
widget_annotation.set_visible_stack('preview')
 
self.log.debug("%s %s", action, aid)
self.log.debug("Action: %s annotation with Id: %s", action, aid)
 
widget_annotation.set_metadata_to_widget(aid, action)
self.srvuif.set_widget_visibility('gtk_vbox_container_annotations', True)
self.srvuif.grab_focus()
386,9 → 388,11
def gui_show_popover(self, button, popover):
self.srvgui.set_key_value('LAST_POPOVER', popover)
if popover.get_visible():
popover.popdown()
popover.hide()
else:
popover.show_all()
popover.popup()
 
 
def switch_bookmark_current_view(self, *args):
/branches/BR-0.4/basico/services/srv_database.py
288,7 → 288,7
component = ''
metadata = self.get_sapnote_metadata(sid)
if metadata is not None:
component = metadata['component-key']
component = metadata['componentkey']
 
return component
 
/branches/BR-0.4/basico/services/srv_uif.py
173,23 → 173,24
dialog.set_size_request(800, 600);
content_area = dialog.get_content_area()
vbox = Gtk.VBox()
label = Gtk.Label()
label.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
label.set_property('selectable', True)
label.set_xalign(0.0)
label.grab_focus()
msg = '\t<b>You are about to delete %d SAP Notes:</b>' % len(bag)
scr = Gtk.ScrolledWindow()
scr.set_shadow_type(Gtk.ShadowType.NONE)
scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
# ~ label = Gtk.Label()
# ~ label.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
# ~ label.set_property('selectable', True)
# ~ label.set_xalign(0.0)
# ~ label.grab_focus()
# ~ msg = '\t<b>You are about to delete %d SAP Notes:</b>' % len(bag)
# ~ scr = Gtk.ScrolledWindow()
# ~ scr.set_shadow_type(Gtk.ShadowType.NONE)
# ~ scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
 
msg += '\n\n'
for sid in bag:
msg += '\t%010d - %s\t\n' % (int(sid), escape(self.srvdtb.get_title(sid)))
msg += '\n'
label.set_markup(msg)
scr.add(label)
vbox.pack_start(scr, True, True, 0)
# ~ msg += '\n\n'
# ~ for sid in bag:
# ~ msg += '\t%010d - %s\t\n' % (int(sid), escape(self.srvdtb.get_title(sid)))
# ~ msg += '\n'
# ~ label.set_markup(msg)
# ~ scr.add(label)
sapnotesbox = self.sapnotebox(bag)
vbox.pack_start(sapnotesbox, True, True, 0)
content_area.pack_start(vbox, True, True, 0)
content_area.show_all()
dialog.set_image(icon)
317,3 → 318,111
return folder
 
 
def sapnotebox(self, lsid):
box = Gtk.Box()
box.set_property('margin', 6)
scr = Gtk.ScrolledWindow()
scr.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
scr.set_shadow_type(Gtk.ShadowType.IN)
treeview = Gtk.TreeView()
scr.add(treeview)
box.pack_start(scr, True, True, 0)
 
model = Gtk.ListStore(
str, # sid
str, # title
str, # component
)
 
# SAP Note Id
renderer_sid = Gtk.CellRendererText()
renderer_sid.set_property('xalign', 1.0)
renderer_sid.set_property('height', 36)
# ~ renderer_sid.set_property('background', '#F0E3E3')
column_sid = Gtk.TreeViewColumn('SAP Note', renderer_sid, markup=0)
column_sid.set_visible(True)
column_sid.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
column_sid.set_expand(False)
column_sid.set_clickable(True)
column_sid.set_sort_indicator(True)
column_sid.set_sort_column_id(0)
column_sid.set_sort_order(Gtk.SortType.ASCENDING)
model.set_sort_column_id(0, Gtk.SortType.ASCENDING)
treeview.append_column(column_sid)
 
# SAP Note title
renderer_title = Gtk.CellRendererText()
renderer_title.set_property('xalign', 0.0)
renderer_title.set_property('height', 36)
renderer_title.set_property('ellipsize', Pango.EllipsizeMode.MIDDLE)
# ~ renderer_title.set_property('background', '#FFFEEA')
column_title = Gtk.TreeViewColumn('Title', renderer_title, markup=1)
column_title.set_visible(True)
column_title.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
column_title.set_expand(True)
column_title.set_clickable(True)
column_title.set_sort_indicator(True)
column_title.set_sort_column_id(1)
column_title.set_sort_order(Gtk.SortType.ASCENDING)
model.set_sort_column_id(1, Gtk.SortType.ASCENDING)
treeview.append_column(column_title)
 
# SAP Note component
renderer_component = Gtk.CellRendererText()
renderer_component.set_property('xalign', 0.0)
renderer_component.set_property('height', 36)
# ~ renderer_component.set_property('background', '#F0E3E3')
column_component = Gtk.TreeViewColumn('Component', renderer_component, markup=2)
column_component.set_visible(True)
column_component.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
column_component.set_expand(False)
column_component.set_clickable(True)
column_component.set_sort_indicator(True)
column_component.set_sort_column_id(1)
column_component.set_sort_order(Gtk.SortType.ASCENDING)
model.set_sort_column_id(2, Gtk.SortType.ASCENDING)
treeview.append_column(column_component)
 
# Treeview properties
treeview.set_can_focus(False)
treeview.set_enable_tree_lines(True)
treeview.set_headers_visible(True)
treeview.set_enable_search(True)
treeview.set_hover_selection(False)
treeview.set_grid_lines(Gtk.TreeViewGridLines.NONE)
treeview.set_enable_tree_lines(True)
treeview.set_level_indentation(10)
 
# TreeView sorting
def sort_function(model, row1, row2, user_data):
sort_column = 0
 
value1 = model.get_value(row1, sort_column)
value2 = model.get_value(row2, sort_column)
 
if value1 < value2:
return -1
elif value1 == value2:
return 0
else:
return 1
 
self.sorted_model = Gtk.TreeModelSort(model=model)
self.sorted_model.set_sort_func(0, sort_function, None)
 
# Selection
selection = treeview.get_selection()
selection.set_mode(Gtk.SelectionMode.NONE)
 
# Set model (filtered and sorted)
treeview.set_model(self.sorted_model)
 
for sid in lsid:
ssid = str(int(sid))
title = self.srvdtb.get_title(sid)
component = self.srvdtb.get_component(sid)
model.append([ssid, escape(title), component])
 
box.show_all()
 
return box
/branches/BR-0.4/basico/widgets/wdg_visor_annotations.py
561,7 → 561,7
annotations = self.get_bag()
if annotations is None:
annotations = self.srvant.get_all()
self.log.debug("Displaying all annotations")
# ~ self.log.debug("Displaying all annotations")
else:
self.log.debug("Displaying last query")
else:
638,7 → 638,7
self.treeview.set_model(self.sorted_model)
self.sort_by_timestamp()
self.update_total_annotations_count()
self.log.debug("Visor updated")
# ~ self.log.debug("Visor updated")
 
 
def show_widgets(self):
/branches/BR-0.4/basico/widgets/wdg_visor_attachments.py
65,8 → 65,8
self.srvutl = self.get_service("Utils")
self.srvatc = self.get_service('Attachment')
self.srvant = self.get_service('Annotation')
 
 
def get_treeview(self):
return self.treeview
 
94,7 → 94,7
pgb.set_show_text(True)
hbox.pack_start(pgb, True, True, 0)
self.pack_start(hbox, False, False, 0)
 
# Setup model
self.model = Gtk.TreeStore(
str, # TID (Attachment ID)
107,7 → 107,7
str, # Added (timestamp)
str, # Size
int, # Size (int)
str, # Mimetype
str, # Mimetype
)
 
# Setup columns
171,7 → 171,7
self.column_description.set_sort_indicator(True)
self.column_description.set_sort_column_id(3)
self.treeview.append_column(self.column_description)
 
# Attachment Title
self.renderer_title = Gtk.CellRendererText()
self.renderer_title.set_property('background', '#FFFEEA')
202,7 → 202,7
self.column_sid.set_sort_indicator(True)
self.column_sid.set_sort_column_id(5)
self.treeview.append_column(self.column_sid)
 
# Added
self.renderer_added = Gtk.CellRendererText()
self.renderer_added.set_property('background', '#E3F1E3')
249,7 → 249,7
self.column_annotation = Gtk.TreeViewColumn('Mimetype', self.renderer_annotation, markup=10)
self.column_annotation.set_visible(False)
self.treeview.append_column(self.column_annotation)
 
# Treeview properties
self.treeview.set_can_focus(False)
self.treeview.set_enable_tree_lines(True)
260,7 → 260,7
self.treeview.set_enable_tree_lines(True)
self.treeview.set_level_indentation(10)
self.treeview.connect('button_press_event', self.row_right_click)
 
# DOC: In order to have a Gtk.Widged with sorting and filtering
# capabilities, you have to filter the model first, and use this
# new model to create the sorted model. Then, attach the sorted
417,7 → 417,7
sid = str(int(sid))
if sid == '0':
sid = ''
node = self.get_node( metadata['TID'],
node = self.get_node( metadata['TID'],
self.srvicm.find_mime_type_pixbuf(metadata['Mimetype'], 36, 36),
metadata['Doctype'],
metadata['Description'],
426,8 → 426,8
self.srvutl.fuzzy_date_from_timestamp(metadata['Created']),
metadata['Created'],
str(self.srvutl.get_human_sizes(int(metadata['Size']))),
int(metadata['Size']),
metadata['Mimetype'],
int(metadata['Size']),
metadata['Mimetype'],
)
nodes.append(node)
except Exception as error:
445,7 → 445,7
self.treeview.set_model(self.sorted_model)
self.sort_by_timestamp()
self.update_total_attachments_count()
self.log.debug("Visor updated")
# ~ self.log.debug("Visor updated")
 
def show_widgets(self):
self.srvuif.set_widget_visibility('gtk_label_total_notes', True)
518,7 → 518,7
button.show_all()
button.connect('clicked', self.srvclb.gui_jump_to_annotation, aid_file)
box.pack_start(button, False, False, 0)
 
# Separator
separator = Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL)
box.pack_start(separator, True, True, 0)
528,7 → 528,7
button.show_all()
button.connect('clicked', self.download, tid)
box.pack_start(button, False, False, 0)
 
return box
 
 
/branches/BR-0.4/basico/widgets/wdg_visor_sapnotes.py
73,7 → 73,7
self.pack_start(scr, True, True, 0)
 
# Setup model
self.model = Gtk.TreeStore(
self.model = Gtk.ListStore(
int, # key
Pixbuf, # Icon
int, # checkbox
140,8 → 140,8
self.renderer_sid.set_property('xalign', 1.0)
self.renderer_sid.set_property('height', 36)
self.renderer_sid.set_property('background', '#F0E3E3')
self.column_sid = Gtk.TreeViewColumn('SAP Note Id', self.renderer_sid, markup=3)
widget = get_column_header_widget('SAP Note Id', 'basico-sid')
self.column_sid = Gtk.TreeViewColumn('SAP Note', self.renderer_sid, markup=3)
widget = get_column_header_widget('SAP Note', 'basico-sid')
self.column_sid.set_widget(widget)
self.column_sid.set_visible(True)
self.column_sid.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
440,53 → 440,53
'',
timestamp
)
pid = self.model.append(None, node)
pid = self.model.append(node)
 
# Load annotations
files = self.srvant.get_by_sid(metadata['id'])
for fname in files:
with open(fname, 'r') as fa:
annotation = json.load(fa)
atype = annotation['Type']
try:
icon = self.icons['type']['%s' % atype.lower()]
except:
icon = None
node = self.get_node( 0,
icon,
False,
'',
annotation['Title'],
annotation['Component'],
'',
annotation['Type'],
'',
self.srvutl.fuzzy_date_from_timestamp(annotation['Timestamp']),
annotation['AID'],
annotation['Timestamp']
)
self.model.append(pid, node)
# ~ files = self.srvant.get_by_sid(metadata['id'])
# ~ for fname in files:
# ~ with open(fname, 'r') as fa:
# ~ annotation = json.load(fa)
# ~ atype = annotation['Type']
# ~ try:
# ~ icon = self.icons['type']['%s' % atype.lower()]
# ~ except:
# ~ icon = None
# ~ node = self.get_node( 0,
# ~ icon,
# ~ False,
# ~ '',
# ~ annotation['Title'],
# ~ annotation['Component'],
# ~ '',
# ~ annotation['Type'],
# ~ '',
# ~ self.srvutl.fuzzy_date_from_timestamp(annotation['Timestamp']),
# ~ annotation['AID'],
# ~ annotation['Timestamp']
# ~ )
# ~ self.model.append(pid, node)
 
# Load attachments
files = self.srvatc.get_by_sid(metadata['id'])
for fname in files:
with open(fname, 'r') as ft:
attachment = json.load(ft)
icon = self.srvicm.get_pixbuf_icon('basico-attachment')
node = self.get_node( 0,
icon,
False,
'',
attachment['Title'],
'Attachment',
'',
attachment['Description'],
'',
self.srvutl.fuzzy_date_from_timestamp(attachment['Created']),
attachment['TID'],
attachment['Created']
)
self.model.append(pid, node)
# ~ files = self.srvatc.get_by_sid(metadata['id'])
# ~ for fname in files:
# ~ with open(fname, 'r') as ft:
# ~ attachment = json.load(ft)
# ~ icon = self.srvicm.get_pixbuf_icon('basico-attachment')
# ~ node = self.get_node( 0,
# ~ icon,
# ~ False,
# ~ '',
# ~ attachment['Title'],
# ~ 'Attachment',
# ~ '',
# ~ attachment['Description'],
# ~ '',
# ~ self.srvutl.fuzzy_date_from_timestamp(attachment['Created']),
# ~ attachment['TID'],
# ~ attachment['Created']
# ~ )
# ~ self.model.append(pid, node)
 
self.treeview.set_model(self.sorted_model)
self.update_total_sapnotes_count()
493,7 → 493,7
self.show_widgets()
stack = self.srvgui.get_widget('gtk_stack_main')
stack.set_visible_child_name('visor')
self.log.debug("Visor updated")
# ~ self.log.debug("Visor updated")
 
def show_widgets(self):
self.srvuif.set_widget_visibility('gtk_label_total_notes', True)
564,14 → 564,31
button.connect('clicked', self.clb_create_annotation, sid)
box.pack_start(button, False, False, 0)
 
fbox = Gtk.VBox()
frame = Gtk.Frame()
frame.set_border_width(3)
label = Gtk.Label()
label.set_markup(' <b>Attachments</b> ')
frame.set_label_widget(label)
# Popover button "Add attachments"
button = get_popover_button("<b>Add attachments</b> to SAP Note %d" % isid, 'basico-attachment')
button = get_popover_button("<b>Add</b> new to SAP Note %d" % isid, 'basico-attachment')
button.set_property('margin', 3)
button.show_all()
button.connect('clicked', self.srvclb.gui_attachment_add_to_sapnote, sid)
box.pack_start(button, False, False, 0)
fbox.pack_start(button, False, False, 0)
 
# Popover button "Show attachments"
if len(self.srvatc.get_by_sid(sid)) > 0:
button = get_popover_button("<b>Show</b> linked to SAP Note %d" % isid, 'basico-attachment')
button.set_property('margin', 3)
button.show_all()
# ~ button.connect('clicked', self.srvclb.gui_attachment_show_, sid)
fbox.pack_start(button, False, False, 0)
frame.add(fbox)
box.pack_start(frame, False, False, 0)
 
# Popover button "Open SAP Note"
button = get_popover_button("<b>Browse</b> SAP Note %d" % isid, 'basico-browse')
button = get_popover_button("<b>Browse</b> SAP Note %d" % isid, 'basico-preview')
button.connect('clicked', self.srvclb.sapnote_browse, sid)
box.pack_start(button, False, False, 0)