Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Fixed dim_cursor_changed to to use the correct treemodel, and added show/hide on selection details

This commit is contained in:
Arnar Flatberg 2007-02-23 10:46:04 +00:00
parent 0d8702bb71
commit 41e8ed511b
1 changed files with 37 additions and 39 deletions

View File

@ -15,9 +15,9 @@ class SimpleMenu(gtk.Menu):
def __init__(self): def __init__(self):
gtk.Menu.__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 = gtk.MenuItem(title)
item.connect('activate', function) item.connect('activate', function, *args)
self.append(item) self.append(item)
item.show() item.show()
@ -104,10 +104,8 @@ class IdListController:
def set_selection(self, selection): def set_selection(self, selection):
"""Set the selection to be displayed. """Set the selection to be displayed.
The selection is not stored, the values are copied into the TreeStore""" The selection is not stored, the values are copied into the TreeStore"""
self._idstore.clear() self._idstore.clear()
id_list = list(selection[self._dimension]) id_list = list(selection[self._dimension])
idlist = list(selection[self._dimension]) idlist = list(selection[self._dimension])
if self._annotation[self._dimension] != None: if self._annotation[self._dimension] != None:
annlist = annotations.get_dim_annotations(self._dimension, annlist = annotations.get_dim_annotations(self._dimension,
@ -182,23 +180,21 @@ class SelectionListController:
def __init__(self, seltree, idlist_controller): def __init__(self, seltree, idlist_controller):
self._seltree = seltree self._seltree = seltree
self._sel_stores = {} self._sel_stores = {}
self._detail_cols = []
self._dimension = None self._dimension = None
self._idlist_controller = idlist_controller self._idlist_controller = idlist_controller
self._details_on = False
# Selection renderers
# Selection column
renderer = gtk.CellRendererText() renderer = gtk.CellRendererText()
sel_column = gtk.TreeViewColumn('Selection', renderer, text=0) sel_column = gtk.TreeViewColumn('Selection', renderer, text=0)
seltree.insert_column(sel_column, 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 # Signals
seltree.connect('row-activated', self._on_row_activated) seltree.connect('row-activated', self._on_row_activated)
seltree.connect('cursor-changed', self._on_cursor_changed) seltree.connect('cursor-changed', self._on_cursor_changed)
@ -212,6 +208,8 @@ 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._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('Copy selection', self._on_seltree_copy_selection)
# #
# Public interface # Public interface
@ -239,7 +237,7 @@ class SelectionListController:
if not self._get_current_selection_iter(selection, dim): if not self._get_current_selection_iter(selection, dim):
n = len(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) store.insert_after(None, None, values)
def add_dataset(self, dataset): def add_dataset(self, dataset):
@ -259,11 +257,10 @@ class SelectionListController:
n_sel = len(selection[dim_name]) n_sel = len(selection[dim_name])
values = (selection.title, selection, dim_name, 0, n_sel, 0) values = (selection.title, selection, dim_name, 0, n_sel, 0)
store.insert_after(i, None, values) store.insert_after(i, None, values)
## #
## Private interface # Private interface
## #
def _add_selection_store(self, dim): def _add_selection_store(self, dim):
"""Add a new gtk.TreeStore for the selections on a dimension.""" """Add a new gtk.TreeStore for the selections on a dimension."""
# Create new store # Create new store
@ -340,6 +337,15 @@ class SelectionListController:
# #
# GTK callbacks # 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, def _drag_data_received(self, widget, drag_context, x, y,
selection, info, timestamp): selection, info, timestamp):
@ -354,7 +360,6 @@ class SelectionListController:
def _on_cursor_changed(self, widget): def _on_cursor_changed(self, widget):
"Show the list of identifier strings." "Show the list of identifier strings."
store = self._sel_stores[self._dimension] store = self._sel_stores[self._dimension]
p = self._seltree.get_cursor()[0] p = self._seltree.get_cursor()[0]
@ -366,7 +371,6 @@ class SelectionListController:
def _on_row_activated(self, widget, path, column): def _on_row_activated(self, widget, path, column):
store = self._sel_stores[self._dimension] store = self._sel_stores[self._dimension]
i = store.get_iter(path) i = store.get_iter(path)
obj = store.get_value(i, 1) obj = store.get_value(i, 1)
if isinstance(obj, dataset.Dataset): if isinstance(obj, dataset.Dataset):
@ -450,33 +454,27 @@ class DimListController:
def set_dimension(self, dimname): def set_dimension(self, dimname):
self._current_dim = dimname self._current_dim = dimname
dim = self.get_dimension(self._current_dim) dim = self.get_dimension(self._current_dim)
path = self.dimstore.get_path(dim) path = self.dimstore.get_path(dim)
if self.dimlist.get_cursor()[0] != path: if self.dimlist.get_cursor()[0] != path:
self.dimlist.set_cursor(self.dimstore.get_path(dim)) self.dimlist.set_cursor(self.dimstore.get_path(dim))
self._seltree_controller.set_dimension(dimname) self._seltree_controller.set_dimension(dimname)
def dataset_changed(self): def dataset_changed(self):
"""Callback function from Project.""" """Callback function from Project."""
self.update_dims() self.update_dims()
##
## Private interface
##
def update_dims(self): def update_dims(self):
"""Update the list of dimensions shown""" """Update the list of dimensions shown"""
for dim in self.dim_names: for dim in self.dim_names:
if not self.get_dimension(dim): if not self.get_dimension(dim):
self.dimstore.insert_after(None, (dim,)) self.dimstore.insert_after(None, (dim,))
#def _dimension_filter(self, store, row): #
# """Filters out everything but the selected dimension.""" # Private interface
# row_dim = store.get_value(row, 2) #
# return row_dim == self._current_dim
def _dimension_filter(self, store, row): def _dimension_filter(self, store, row):
"""Filters out dimension with underscore prefix""" """Filters out dimension with underscore prefix"""
visible = False visible = False
@ -493,18 +491,18 @@ class DimListController:
def _on_dim_show(self, menuitem): def _on_dim_show(self, menuitem):
self.dimlist.set_model(self.dimstore) self.dimlist.set_model(self.dimstore)
## #
## GTK Callbacks. # GTK Callbacks.
## #
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.dimstore.get_iter(cursor) i = self.dimlist.get_model().get_iter(cursor)
row = self.dimstore.get_value(i, 0) row = self.dimlist.get_model().get_value(i, 0)
self.set_dimension(row) self.set_dimension(row)
def _dim_row_activated(self, widget, path, column): def _dim_row_activated(self, widget, path, column):
self._seltree_controller.set_dimension(dim) self._seltree_controller.set_dimension(dim)
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)