From 41e8ed511b9f7fd339440c36799a1b2431ce7434 Mon Sep 17 00:00:00 2001 From: flatberg Date: Fri, 23 Feb 2007 10:46:04 +0000 Subject: [PATCH] Fixed dim_cursor_changed to to use the correct treemodel, and added show/hide on selection details --- fluents/selections.py | 76 +++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/fluents/selections.py b/fluents/selections.py index e48b957..6629147 100644 --- a/fluents/selections.py +++ b/fluents/selections.py @@ -15,9 +15,9 @@ class SimpleMenu(gtk.Menu): def __init__(self): gtk.Menu.__init__(self) - def add_simple_item(self, title, function): + def add_simple_item(self, title, function, *args): item = gtk.MenuItem(title) - item.connect('activate', function) + item.connect('activate', function, *args) self.append(item) item.show() @@ -104,10 +104,8 @@ class IdListController: def set_selection(self, selection): """Set the selection to be displayed. The selection is not stored, the values are copied into the TreeStore""" - self._idstore.clear() id_list = list(selection[self._dimension]) - idlist = list(selection[self._dimension]) if self._annotation[self._dimension] != None: annlist = annotations.get_dim_annotations(self._dimension, @@ -182,23 +180,21 @@ class SelectionListController: def __init__(self, seltree, idlist_controller): self._seltree = seltree self._sel_stores = {} + self._detail_cols = [] self._dimension = None self._idlist_controller = idlist_controller - - # Selection renderers + self._details_on = False + + # Selection column renderer = gtk.CellRendererText() sel_column = gtk.TreeViewColumn('Selection', renderer, text=0) seltree.insert_column(sel_column, 0) - - intersect_cs_col = gtk.TreeViewColumn('In curr.sel.', renderer, text=3) - seltree.insert_column(intersect_cs_col, 1) - - n_all_col = gtk.TreeViewColumn('# All', renderer, text=4) - seltree.insert_column(n_all_col, 2) - - rank_col = gtk.TreeViewColumn('Rank', renderer, text=5) - seltree.insert_column(rank_col, 3) + # Detail columns + cols = [('In CS', 3), ('All', 4), ('Rank', 5)] + for name, store_col in cols: + self._detail_cols.append(gtk.TreeViewColumn(name, renderer, text=store_col)) + # Signals seltree.connect('row-activated', self._on_row_activated) seltree.connect('cursor-changed', self._on_cursor_changed) @@ -212,6 +208,8 @@ 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) # # Public interface @@ -239,7 +237,7 @@ class SelectionListController: if not self._get_current_selection_iter(selection, dim): n = len(selection[dim]) - values = (selection.title, selection, dim, n, n, 2) + values = (selection.title, selection, dim, n, n, 0) store.insert_after(None, None, values) def add_dataset(self, dataset): @@ -259,11 +257,10 @@ class SelectionListController: n_sel = len(selection[dim_name]) values = (selection.title, selection, dim_name, 0, n_sel, 0) store.insert_after(i, None, values) - - ## - ## Private interface - ## + # + # Private interface + # def _add_selection_store(self, dim): """Add a new gtk.TreeStore for the selections on a dimension.""" # Create new store @@ -340,6 +337,15 @@ class SelectionListController: # # GTK callbacks # + def _enable_details(self, widget, bool): + if self._details_on == bool : return + self._details_on = bool + if bool==True: + for col in self._detail_cols: + self._seltree.insert_column(col, -1) + else: + for col in self._detail_cols: + self._seltree.remove_column(col) def _drag_data_received(self, widget, drag_context, x, y, selection, info, timestamp): @@ -354,7 +360,6 @@ class SelectionListController: def _on_cursor_changed(self, widget): "Show the list of identifier strings." - store = self._sel_stores[self._dimension] p = self._seltree.get_cursor()[0] @@ -366,7 +371,6 @@ class SelectionListController: def _on_row_activated(self, widget, path, column): store = self._sel_stores[self._dimension] - i = store.get_iter(path) obj = store.get_value(i, 1) if isinstance(obj, dataset.Dataset): @@ -450,33 +454,27 @@ class DimListController: def set_dimension(self, dimname): self._current_dim = dimname - + dim = self.get_dimension(self._current_dim) path = self.dimstore.get_path(dim) if self.dimlist.get_cursor()[0] != path: self.dimlist.set_cursor(self.dimstore.get_path(dim)) - self._seltree_controller.set_dimension(dimname) def dataset_changed(self): """Callback function from Project.""" self.update_dims() - - ## - ## Private interface - ## + def update_dims(self): """Update the list of dimensions shown""" for dim in self.dim_names: if not self.get_dimension(dim): self.dimstore.insert_after(None, (dim,)) - #def _dimension_filter(self, store, row): - # """Filters out everything but the selected dimension.""" - # row_dim = store.get_value(row, 2) - # return row_dim == self._current_dim - + # + # Private interface + # def _dimension_filter(self, store, row): """Filters out dimension with underscore prefix""" visible = False @@ -493,18 +491,18 @@ class DimListController: def _on_dim_show(self, menuitem): self.dimlist.set_model(self.dimstore) - ## - ## GTK Callbacks. - ## + # + # GTK Callbacks. + # def _dim_cursor_changed(self, widget): cursor = self.dimlist.get_cursor()[0] - i = self.dimstore.get_iter(cursor) - row = self.dimstore.get_value(i, 0) + i = self.dimlist.get_model().get_iter(cursor) + row = self.dimlist.get_model().get_value(i, 0) self.set_dimension(row) def _dim_row_activated(self, widget, path, column): self._seltree_controller.set_dimension(dim) - + def _dimlist_button_pressed(self, widget, event): if event.button == 3: self._dimlist_menu.popup(None, None, None, event.button, event.time)