import dataset import scipy class Project: def __init__(self,name="Testing"): self.name = name self.dim_names = [] self._observers = {} self.current_data=None self.datasets=[] self.sel_obj = dataset.Selection() def attach(self,observer,key): """Attach observer for selection updates""" if not self._observers.has_key(key): self._observers[key]=[] if not observer in self._observers[key]: self._observers[key].append(observer) def detach(self,observer,key): """Detach observer for selection updates""" try: self._observers[key].remove(observer) except ValueError: pass def notify(self,key,modifier=None): """Notifies observers""" for observer in self._observers[key]: if modifier != observer: observer.update(self,key) def set_selection(self,dim_name,selection): """Sets a current selection and notify observers""" self.sel_obj.current_selection[dim_name] = set(selection) self.notify('selection_update') def get_selection(self): """Returns the current selection object""" return self.sel_obj.current_selection def add_dataset(self,dataset): """Appends a new Dataset to the project.""" 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): """Creates an arbitrary unique name for a new dimension.""" while dim_name in self.dim_names: dim_name = dim_name + "_t" return dim_name