2006-08-30 12:27:45 +02:00
|
|
|
import os
|
2006-04-18 16:25:46 +02:00
|
|
|
import scipy
|
2006-04-20 16:29:13 +02:00
|
|
|
import gobject
|
|
|
|
import gtk
|
2006-08-30 12:27:45 +02:00
|
|
|
import fluents
|
2007-12-11 02:02:47 +01:00
|
|
|
import logger, dataset, plots, main
|
2006-04-17 00:57:50 +02:00
|
|
|
|
|
|
|
class Project:
|
2007-12-11 01:13:26 +01:00
|
|
|
"""A Project contains datasets, selections etc.
|
|
|
|
The project, of which the application has only one at any given time,
|
|
|
|
is the container for all datasets, plots and selections in use. The data
|
|
|
|
in the project is organized in a gtk.TreeStrore that is displayed in the
|
|
|
|
navigator.
|
|
|
|
"""
|
|
|
|
|
2007-12-11 02:02:47 +01:00
|
|
|
def __init__(self, name="Testing"):
|
2007-12-11 01:13:26 +01:00
|
|
|
self.data_tree = gtk.TreeStore(str,
|
|
|
|
str,
|
|
|
|
object,
|
|
|
|
str,
|
|
|
|
str,
|
|
|
|
gobject.TYPE_OBJECT,
|
|
|
|
float)
|
2006-04-20 16:29:13 +02:00
|
|
|
|
2006-04-17 00:57:50 +02:00
|
|
|
self.name = name
|
|
|
|
self.dim_names = []
|
2006-04-27 16:38:48 +02:00
|
|
|
self._selection_observers = []
|
2006-08-07 16:14:42 +02:00
|
|
|
self._dataset_observers = []
|
2006-05-03 13:52:54 +02:00
|
|
|
self.current_data = []
|
2006-04-24 11:53:07 +02:00
|
|
|
self.datasets = []
|
2006-08-30 01:57:21 +02:00
|
|
|
self.sel_obj = dataset.Selection('Current Selection')
|
|
|
|
self.selections = []
|
2006-10-09 20:31:09 +02:00
|
|
|
self._last_selection = None
|
2007-01-03 14:05:37 +01:00
|
|
|
self._dataset_iter_map = {}
|
2006-04-17 00:57:50 +02:00
|
|
|
|
2006-08-07 16:14:42 +02:00
|
|
|
def add_selection_observer(self, observer):
|
|
|
|
self._selection_observers.append(observer)
|
2006-10-12 19:38:41 +02:00
|
|
|
observer.selection_changed(None, self.get_selection())
|
2006-08-07 16:14:42 +02:00
|
|
|
|
|
|
|
def notify_selection_listeners(self, dim_name):
|
2006-04-20 12:27:58 +02:00
|
|
|
"""Notifies observers"""
|
2006-04-27 16:38:48 +02:00
|
|
|
for observer in self._selection_observers:
|
2006-10-12 19:38:41 +02:00
|
|
|
observer.selection_changed(dim_name, self.get_selection())
|
2006-04-17 00:57:50 +02:00
|
|
|
|
2006-08-07 16:14:42 +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):
|
2006-04-20 12:27:58 +02:00
|
|
|
"""Sets a current selection and notify observers"""
|
2007-02-21 13:05:08 +01:00
|
|
|
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"""
|
2006-08-30 01:57:21 +02:00
|
|
|
return self.sel_obj
|
2006-04-24 16:52:21 +02:00
|
|
|
|
2007-11-09 16:02:32 +01:00
|
|
|
def delete_data(self, it):
|
2007-12-11 02:02:47 +01:00
|
|
|
"""Delete elements from the project."""
|
2007-11-09 16:02:32 +01:00
|
|
|
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'):
|
2006-04-20 16:29:13 +02:00
|
|
|
"""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."""
|
2006-04-24 16:52:21 +02:00
|
|
|
|
2007-01-03 14:05:37 +01:00
|
|
|
if len(parents) > 0:
|
|
|
|
parent_iter = self._dataset_iter_map[parents[0]]
|
|
|
|
else:
|
|
|
|
parent_iter = None
|
|
|
|
|
2007-01-03 14:34:40 +01:00
|
|
|
# Add the function node to the tree
|
2007-01-03 14:46:39 +01:00
|
|
|
icon = fluents.icon_factory.get("folder_grey")
|
2007-01-03 14:05:37 +01:00
|
|
|
it = self.data_tree_insert(parent_iter, fun, None, None, "black", icon)
|
2006-08-30 12:27:45 +02:00
|
|
|
|
2007-01-03 14:34:40 +01:00
|
|
|
# Add all returned datasets/plots/selections
|
2006-04-20 16:29:13 +02:00
|
|
|
for d in data:
|
2007-01-03 14:34:40 +01:00
|
|
|
# Any kind of dataset
|
|
|
|
if isinstance(d, dataset.Dataset):
|
|
|
|
if isinstance(d, dataset.GraphDataset):
|
2007-01-03 14:46:39 +01:00
|
|
|
icon = fluents.icon_factory.get("graph_dataset")
|
2007-01-03 14:34:40 +01:00
|
|
|
elif isinstance(d, dataset.CategoryDataset):
|
2007-01-03 14:46:39 +01:00
|
|
|
icon = fluents.icon_factory.get("category_dataset")
|
2007-01-03 14:34:40 +01:00
|
|
|
else:
|
2007-01-03 14:46:39 +01:00
|
|
|
icon = fluents.icon_factory.get("dataset")
|
2007-01-03 14:34:40 +01:00
|
|
|
|
2006-08-28 14:06:05 +02:00
|
|
|
self.add_dataset(d)
|
2007-01-03 14:34:40 +01:00
|
|
|
self.data_tree_insert(it, d.get_name(), d, None, "black", icon)
|
|
|
|
|
|
|
|
# Any kind of plot
|
2006-04-20 16:29:13 +02:00
|
|
|
elif isinstance(d, plots.Plot):
|
2007-01-03 14:46:39 +01:00
|
|
|
icon = fluents.icon_factory.get("line_plot")
|
2007-01-03 14:34:40 +01:00
|
|
|
self.data_tree_insert(it, d.get_title(), d, None, "black", icon)
|
2006-04-27 16:38:48 +02:00
|
|
|
d.set_selection_listener(self.set_selection)
|
|
|
|
self._selection_observers.append(d)
|
2007-01-03 14:34:40 +01:00
|
|
|
|
|
|
|
# Selections are not added to the data tree
|
2006-08-30 01:57:21 +02:00
|
|
|
elif isinstance(d, dataset.Selection):
|
|
|
|
self.add_selection(d)
|
2006-04-20 16:29:13 +02:00
|
|
|
|
2007-12-11 01:13:26 +01:00
|
|
|
def data_tree_insert(self, parent, text, data, bg, fg, icon, selected = 0):
|
|
|
|
"""Inserts data into the tree view.
|
|
|
|
@param text: The title of the object.
|
|
|
|
@param data: A dataset, plot or function object.
|
|
|
|
@param bg: Background color.
|
|
|
|
@param fg: Foreground (font) color.
|
|
|
|
@param icon: Pixmap icon.
|
|
|
|
"""
|
2006-04-20 16:29:13 +02:00
|
|
|
tree = self.data_tree
|
2006-04-24 16:52:21 +02:00
|
|
|
it = tree.append(parent)
|
2007-12-11 01:13:26 +01:00
|
|
|
tree[it] = [text, type(data), data, bg, fg, icon, selected]
|
2007-01-03 14:05:37 +01:00
|
|
|
self._dataset_iter_map[data] = it
|
2006-04-24 17:20:27 +02:00
|
|
|
return it
|
2006-04-20 16:29:13 +02:00
|
|
|
|
2006-08-30 01:57:21 +02:00
|
|
|
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)
|
2006-04-24 11:53:07 +02:00
|
|
|
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)
|
2006-08-30 01:57:21 +02:00
|
|
|
self.sel_obj[dim_name] = set()
|
2007-02-21 13:05:08 +01:00
|
|
|
self.notify_selection_listeners(dim_name)
|
2006-08-07 16:14:42 +02:00
|
|
|
self.notify_dataset_listeners()
|
2006-04-17 00:57:50 +02:00
|
|
|
|
2006-08-30 01:57:21 +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
|
|
|
|
2006-04-20 16:29:13 +02:00
|
|
|
def object_at(self, path):
|
2007-12-11 02:02:47 +01:00
|
|
|
"""Returns the object at a given path in the tree."""
|
|
|
|
it = self.get_iter(path)
|
|
|
|
obj = self[it][2]
|
|
|
|
if obj:
|
|
|
|
obj.show()
|
|
|
|
return obj
|
2006-04-18 16:25:46 +02:00
|
|
|
|
2007-12-14 16:42:37 +01:00
|
|
|
#def set_current_data(self, obj):
|
|
|
|
# self.current_data = obj
|
2006-04-24 17:20:27 +02:00
|
|
|
|