Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Cleanup of selection browser module. Added comments, fixed some bits of code.

This commit is contained in:
Einar Ryeng 2007-02-26 14:35:31 +00:00
parent c0bbe24c39
commit 537dc9f0ec
1 changed files with 48 additions and 25 deletions

View File

@ -141,6 +141,26 @@ class IdListController:
self._menu_ann.set_submenu(annotations_menu) 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
file to be loaded. Only one file can be selected. The file is loaded
into a annotations.AnnotationDictHandler object"""
dialog = gtk.FileChooserDialog('Load annotations')
dialog.set_action(gtk.FILE_CHOOSER_ACTION_OPEN)
dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK)
dialog.set_select_multiple(True)
retval = dialog.run()
if retval in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]:
pass
elif retval == gtk.RESPONSE_OK:
for filename in dialog.get_filenames():
annotations.read_annotations_file(filename)
else:
print "unknown; ", retval
dialog.destroy()
## ##
## GTK Callbacks ## GTK Callbacks
## ##
@ -160,20 +180,7 @@ class IdListController:
print "export stuff" print "export stuff"
def _on_import_list(self, menuitem): def _on_import_list(self, menuitem):
dialog = gtk.FileChooserDialog('Load annotations') self.import_annotation_file()
dialog.set_action(gtk.FILE_CHOOSER_ACTION_OPEN)
dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK)
dialog.set_select_multiple(True)
retval = dialog.run()
if retval in [gtk.RESPONSE_CANCEL, gtk.RESPONSE_DELETE_EVENT]:
pass
elif retval == gtk.RESPONSE_OK:
for filename in dialog.get_filenames():
annotations.read_annotations_file(filename)
else:
print "unknown; ", retval
dialog.destroy()
class SelectionListController: class SelectionListController:
@ -207,23 +214,29 @@ class SelectionListController:
# Selections context menu # Selections context menu
self._seltree_menu = SimpleMenu() self._seltree_menu = SimpleMenu()
self._seltree_menu.add_simple_item('Sort by selection', self._on_seltree_sort) self._seltree_menu.add_simple_item('Sort by selection',
self._seltree_menu.add_simple_item('Show details', self._enable_details, True) self._on_seltree_sort)
self._seltree_menu.add_simple_item('Hide details', self._enable_details, False) self._seltree_menu.add_simple_item('Show details',
# self._seltree_menu.add_simple_item('Copy selection', self._on_seltree_copy_selection) self._enable_details, True)
self._seltree_menu.add_simple_item('Hide details',
self._enable_details, False)
# #
# Public interface # Public interface
# #
def set_project(self, project): def set_project(self, project):
"""Dependency injection.""" """Dependency injection."""
self.project = project self.project = project
project.add_selection_observer(self) project.add_selection_observer(self)
def set_dimlist_controller(self, dimlist_controller): def set_dimlist_controller(self, dimlist_controller):
"""Dependency injection of the dimension list controller."""
self._dimlist_controller = dimlist_controller self._dimlist_controller = dimlist_controller
def set_dimension(self, dim): def set_dimension(self, dim):
"""Set the current dimension, changing the model of the treeview
to match dim. After this the current dimension of the identifier list
is updated."""
self._ensure_selection_store(dim) self._ensure_selection_store(dim)
self._seltree.set_model(self._sel_stores[dim]) self._seltree.set_model(self._sel_stores[dim])
self._idlist_controller.set_dimension(dim) self._idlist_controller.set_dimension(dim)
@ -246,6 +259,10 @@ class SelectionListController:
row[3] = row[4] = len(selection[dim]) row[3] = row[4] = len(selection[dim])
def add_dataset(self, dataset): def add_dataset(self, dataset):
"""Converts a CategoryDataset to Selection objects and adds it to
the selection tree. The name of the dataset will be the parent
node in the tree, and the identifers along the first axis will
be added as the names of the subselections."""
dim_name = dataset.get_dim_name(0) dim_name = dataset.get_dim_name(0)
self._ensure_selection_store(dim_name) self._ensure_selection_store(dim_name)
store = self._sel_stores[dim_name] store = self._sel_stores[dim_name]
@ -402,6 +419,7 @@ class SelectionListController:
if isinstance(obj, dataset.CategoryDataset): if isinstance(obj, dataset.CategoryDataset):
self._sort_selections(obj) self._sort_selections(obj)
class DimListController: class DimListController:
def __init__(self, dimlist, seltree_controller): def __init__(self, dimlist, seltree_controller):
@ -458,6 +476,7 @@ class DimListController:
return None return None
def set_dimension(self, dimname): def set_dimension(self, dimname):
"""Sets the current dimension."""
self._current_dim = dimname self._current_dim = dimname
dim = self.get_dimension(self._current_dim) dim = self.get_dimension(self._current_dim)
@ -481,24 +500,27 @@ class DimListController:
# Private interface # Private interface
# #
def _dimension_filter(self, store, row): def _dimension_filter(self, store, row):
"""Filters out dimension with underscore prefix""" """Filters out dimensions with underscore prefix."""
visible = False visible = False
name = store.get_value(row, 0) name = store.get_value(row, 0)
if name != None: if name != None:
visible = name[0]!="_" visible = name[0]!="_"
#print (name, visible)
return visible return visible
def _on_dim_hide(self, menuitem):
self.dimstore_filter.refilter()
self.dimlist.set_model(self.dimstore_filter)
def _on_dim_show(self, menuitem):
self.dimlist.set_model(self.dimstore)
# #
# GTK Callbacks. # GTK Callbacks.
# #
def _on_dim_hide(self, menuitem):
"""Menu item callback function which hides underscore prefixed
dimensions."""
self.dimstore_filter.refilter()
self.dimlist.set_model(self.dimstore_filter)
def _on_dim_show(self, menuitem):
"""Menu item callback function that shows underscore prefixed
dimension names."""
self.dimlist.set_model(self.dimstore)
def _dim_cursor_changed(self, widget): def _dim_cursor_changed(self, widget):
cursor = self.dimlist.get_cursor()[0] cursor = self.dimlist.get_cursor()[0]
i = self.dimlist.get_model().get_iter(cursor) i = self.dimlist.get_model().get_iter(cursor)
@ -511,3 +533,4 @@ class DimListController:
def _dimlist_button_pressed(self, widget, event): def _dimlist_button_pressed(self, widget, event):
if event.button == 3: if event.button == 3:
self._dimlist_menu.popup(None, None, None, event.button, event.time) self._dimlist_menu.popup(None, None, None, event.button, event.time)