Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Removed need to provide plots with project/workflow on creation, is instead injected by project itself when added to it.

This commit is contained in:
Truls Alexander Tangstad 2006-04-24 14:42:45 +00:00
parent b807f27874
commit 6c72dec7fa
4 changed files with 23 additions and 23 deletions

View File

@ -161,15 +161,12 @@ class LargeView (gtk.Frame):
class Plot (gtk.Frame): class Plot (gtk.Frame):
def __init__(self,project): def __init__(self):
gtk.Frame.__init__(self) gtk.Frame.__init__(self)
self.project = project
self.mark_active(False) self.mark_active(False)
self.connect('button_press_event', self.on_button_press) self.connect('button_press_event', self.on_button_press)
self.sel_obj = None self.sel_obj = None
self.active = False self.active = False
if project!=None: #its not an Emptyview
project.attach(self,'selection_update')
def on_button_press(self, *rest): def on_button_press(self, *rest):
# logger.log('debug', 'button pressed in plot') # logger.log('debug', 'button pressed in plot')
@ -182,12 +179,16 @@ class Plot (gtk.Frame):
self.set_shadow_type(gtk.SHADOW_OUT) self.set_shadow_type(gtk.SHADOW_OUT)
self.active = active self.active = active
def update(self,project,key): def update(self, key):
pass pass
def set_project(self, project):
self.project = project
class EmptyView (Plot): class EmptyView (Plot):
def __init__(self): def __init__(self):
Plot.__init__(self,None) Plot.__init__(self)
label = gtk.Label('No view') label = gtk.Label('No view')
ebox = gtk.EventBox() ebox = gtk.EventBox()
@ -211,8 +212,8 @@ class EmptyView (Plot):
class SinePlot(Plot): class SinePlot(Plot):
def __init__(self,project): def __init__(self):
Plot.__init__(self,project) Plot.__init__(self)
fig = Figure(figsize=(5,4), dpi=72) fig = Figure(figsize=(5,4), dpi=72)
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
t = arange(0.0,3.0,0.01) t = arange(0.0,3.0,0.01)
@ -224,9 +225,8 @@ class SinePlot(Plot):
class ScatterPlot(Plot): class ScatterPlot(Plot):
def __init__(self,project,dataset,id_dim,sel_dim,id_1,id_2): def __init__(self, dataset, id_dim, sel_dim, id_1, id_2):
Plot.__init__(self,project) Plot.__init__(self)
self.project = project
fig = Figure(figsize=(5,4), dpi=72) fig = Figure(figsize=(5,4), dpi=72)
self.ax = ax = fig.add_subplot(111) self.ax = ax = fig.add_subplot(111)
self.current_dim = id_dim self.current_dim = id_dim
@ -272,8 +272,8 @@ class ScatterPlot(Plot):
ids = [id for id,ind in self.dataset[self.current_dim].items() if ind in index] ids = [id for id,ind in self.dataset[self.current_dim].items() if ind in index]
self.project.set_selection(self.current_dim,ids) self.project.set_selection(self.current_dim,ids)
def update(self,project,key): def update(self, key):
curr_sel = project.get_selection() # get selection object curr_sel = self.project.get_selection() # get selection object
ids = curr_sel[self.current_dim] # current identifiers ids = curr_sel[self.current_dim] # current identifiers
index = [ind for id,ind in self.dataset[self.current_dim].items() if id in ids] #conversion to index index = [ind for id,ind in self.dataset[self.current_dim].items() if id in ids] #conversion to index
@ -283,5 +283,3 @@ class ScatterPlot(Plot):
self.ax.plot(self.xaxis_data,self.yaxis_data,'og') self.ax.plot(self.xaxis_data,self.yaxis_data,'og')
self.ax.plot(xdata_new,ydata_new,'or') self.ax.plot(xdata_new,ydata_new,'or')
self.canvas.draw() self.canvas.draw()

View File

@ -35,7 +35,7 @@ class Project:
"""Notifies observers""" """Notifies observers"""
for observer in self._observers[key]: for observer in self._observers[key]:
if modifier != observer: if modifier != observer:
observer.update(self,key) observer.update(key)
def set_selection(self,dim_name,selection): def set_selection(self,dim_name,selection):
"""Sets a current selection and notify observers""" """Sets a current selection and notify observers"""
@ -58,6 +58,8 @@ class Project:
elif isinstance(d, plots.Plot): elif isinstance(d, plots.Plot):
# self.add_view(d) # self.add_view(d)
self.data_tree_insert(None, 'view', d) self.data_tree_insert(None, 'view', d)
d.set_project(self)
self.attach(d, 'selection_update')
def data_tree_insert(self, parent, text, data): def data_tree_insert(self, parent, text, data):
tree = self.data_tree tree = self.data_tree

View File

@ -107,7 +107,7 @@ class TestDataFunction(Function):
logger.log('notice', 'Injecting foo test data') logger.log('notice', 'Injecting foo test data')
x = randn(20,30) x = randn(20,30)
X = dataset.Dataset(x) X = dataset.Dataset(x)
return [X, plots.SinePlot(None)] return [X, plots.SinePlot()]
class DatasetLoadFunction(Function): class DatasetLoadFunction(Function):
@ -239,8 +239,8 @@ class PCAFunction(Function):
# cleanup # cleanup
rpy.r.rm(["t", "m"]) rpy.r.rm(["t", "m"])
loading_plot1 = plots.ScatterPlot(self._workflow.project,P,'ids','component','1','2') loading_plot1 = plots.ScatterPlot(P,'ids','component','1','2')
loading_plot2 = plots.ScatterPlot(self._workflow.project,P,'ids','component','3','4') loading_plot2 = plots.ScatterPlot(P,'ids','component','3','4')
score_plot = plots.ScatterPlot(self._workflow.project,T,'filename','component','1','2') score_plot = plots.ScatterPlot(T,'filename','component','1','2')
return [T, P, loading_plot1, loading_plot2, score_plot] return [T, P, loading_plot1, loading_plot2, score_plot]

View File

@ -102,9 +102,9 @@ class PCAFunction(Function):
#tsq = dataset.Dataset(tsq,[singel_def,data_ids[1]) #tsq = dataset.Dataset(tsq,[singel_def,data_ids[1])
## plots ## plots
loading_plot1 = plots.ScatterPlot(self.workflow.project,P,'genes','comp','1','2') loading_plot1 = plots.ScatterPlot(P,'genes','comp','1','2')
loading_plot2 = plots.ScatterPlot(self.workflow.project,P,'genes','comp','3','4') loading_plot2 = plots.ScatterPlot(P,'genes','comp','3','4')
score_plot = plots.ScatterPlot(self.workflow.project,T,'samples','comp','1','2') score_plot = plots.ScatterPlot(T,'samples','comp','1','2')
return [T,P,E,loading_plot1,loading_plot2,score_plot] return [T,P,E,loading_plot1,loading_plot2,score_plot]