Added drag-n-drop of matrices to idlist window to support ranking of selected variables.
This commit is contained in:
parent
f83a16ec37
commit
848ba7f80c
|
@ -5,6 +5,7 @@ import gtk.glade
|
||||||
import gnome
|
import gnome
|
||||||
import gnome.ui
|
import gnome.ui
|
||||||
import gobject
|
import gobject
|
||||||
|
import scipy
|
||||||
|
|
||||||
import logger, dataset, main
|
import logger, dataset, main
|
||||||
import annotations
|
import annotations
|
||||||
|
@ -38,7 +39,7 @@ class IdListController:
|
||||||
|
|
||||||
# id, annotation
|
# id, annotation
|
||||||
self._idstore = gtk.ListStore(gobject.TYPE_STRING,
|
self._idstore = gtk.ListStore(gobject.TYPE_STRING,
|
||||||
gobject.TYPE_STRING,)
|
gobject.TYPE_STRING)
|
||||||
self._idstore.set_sort_func(0, self._numeric_compare)
|
self._idstore.set_sort_func(0, self._numeric_compare)
|
||||||
|
|
||||||
# Annotation tree column
|
# Annotation tree column
|
||||||
|
@ -55,6 +56,12 @@ class IdListController:
|
||||||
idlist.insert_column(dim_column, 0)
|
idlist.insert_column(dim_column, 0)
|
||||||
idlist.connect('button-press-event', self._button_pressed)
|
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
|
## Set up identifier list context menu
|
||||||
menu = self._menu = SimpleMenu()
|
menu = self._menu = SimpleMenu()
|
||||||
menu.add_simple_item('Import...', self._on_import_list)
|
menu.add_simple_item('Import...', self._on_import_list)
|
||||||
|
@ -179,6 +186,22 @@ class IdListController:
|
||||||
print "unknown; ", retval
|
print "unknown; ", retval
|
||||||
dialog.destroy()
|
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
|
## GTK Callbacks
|
||||||
##
|
##
|
||||||
|
@ -223,6 +246,20 @@ class IdListController:
|
||||||
ids = [self._idstore.get_value(i, 0) for i in iters]
|
ids = [self._idstore.get_value(i, 0) for i in iters]
|
||||||
main.project.set_selection(self._dimension, ids)
|
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:
|
class SelectionListController:
|
||||||
def __init__(self, seltree, idlist_controller):
|
def __init__(self, seltree, idlist_controller):
|
||||||
|
|
Reference in New Issue