Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Added drag-n-drop of matrices to idlist window to support ranking of selected variables.

This commit is contained in:
Einar Ryeng 2008-02-01 11:09:10 +00:00
parent f83a16ec37
commit 848ba7f80c
1 changed files with 38 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import gtk.glade
import gnome
import gnome.ui
import gobject
import scipy
import logger, dataset, main
import annotations
@ -38,7 +39,7 @@ class IdListController:
# id, annotation
self._idstore = gtk.ListStore(gobject.TYPE_STRING,
gobject.TYPE_STRING,)
gobject.TYPE_STRING)
self._idstore.set_sort_func(0, self._numeric_compare)
# Annotation tree column
@ -55,6 +56,12 @@ class IdListController:
idlist.insert_column(dim_column, 0)
idlist.connect('button-press-event', self._button_pressed)
## Enable dropping
idlist.drag_dest_set(gtk.DEST_DEFAULT_ALL,
[("GTK_TREE_MODEL_ROW", gtk.TARGET_SAME_APP, 7)],
gtk.gdk.ACTION_LINK)
idlist.connect('drag-data-received', self._drag_data_received)
## Set up identifier list context menu
menu = self._menu = SimpleMenu()
menu.add_simple_item('Import...', self._on_import_list)
@ -179,6 +186,22 @@ class IdListController:
print "unknown; ", retval
dialog.destroy()
def set_rank(self, ds):
print "Set rank."
ra = scipy.sum(ds.asarray(), 1)
ranks = {}
dim = ds.get_dim_name()[0]
for key, value in ds[dim].items():
ranks[key] = ra[value]
ann_h = annotations.get_dim_handler(self._dimension)
if ann_h is None:
ann_h = annotations.DictAnnotationHandler()
annotations.set_dim_handler(self._dimension, ann_h)
ann_h.add_annotations('Rank', ranks)
##
## GTK Callbacks
##
@ -223,6 +246,20 @@ class IdListController:
ids = [self._idstore.get_value(i, 0) for i in iters]
main.project.set_selection(self._dimension, ids)
def _drag_data_received(self, widget, drag_context, x, y,
selection, info, timestamp):
print "drag_data_received"
treestore, path = selection.tree_get_row_drag_data()
i = treestore.get_iter(path)
obj = treestore.get_value(i, 2)
if isinstance(obj, dataset.Dataset):
print "is dataset"
if self._dimension in obj.get_dim_name():
print "has correct dimensions"
self.set_rank(obj)
widget.emit_stop_by_name('drag-data-received')
class SelectionListController:
def __init__(self, seltree, idlist_controller):