From 537dc9f0ecd5800d84344ef00f1ba48149c74bb1 Mon Sep 17 00:00:00 2001 From: einarr Date: Mon, 26 Feb 2007 14:35:31 +0000 Subject: [PATCH] Cleanup of selection browser module. Added comments, fixed some bits of code. --- fluents/selections.py | 73 ++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/fluents/selections.py b/fluents/selections.py index 8f0470e..a1ea856 100644 --- a/fluents/selections.py +++ b/fluents/selections.py @@ -141,6 +141,26 @@ class IdListController: 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 ## @@ -160,21 +180,8 @@ class IdListController: print "export stuff" def _on_import_list(self, menuitem): - 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() - + self.import_annotation_file() + class SelectionListController: def __init__(self, seltree, idlist_controller): @@ -207,23 +214,29 @@ class SelectionListController: # Selections context menu self._seltree_menu = SimpleMenu() - self._seltree_menu.add_simple_item('Sort by selection', self._on_seltree_sort) - self._seltree_menu.add_simple_item('Show details', self._enable_details, True) - self._seltree_menu.add_simple_item('Hide details', self._enable_details, False) - # self._seltree_menu.add_simple_item('Copy selection', self._on_seltree_copy_selection) + self._seltree_menu.add_simple_item('Sort by selection', + self._on_seltree_sort) + self._seltree_menu.add_simple_item('Show details', + self._enable_details, True) + self._seltree_menu.add_simple_item('Hide details', + self._enable_details, False) + # # Public interface # - def set_project(self, project): """Dependency injection.""" self.project = project project.add_selection_observer(self) def set_dimlist_controller(self, dimlist_controller): + """Dependency injection of the dimension list controller.""" self._dimlist_controller = dimlist_controller 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._seltree.set_model(self._sel_stores[dim]) self._idlist_controller.set_dimension(dim) @@ -246,6 +259,10 @@ class SelectionListController: row[3] = row[4] = len(selection[dim]) 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) self._ensure_selection_store(dim_name) store = self._sel_stores[dim_name] @@ -402,6 +419,7 @@ class SelectionListController: if isinstance(obj, dataset.CategoryDataset): self._sort_selections(obj) + class DimListController: def __init__(self, dimlist, seltree_controller): @@ -458,6 +476,7 @@ class DimListController: return None def set_dimension(self, dimname): + """Sets the current dimension.""" self._current_dim = dimname dim = self.get_dimension(self._current_dim) @@ -481,24 +500,27 @@ class DimListController: # Private interface # def _dimension_filter(self, store, row): - """Filters out dimension with underscore prefix""" + """Filters out dimensions with underscore prefix.""" visible = False name = store.get_value(row, 0) if name != None: visible = name[0]!="_" - #print (name, visible) return visible + # + # 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) - # - # GTK Callbacks. - # def _dim_cursor_changed(self, widget): cursor = self.dimlist.get_cursor()[0] i = self.dimlist.get_model().get_iter(cursor) @@ -511,3 +533,4 @@ class DimListController: def _dimlist_button_pressed(self, widget, event): if event.button == 3: self._dimlist_menu.popup(None, None, None, event.button, event.time) +