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

88 lines
2.8 KiB
Python

import dataset
import plots
import scipy
import gobject
import gtk
class Project:
def __init__(self,name="Testing"):
self.data_tree = gtk.TreeStore(gobject.TYPE_STRING,
gobject.TYPE_STRING,
gobject.TYPE_PYOBJECT)
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_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."""
for d in data:
if isinstance(d, dataset.Dataset):
self.add_dataset(d)
self.data_tree_insert(None, d.get_name(), d)
elif isinstance(d, plots.Plot):
# self.add_view(d)
self.data_tree_insert(None, 'view', d)
def data_tree_insert(self, parent, text, data):
tree = self.data_tree
iter = tree.append(parent)
tree.set_value(iter, 0, text)
tree.set_value(iter, 1, type(data))
tree.set_value(iter, 2, data)
def add_dataset(self,dataset):
"""Appends a new Dataset to the project."""
self.datasets.append(dataset)
for dim_name in dataset.get_all_dims():
if dim_name not in self.dim_names:
self.dim_names.append(dim_name)
self.sel_obj.current_selection[dim_name] = set()
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
def set_current_data(self, obj):
self.current_data = obj