diff --git a/system/selections.py b/system/selections.py new file mode 100644 index 0000000..b52b930 --- /dev/null +++ b/system/selections.py @@ -0,0 +1,77 @@ + +from system import logger, dataset + +import pygtk +import gtk +import gtk.gdk +import gtk.glade +import gnome +import gnome.ui +import gobject + +class SelectionTree(gtk.TreeView): + + def __init__(self): + self.store = gtk.TreeStore(gobject.TYPE_STRING) + gtk.TreeView.__init__(self, self.store) + + renderer = gtk.CellRendererText() + sel_column = gtk.TreeViewColumn('Selection', renderer, text=0) + self.insert_column(sel_column, 0) + + self.connect('row-activated', self.on_row_activated) + + self._identifier_list = None + self._dim_list = {} + + # A mapping of selection names to selection lines. + self._selections = {} + + self.set_headers_visible(True) + + def set_identifier_list(self, identifier_list): + self._identifier_list = identifier_list + + def set_project(self, project): + self.project = project + project.add_selection_observer(self) + project.add_dataset_observer(self) + self.update_dims(project.dim_names) + + def selection_changed(self, selection): + self.update_dims(selection.keys()) + + def dataset_changed(self): + self.selection_changed(self.project.get_selection()) + + def update_dims(self, dim_list): + for dim in dim_list: + if not self._dim_list.has_key(dim): + d = self.store.insert_after(None, None, (dim,)) + self._dim_list[dim] = d + self.store.insert_before(d, None, ('current selection',)) + + def on_row_activated(self, treeview, path, column): + i = self.store.get_iter(path) + p = self.store.iter_parent(i) + dim = self.store.get_value(p, 0) + id_list = self.project.get_selection()[dim] + self._identifier_list.set_identifiers(id_list) + + +class IdentifierList(gtk.TreeView): + + def __init__(self): + self.store = gtk.ListStore(gobject.TYPE_STRING) + gtk.TreeView.__init__(self, self.store) + + renderer = gtk.CellRendererText() + ids_column = gtk.TreeViewColumn('Identifiers', renderer, text=0) + self.insert_column(ids_column, 0) + + self.set_headers_visible(True) + + def set_identifiers(self, identifiers): + self.store.clear() + for e in identifiers: + self.store.append((e,))