Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Changed the name of the current Project class to ProjectView, to make room for a new

non-GUI project class.
This commit is contained in:
Einar Ryeng 2011-03-06 22:33:51 +00:00
parent 21133af8f7
commit b5d2e8e181
7 changed files with 76 additions and 78 deletions

View File

@ -3,7 +3,7 @@
from getopt import getopt
import os
import sys
from laydi import laydi, project, workflow, main
from laydi import laydi, projectview, workflow, main
#import workflows
from laydi import cfgparse
import optparse
@ -113,9 +113,9 @@ if __name__ == '__main__':
app = laydi.LaydiApp()
main.set_application(app)
main.set_project(project.Project())
main.set_projectview(projectview.ProjectView())
app.set_project(main.project)
app.set_projectview(main.projectview)
app.show()
gtk.main()

View File

@ -4,7 +4,7 @@ import gtk
import sys
import os
import gobject
import logger, project, workflow
import logger, projectview, workflow
DATADIR = os.path.dirname(sys.modules['laydi'].__file__)
GLADEFILENAME = os.path.join(DATADIR, 'laydi.glade')
@ -62,11 +62,11 @@ class CreateProjectDruid(gtk.Window):
def finish(self, *rest):
tree, it = self['workflow_list'].get_selection().get_selected()
wf_class = self.workflows.get_value(it, 1)
proj = project.Project()
proj = projectview.ProjectView()
main.set_workflow(wf_class())
# self.app.set_workflow(wf(self.app))
# self.app.set_project(proj)
main.set_project(proj)
main.set_projectview(proj)
self.hide()
self.destroy()

View File

@ -13,7 +13,7 @@ import gnome
import gnome.ui
import scipy
import pango
import project, workflow, dataset, view, navigator, dialogs, selections, plots, main
import projectview, workflow, dataset, view, navigator, dialogs, selections, plots, main
from logger import logger, LogView
@ -160,7 +160,6 @@ class ViewFrameToolButton (gtk.ToolItem):
class LaydiApp:
def __init__(self): # Application variables
# self.project = None
self.current_data = None
self._last_view = None
self._plot_toolbar = None
@ -227,11 +226,11 @@ class LaydiApp:
tb = ViewFrameToolButton()
self['toolbar'].add(tb)
def set_project(self, proj):
def set_projectview(self, proj):
logger.notice('Welcome to your new project. Grasp That Data!')
self.navigator_view.add_project(proj)
self.dimlist_crt.set_project(proj)
self.sellist_crt.set_project(proj)
self.navigator_view.add_projectview(proj)
self.dimlist_crt.set_projectview(proj)
self.sellist_crt.set_projectview(proj)
def set_workflow(self, workflow):
main.workflow = workflow
@ -244,7 +243,7 @@ class LaydiApp:
"""Sets the plot in the currently active ViewFrame. If the plot is
already shown in another ViewFrame it will be moved from there."""
# Set current selection in the plot before showing it.
plot.selection_changed(None, main.project.get_selection())
plot.selection_changed(None, main.projectview.get_selection())
self['main_view'].insert_view(plot)
self._update_toolbar(plot)

View File

@ -21,8 +21,8 @@ navigator = None
#: The current application
application = None
#: The current project
project = None
#: The current projectview
projectview = None
#: The current workflow
workflow = None
@ -84,9 +84,9 @@ def set_application(app):
application = app
notify_observers('application')
def set_project(p):
global project
project = p
def set_projectview(p):
global projectview
projectview = p
notify_observers('project')
def set_workflow(wf):

View File

@ -4,7 +4,7 @@ import plots
import time
import laydi
from logger import logger
import dataset, plots, project, workflow, main
import dataset, plots, projectview, workflow, main
import scipy
class NavigatorView (gtk.TreeView):
@ -15,8 +15,8 @@ class NavigatorView (gtk.TreeView):
"""
def __init__(self):
if main.project:
self.data_tree = main.project.data_tree
if main.projectview:
self.data_tree = main.projectview.data_tree
else:
self.data_tree = None
@ -67,10 +67,10 @@ class NavigatorView (gtk.TreeView):
if paths:
self.data_tree.drag_data_get(paths[0], selection)
def add_project(self, project):
def add_projectview(self, projectview):
"""Dependency injection."""
self.data_tree = project.data_tree
self.set_model(project.data_tree)
self.data_tree = projectview.data_tree
self.set_model(projectview.data_tree)
self.data_tree.connect('row-changed',self.on_row_changed)
def on_selection_changed(self, selection):
@ -97,10 +97,10 @@ class NavigatorView (gtk.TreeView):
if objs and isinstance(objs[0], dataset.Dataset):
logger.debug('Selecting dataset')
main.project.current_data = objs
main.projectview.current_data = objs
else:
logger.debug('Deselecting dataset')
main.project.current_data = []
main.projectview.current_data = []
def on_row_changed(self, treestore, pos, iter):
"""Set correct focus and colours when rows have changed."""
@ -294,8 +294,8 @@ class NavigatorMenu(gtk.Menu):
else:
icon = laydi.icon_factory.get("dataset")
main.project.add_dataset(ds)
main.project.data_tree_insert(None, ds.get_name(), ds, None, "black", icon)
main.projectview.add_dataset(ds)
main.projectview.data_tree_insert(None, ds.get_name(), ds, None, "black", icon)
def on_load_dataset(self, item, navigator):
# Set up file chooser.
@ -338,28 +338,28 @@ class NavigatorMenu(gtk.Menu):
iters = [tm.get_iter(r) for r in rows]
iters.reverse()
for i in iters:
main.project.delete_data(i)
main.projectview.delete_data(i)
# tm.remove(i)
def on_plot_image(self, item, navigator):
plot = plots.ImagePlot(self.dataset, name='Image Plot')
icon = laydi.icon_factory.get("line_plot")
main.project.data_tree_insert(self.tree_iter, 'Image Plot', plot, None, "black", icon)
main.projectview.data_tree_insert(self.tree_iter, 'Image Plot', plot, None, "black", icon)
# fixme: image plot selections are not well defined
#plot.set_selection_listener(project.set_selection)
#project._selection_observers.append(plot)
#plot.set_selection_listener(projectview.set_selection)
#projectview._selection_observers.append(plot)
def on_plot_hist(self, item, navigator):
project = main.project
projectview = main.projectview
plot = plots.HistogramPlot(self.dataset, name='Histogram')
icon = laydi.icon_factory.get("line_plot")
project.data_tree_insert(self.tree_iter, 'Histogram', plot, None, "black", icon)
plot.set_selection_listener(project.set_selection)
project._selection_observers.append(plot)
projectview.data_tree_insert(self.tree_iter, 'Histogram', plot, None, "black", icon)
plot.set_selection_listener(projectview.set_selection)
projectview._selection_observers.append(plot)
def on_plot_scatter(self, item, navigator):
project = main.project
datasets = main.project.current_data
projectview = main.projectview
datasets = main.projectview.current_data
ds_major = datasets[0]
dims_major = ds_major.get_dim_name()
ids_major = ds_major.get_identifiers(dims_major[1], sorted=True)
@ -380,70 +380,70 @@ class NavigatorMenu(gtk.Menu):
name='Scatter (%s)' % ds_major.get_name())
plot.add_axes_spin_buttons(len(ids_major), 0, 1)
icon = laydi.icon_factory.get("line_plot")
project.data_tree_insert(self.tree_iter, 'Scatter', plot, None, "black", icon)
plot.set_selection_listener(project.set_selection)
project._selection_observers.append(plot)
projectview.data_tree_insert(self.tree_iter, 'Scatter', plot, None, "black", icon)
plot.set_selection_listener(projectview.set_selection)
projectview._selection_observers.append(plot)
def on_plot_line(self, item, navigator):
project = main.project
projectview = main.projectview
ds = self.dataset
dims = ds.get_dim_name()
ids = ds.get_identifiers(dims[1])
plot = plots.LineViewPlot(ds, name='Line (%s)' % ds.get_name())
icon = laydi.icon_factory.get("line_plot")
project.data_tree_insert(self.tree_iter, 'Line view', plot, None, "black", icon)
plot.set_selection_listener(project.set_selection)
project._selection_observers.append(plot)
projectview.data_tree_insert(self.tree_iter, 'Line view', plot, None, "black", icon)
plot.set_selection_listener(projectview.set_selection)
projectview._selection_observers.append(plot)
def on_plot_bar(self, item, navigator):
project = main.project
projectview = main.projectview
ds = self.dataset
dims = ds.get_dim_name()
ids = ds.get_identifiers(dims[1])
plot = plots.BarPlot(ds, name='Bar (%s)' % ds.get_name())
icon = laydi.icon_factory.get("line_plot")
project.data_tree_insert(self.tree_iter, 'Bar plot', plot, None, "black", icon)
plot.set_selection_listener(project.set_selection)
project._selection_observers.append(plot)
projectview.data_tree_insert(self.tree_iter, 'Bar plot', plot, None, "black", icon)
plot.set_selection_listener(projectview.set_selection)
projectview._selection_observers.append(plot)
def on_plot_box(self, item, navigator):
project = main.project
projectview = main.projectview
ds = self.dataset
dims = ds.get_dim_name()
ids = ds.get_identifiers(dims[1])
plot = plots.BoxPlot(ds, name='Box (%s)' % ds.get_name())
icon = laydi.icon_factory.get("line_plot")
project.data_tree_insert(self.tree_iter, 'Box plot', plot, None, "black", icon)
plot.set_selection_listener(project.set_selection)
project._selection_observers.append(plot)
projectview.data_tree_insert(self.tree_iter, 'Box plot', plot, None, "black", icon)
plot.set_selection_listener(projectview.set_selection)
projectview._selection_observers.append(plot)
def on_transpose(self, item, navigator):
project = main.project
projectview = main.projectview
ds = self.dataset.transpose()
ds._name = ds._name + ".T"
icon = laydi.icon_factory.get(ds)
project.data_tree_insert(self.tree_iter, ds.get_name(), ds, None, "black", icon)
projectview.data_tree_insert(self.tree_iter, ds.get_name(), ds, None, "black", icon)
def on_standardise_rows(self, item, navigator):
project = main.project
projectview = main.projectview
ds = self.dataset.copy()
ds._name = self.dataset._name + ".rsc"
axis = 1
ds._array = ds.asarray()/scipy.expand_dims(ds.asarray().std(axis), axis)
icon = laydi.icon_factory.get(ds)
project.data_tree_insert(self.tree_iter, ds.get_name(), ds, None, "black", icon)
projectview.data_tree_insert(self.tree_iter, ds.get_name(), ds, None, "black", icon)
def on_standardise_cols(self, item, navigator):
project = main.project
projectview = main.projectview
ds = self.dataset.copy()
ds._name = self.dataset._name + ".csc"
axis = 0
ds._array = ds.asarray()/scipy.expand_dims(ds.asarray().std(axis), axis)
icon = laydi.icon_factory.get(ds)
project.data_tree_insert(self.tree_iter, ds.get_name(), ds, None, "black", icon)
projectview.data_tree_insert(self.tree_iter, ds.get_name(), ds, None, "black", icon)
def on_log(self, item, navigator):
project = main.project
projectview = main.projectview
try:
if not scipy.all(self.dataset.asarray()>0):
raise ValueError
@ -455,7 +455,7 @@ class NavigatorMenu(gtk.Menu):
ds._array = scipy.log(ds.asarray())
icon = laydi.icon_factory.get(ds)
ds._name = ds._name + ".log"
project.data_tree_insert(self.tree_iter, ds.get_name(), ds, None, "black", icon)
projectview.data_tree_insert(self.tree_iter, ds.get_name(), ds, None, "black", icon)
def on_split(self, item, navigator):
if self.dataset is None:
@ -464,13 +464,13 @@ class NavigatorMenu(gtk.Menu):
dim = self.dataset.get_dim_name(0)
project = main.project
sel_ids = set(project.get_selection()[dim])
projectview = main.projectview
sel_ids = set(projectview.get_selection()[dim])
sel_ds = self.dataset.subdata(dim, sel_ids)
unsel_ids = set(self.dataset.get_identifiers(dim)) - set(sel_ids)
unsel_ds = self.dataset.subdata(dim, unsel_ids)
icon = laydi.icon_factory.get(self.dataset)
project.data_tree_insert(self.tree_iter, 'Selected', sel_ds, None, "black", icon)
project.data_tree_insert(self.tree_iter, 'Unselected', unsel_ds, None, "black", icon)
projectview.data_tree_insert(self.tree_iter, 'Selected', sel_ds, None, "black", icon)
projectview.data_tree_insert(self.tree_iter, 'Unselected', unsel_ds, None, "black", icon)

View File

@ -268,7 +268,7 @@ class IdListController:
if paths==None: return
iters = [self._idstore.get_iter(p) for p in paths]
ids = [self._idstore.get_value(i, 0) for i in iters]
main.project.set_selection(self._dimension, ids)
main.projectview.set_selection(self._dimension, ids)
def _drag_data_received(self, widget, drag_context, x, y,
selection, info, timestamp):
@ -331,9 +331,9 @@ class SelectionListController:
def activate(self):
self._seltree.set_cursor((0,))
def set_project(self, project):
def set_projectview(self, projectview):
"""Dependency injection."""
main.project.add_selection_observer(self)
main.projectview.add_selection_observer(self)
def set_dimlist_controller(self, dimlist_controller):
"""Dependency injection of the dimension list controller."""
@ -381,7 +381,7 @@ class SelectionListController:
di = self._get_dataset_iter(dataset)
if not di:
n_tot = dataset.shape[0]
selection = main.project.get_selection().get(dim_name)
selection = main.projectview.get_selection().get(dim_name)
ds_idents = dataset.get_identifiers(dim_name)
n_cs = len(selection.intersection(ds_idents))
values = (dataset.get_name(), dataset, dim_name, n_cs, n_tot, 2)
@ -452,7 +452,7 @@ class SelectionListController:
"""
dim_name = dataset.get_dim_name(0)
sel_store = self._sel_stores[dim_name]
selection_obj = main.project.get_selection()
selection_obj = main.projectview.get_selection()
current_selection = selection_obj.get(dim_name)
if current_selection==None: return
@ -516,7 +516,7 @@ class SelectionListController:
else:
seltree.expand_row(path, True)
elif isinstance(obj, dataset.Selection):
main.project.set_selection(self._dimension,
main.projectview.set_selection(self._dimension,
obj[self._dimension])
def _on_button_pressed(self, widget, event):
@ -573,12 +573,11 @@ class DimListController:
##
## Public interface
##
def set_project(self, project):
def set_projectview(self, projectview):
"""Dependency injection."""
# self.project = project
self.dim_names = project.dim_names
self.dim_names = projectview.dim_names
self.update_dims()
project.add_dataset_observer(self)
projectview.add_dataset_observer(self)
def get_dimension(self, dim):
"""Returns the iterator to the dimension with the given name, or

View File

@ -427,7 +427,7 @@ class WorkflowMenu (gtk.Menu):
def run_function(function):
logger.log('debug', 'Starting function: %s' % function.name)
parent_data = main.project.current_data
parent_data = main.projectview.current_data
validation = function.validate_input()
@ -464,12 +464,12 @@ def run_function(function):
if pass_selection:
# if the function has a 'selection' argument, we pass in
# the selection
new_data = function.run(selection=main.project.get_selection(), *data)
new_data = function.run(selection=main.projectview.get_selection(), *data)
else:
new_data = function.run(*data)
if new_data != None:
main.project.add_data(parent_data, new_data, function.name)
main.projectview.add_data(parent_data, new_data, function.name)
logger.log('debug', 'Function ended: %s' % function.name)