Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Added support for identifiers sorting, and selection

This commit is contained in:
Arnar Flatberg 2007-08-22 13:41:04 +00:00
parent ffe1ce6319
commit 01ef4bdedd
1 changed files with 39 additions and 2 deletions

View File

@ -27,6 +27,8 @@ class IdListController:
def __init__(self, idlist):
self._idlist = idlist
self._idlist.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
self._idlist.set_rubber_banding(True)
# dimname: current_annotation_name
self._annotation = {}
@ -37,6 +39,7 @@ class IdListController:
# id, annotation
self._idstore = gtk.ListStore(gobject.TYPE_STRING,
gobject.TYPE_STRING,)
self._idstore.set_sort_func(0, self._numeric_compare)
# Annotation tree column
self._annotation_column = None
@ -46,6 +49,9 @@ class IdListController:
renderer = gtk.CellRendererText()
dim_column = gtk.TreeViewColumn('Identifiers', renderer, text=0)
dim_column.set_sort_indicator(True)
dim_column.set_sort_column_id(0)
dim_column.set_sort_order(gtk.SORT_ASCENDING)
idlist.insert_column(dim_column, 0)
idlist.connect('button-press-event', self._button_pressed)
@ -53,7 +59,7 @@ class IdListController:
menu = self._menu = SimpleMenu()
menu.add_simple_item('Import...', self._on_import_list)
menu.add_simple_item('Export...', self._on_export_list)
menu.add_simple_item('Add to selection', self._on_make_selection)
item = gtk.MenuItem('Show annotations')
menu.append(item)
item.show()
@ -95,6 +101,9 @@ class IdListController:
if self._annotation_column == None:
renderer = gtk.CellRendererText()
col = gtk.TreeViewColumn(annotation, renderer, text=1)
col.set_sort_indicator(True)
col.set_sort_column_id(1)
col.set_sort_order(gtk.SORT_ASCENDING)
self._idlist.append_column(col)
self._annotation_column = col
self._annotation_column.set_title(annotation)
@ -111,7 +120,7 @@ class IdListController:
return
# Otherwise show selection, possibly with annotations.
id_list = list(selection[self._dimension])
#id_list = list(selection[self._dimension])
idlist = list(selection[self._dimension])
if self._annotation[self._dimension] != None:
annlist = annotations.get_dim_annotations(self._dimension,
@ -148,6 +157,7 @@ class IdListController:
item.show()
self._menu_ann.set_submenu(annotations_menu)
def import_annotation_file(self):
"""Pops up a file dialog and ask the user to select the annotation
@ -172,6 +182,25 @@ class IdListController:
##
## GTK Callbacks
##
def _numeric_compare(self, treemodel, iter1, iter2):
column = treemodel.get_sort_column_id()[0]
item1 = treemodel.get_value(iter1, column)
item2 = treemodel.get_value(iter2, column)
try:
item1 = float(item1)
item2 = float(item2)
except:
logger.log("notice", "Could not convert to float: %s, %s" %(item1, item2))
if item1==item2: return 0
if item1>item2:
return 1
else:
return -1
def _popup_menu(self, *rest):
self._update_annotations_menu()
self._menu.popup(None, None, None, 0, 0)
@ -189,6 +218,14 @@ class IdListController:
def _on_import_list(self, menuitem):
self.import_annotation_file()
def _on_make_selection(self, menuitem):
selection = self._idlist.get_selection()
model, paths = selection.get_selected_rows()
if paths==None: return
iters = [self._idstore.get_iter(p) for p in paths]
ids = [self._idstore.get_value(i, 0) for i in iters]
main.project.set_selection(self._dimension, ids)
class SelectionListController: