2006-04-17 00:57:50 +02:00
|
|
|
import dataset
|
2006-04-18 16:25:46 +02:00
|
|
|
import scipy
|
2006-04-17 00:57:50 +02:00
|
|
|
|
|
|
|
class Project:
|
|
|
|
def __init__(self,name="Testing"):
|
|
|
|
self.name = name
|
|
|
|
self.dim_names = []
|
2006-04-20 12:27:58 +02:00
|
|
|
self._observers = {}
|
2006-04-19 21:59:55 +02:00
|
|
|
self.current_data=None
|
2006-04-17 00:57:50 +02:00
|
|
|
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-20 12:27:58 +02:00
|
|
|
observer.update(self,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-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)
|
|
|
|
for dim_name in dataset.ids.keys():
|
|
|
|
if dim_name not in self.dim_names:
|
|
|
|
self.dim_names.append(dim_name)
|
|
|
|
|
|
|
|
def suggest_dim_name(self,dim_name):
|
2006-04-17 02:29:00 +02:00
|
|
|
"""Creates an arbitrary unique name for a new dimension."""
|
2006-04-19 20:25:44 +02:00
|
|
|
while dim_name in self.dim_names:
|
2006-04-17 00:57:50 +02:00
|
|
|
dim_name = dim_name + "_t"
|
|
|
|
return dim_name
|
|
|
|
|
2006-04-18 16:25:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
|