2006-04-17 00:57:50 +02:00
|
|
|
import dataset
|
2006-04-20 16:29:13 +02:00
|
|
|
import plots
|
2006-04-18 16:25:46 +02:00
|
|
|
import scipy
|
2006-04-20 16:29:13 +02:00
|
|
|
import gobject
|
|
|
|
import gtk
|
2006-04-17 00:57:50 +02:00
|
|
|
|
|
|
|
class Project:
|
|
|
|
def __init__(self,name="Testing"):
|
2006-04-20 16:29:13 +02:00
|
|
|
self.data_tree = gtk.TreeStore(gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_STRING,
|
|
|
|
gobject.TYPE_PYOBJECT)
|
|
|
|
|
2006-04-17 00:57:50 +02:00
|
|
|
self.name = name
|
|
|
|
self.dim_names = []
|
2006-04-20 12:27:58 +02:00
|
|
|
self._observers = {}
|
2006-04-24 11:53:07 +02:00
|
|
|
self.current_data = None
|
|
|
|
self.datasets = []
|
2006-04-19 20:50:10 +02:00
|
|
|
self.sel_obj = dataset.Selection()
|
2006-04-17 00:57:50 +02:00
|
|
|
|
2006-04-20 12:27:58 +02:00
|
|
|
def attach(self,observer,key):
|
2006-04-17 02:29:00 +02:00
|
|
|
"""Attach observer for selection updates"""
|
2006-04-20 12:27:58 +02:00
|
|
|
if not self._observers.has_key(key):
|
|
|
|
self._observers[key]=[]
|
|
|
|
if not observer in self._observers[key]:
|
|
|
|
self._observers[key].append(observer)
|
2006-04-17 00:57:50 +02:00
|
|
|
|
2006-04-20 12:27:58 +02:00
|
|
|
def detach(self,observer,key):
|
2006-04-17 02:29:00 +02:00
|
|
|
"""Detach observer for selection updates"""
|
|
|
|
try:
|
2006-04-20 12:27:58 +02:00
|
|
|
self._observers[key].remove(observer)
|
2006-04-17 02:29:00 +02:00
|
|
|
except ValueError:
|
|
|
|
pass
|
2006-04-17 00:57:50 +02:00
|
|
|
|
2006-04-20 12:27:58 +02:00
|
|
|
def notify(self,key,modifier=None):
|
|
|
|
"""Notifies observers"""
|
|
|
|
for observer in self._observers[key]:
|
2006-04-17 00:57:50 +02:00
|
|
|
if modifier != observer:
|
2006-04-24 16:42:45 +02:00
|
|
|
observer.update(key)
|
2006-04-17 00:57:50 +02:00
|
|
|
|
2006-04-19 20:50:10 +02:00
|
|
|
def set_selection(self,dim_name,selection):
|
2006-04-20 12:27:58 +02:00
|
|
|
"""Sets a current selection and notify observers"""
|
2006-04-19 20:50:10 +02:00
|
|
|
self.sel_obj.current_selection[dim_name] = set(selection)
|
2006-04-20 12:27:58 +02:00
|
|
|
self.notify('selection_update')
|
2006-04-17 00:57:50 +02:00
|
|
|
|
2006-04-19 20:50:10 +02:00
|
|
|
def get_selection(self):
|
2006-04-17 02:29:00 +02:00
|
|
|
"""Returns the current selection object"""
|
2006-04-19 20:50:10 +02:00
|
|
|
return self.sel_obj.current_selection
|
2006-04-24 16:52:21 +02:00
|
|
|
|
|
|
|
def get_data_iter(self, obj):
|
|
|
|
"""Retuns an iterator to data."""
|
|
|
|
retval = [None]
|
|
|
|
def is_obj(m, p, i, d):
|
|
|
|
if obj == m.get_value(i, 2):
|
|
|
|
d.append(i)
|
|
|
|
return True
|
|
|
|
|
|
|
|
self.data_tree.foreach(is_obj, retval)
|
|
|
|
return retval[-1]
|
|
|
|
|
2006-04-20 16:29:13 +02:00
|
|
|
def add_data(self, parent, data):
|
|
|
|
"""Adds a set of data and plots to the navigator.
|
|
|
|
|
|
|
|
This method is usually called after a Function in a workflow
|
|
|
|
has finished and returns its output."""
|
2006-04-24 16:52:21 +02:00
|
|
|
|
|
|
|
parent_iter = self.get_data_iter(parent)
|
|
|
|
|
2006-04-20 16:29:13 +02:00
|
|
|
for d in data:
|
|
|
|
if isinstance(d, dataset.Dataset):
|
|
|
|
self.add_dataset(d)
|
2006-04-24 16:52:21 +02:00
|
|
|
self.data_tree_insert(parent_iter, d.get_name(), d)
|
2006-04-20 16:29:13 +02:00
|
|
|
elif isinstance(d, plots.Plot):
|
|
|
|
# self.add_view(d)
|
2006-04-24 16:52:21 +02:00
|
|
|
self.data_tree_insert(parent_iter, d.get_title(), d)
|
2006-04-24 16:42:45 +02:00
|
|
|
d.set_project(self)
|
|
|
|
self.attach(d, 'selection_update')
|
2006-04-20 16:29:13 +02:00
|
|
|
|
|
|
|
def data_tree_insert(self, parent, text, data):
|
|
|
|
tree = self.data_tree
|
2006-04-24 16:52:21 +02:00
|
|
|
it = tree.append(parent)
|
|
|
|
tree.set_value(it, 0, text)
|
|
|
|
tree.set_value(it, 1, type(data))
|
|
|
|
tree.set_value(it, 2, data)
|
2006-04-20 16:29:13 +02:00
|
|
|
|
2006-04-17 00:57:50 +02:00
|
|
|
def add_dataset(self,dataset):
|
2006-04-17 02:29:00 +02:00
|
|
|
"""Appends a new Dataset to the project."""
|
2006-04-17 00:57:50 +02:00
|
|
|
self.datasets.append(dataset)
|
2006-04-24 11:53:07 +02:00
|
|
|
for dim_name in dataset.get_all_dims():
|
2006-04-17 00:57:50 +02:00
|
|
|
if dim_name not in self.dim_names:
|
|
|
|
self.dim_names.append(dim_name)
|
2006-04-24 11:53:07 +02:00
|
|
|
self.sel_obj.current_selection[dim_name] = set()
|
2006-04-17 00:57:50 +02:00
|
|
|
|
|
|
|
|
2006-04-20 16:29:13 +02:00
|
|
|
def object_at(self, path):
|
|
|
|
"Returns the object at a given path in the tree."
|
|
|
|
iter = self.get_iter(path)
|
|
|
|
object = self.get_value(iter, 2)
|
|
|
|
if object:
|
|
|
|
object.show()
|
|
|
|
return object
|
2006-04-18 16:25:46 +02:00
|
|
|
|
2006-04-21 11:23:05 +02:00
|
|
|
def set_current_data(self, obj):
|
|
|
|
self.current_data = obj
|