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/fluents/project.py

148 lines
5.3 KiB
Python
Raw Normal View History

2006-08-30 12:27:45 +02:00
import os
2006-04-18 16:25:46 +02:00
import scipy
import gobject
import gtk
2006-08-30 12:27:45 +02:00
import fluents
2006-08-28 14:06:05 +02:00
import logger
import dataset, plots, main
2006-04-17 00:57:50 +02:00
class Project:
def __init__(self,name="Testing"):
self.data_tree = gtk.TreeStore(gobject.TYPE_STRING,
gobject.TYPE_STRING,
gobject.TYPE_PYOBJECT,
gobject.TYPE_STRING,
gobject.TYPE_STRING,
gobject.TYPE_OBJECT,
2006-08-30 12:27:45 +02:00
gobject.TYPE_DOUBLE)
2006-04-17 00:57:50 +02:00
self.name = name
self.dim_names = []
self._selection_observers = []
self._dataset_observers = []
2006-05-03 13:52:54 +02:00
self.current_data = []
self.datasets = []
self.sel_obj = dataset.Selection('Current Selection')
self.selections = []
2006-10-09 20:31:09 +02:00
self._last_selection = None
self._dataset_iter_map = {}
2006-04-17 00:57:50 +02:00
def add_selection_observer(self, observer):
self._selection_observers.append(observer)
observer.selection_changed(None, self.get_selection())
def notify_selection_listeners(self, dim_name):
"""Notifies observers"""
for observer in self._selection_observers:
observer.selection_changed(dim_name, self.get_selection())
2006-04-17 00:57:50 +02:00
def add_dataset_observer(self, observer):
self._dataset_observers.append(observer)
observer.dataset_changed()
def notify_dataset_listeners(self):
"""Notifies observers when new datasets are added"""
for observer in self._dataset_observers:
observer.dataset_changed()
def set_selection(self, dim_name, selection):
"""Sets a current selection and notify observers"""
self.sel_obj[dim_name] = set(selection)
self.notify_selection_listeners(dim_name)
self._last_selection = selection
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"""
return self.sel_obj
def delete_data(self, it):
child = self.data_tree.iter_children(it)
while child != None:
c = self.data_tree.iter_next(child)
self.delete_data(child)
child = c
main.application.main_view.remove_view(self.data_tree.get(it, 2)[0])
self.data_tree.remove(it)
2006-08-27 16:12:37 +02:00
def add_data(self, parents, data, fun='Function'):
"""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."""
if len(parents) > 0:
parent_iter = self._dataset_iter_map[parents[0]]
else:
parent_iter = None
# Add the function node to the tree
icon = fluents.icon_factory.get("folder_grey")
it = self.data_tree_insert(parent_iter, fun, None, None, "black", icon)
2006-08-30 12:27:45 +02:00
# Add all returned datasets/plots/selections
for d in data:
# Any kind of dataset
if isinstance(d, dataset.Dataset):
if isinstance(d, dataset.GraphDataset):
icon = fluents.icon_factory.get("graph_dataset")
elif isinstance(d, dataset.CategoryDataset):
icon = fluents.icon_factory.get("category_dataset")
else:
icon = fluents.icon_factory.get("dataset")
2006-08-28 14:06:05 +02:00
self.add_dataset(d)
self.data_tree_insert(it, d.get_name(), d, None, "black", icon)
# Any kind of plot
elif isinstance(d, plots.Plot):
icon = fluents.icon_factory.get("line_plot")
self.data_tree_insert(it, d.get_title(), d, None, "black", icon)
d.set_selection_listener(self.set_selection)
self._selection_observers.append(d)
# Selections are not added to the data tree
elif isinstance(d, dataset.Selection):
self.add_selection(d)
def data_tree_insert(self, parent, text, data, bgcolour, fontcolour, icon, selected = 0):
tree = self.data_tree
it = tree.append(parent)
tree.set_value(it, 0, text)
tree.set_value(it, 1, type(data))
tree.set_value(it, 2, data)
tree.set_value(it, 3, bgcolour)
tree.set_value(it, 4, fontcolour)
2006-08-30 12:27:45 +02:00
tree.set_value(it, 5, icon)
tree.set_value(it, 6, selected)
self._dataset_iter_map[data] = it
return it
def add_dataset(self, dataset):
2006-04-17 02:29:00 +02:00
"""Appends a new Dataset to the project."""
2006-08-28 14:06:05 +02:00
logger.log('debug','Adding dataset: %s' %dataset.get_name())
2006-04-17 00:57:50 +02:00
self.datasets.append(dataset)
for dim_name in dataset.get_all_dims():
2006-04-17 00:57:50 +02:00
if dim_name not in self.dim_names:
self.dim_names.append(dim_name)
self.sel_obj[dim_name] = set()
self.notify_selection_listeners(dim_name)
self.notify_dataset_listeners()
2006-04-17 00:57:50 +02:00
def add_selection(self, selection):
"""Adds a new selection to the project."""
self.selections.append(selection)
self.notify_dataset_listeners()
2006-04-17 00:57:50 +02:00
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
2006-04-18 16:25:46 +02:00
2006-04-21 11:23:05 +02:00
def set_current_data(self, obj):
self.current_data = obj