Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0
This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
laydi/system/project.py

58 lines
1.7 KiB
Python
Raw Normal View History

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 = []
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
def attach(self,observer,key):
2006-04-17 02:29:00 +02:00
"""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)
2006-04-17 00:57:50 +02:00
def detach(self,observer,key):
2006-04-17 02:29:00 +02:00
"""Detach observer for selection updates"""
try:
self._observers[key].remove(observer)
2006-04-17 02:29:00 +02:00
except ValueError:
pass
2006-04-17 00:57:50 +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:
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):
"""Sets a current selection and notify observers"""
2006-04-19 20:50:10 +02:00
self.sel_obj.current_selection[dim_name] = set(selection)
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."""
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