Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

* project.py: Added comments.

This commit is contained in:
Einar Ryeng 2006-04-17 00:29:00 +00:00
parent 4bdeef05f6
commit adc3bf6bb1
1 changed files with 12 additions and 7 deletions

View File

@ -1,4 +1,3 @@
#import logger
import dataset import dataset
class Project: class Project:
@ -11,39 +10,45 @@ class Project:
self.datasets=[] self.datasets=[]
def attach(self, observer): def attach(self, observer):
"""Attach observer for selection updates"""
if not observer in self._selection_observers: if not observer in self._selection_observers:
self._selection_observers.append(observer) self._selection_observers.append(observer)
def detach(self, observer): def detach(self, observer):
try: """Detach observer for selection updates"""
self.selection_observers.remove(observer) try:
except ValueError: self.selection_observers.remove(observer)
pass except ValueError:
pass
def notify(self, modifier=None): def notify(self, modifier=None):
"""Notifies observers that selection is updated"""
for observer in self.selection_observers: for observer in self.selection_observers:
if modifier != observer: if modifier != observer:
observer.update(self) observer.update(self)
def set_selection(self,dim_name,selection): def set_selection(self,dim_name,selection):
"""Sets selection and notifies observers"""
current_selection = set(selection) current_selection = set(selection)
self.current_selection[dim_name] = current_selection self.current_selection[dim_name] = current_selection
self.notify() self.notify()
def get_selection(self,sel_obj): def get_selection(self,sel_obj):
"""Returns the current selection object"""
return sel_obj.current_selection return sel_obj.current_selection
def add_dataset(self,dataset): def add_dataset(self,dataset):
"""Appends a new Dataset to the project."""
self.datasets.append(dataset) self.datasets.append(dataset)
for dim_name in dataset.ids.keys(): for dim_name in dataset.ids.keys():
if dim_name not in self.dim_names: if dim_name not in self.dim_names:
self.dim_names.append(dim_name) self.dim_names.append(dim_name)
def suggest_dim_name(self,dim_name): def suggest_dim_name(self,dim_name):
"""Creates an arbitrary unique name for a new dimension."""
if dim_name in self.dim_names: if dim_name in self.dim_names:
dim_name = dim_name + "_t" dim_name = dim_name + "_t"
return dim_name return dim_name
# FIXME: Singleton project should be removed.
c_p = Project() c_p = Project()