2006-04-16 20:25:54 +02:00
|
|
|
|
|
|
|
import gtk
|
|
|
|
import logger
|
|
|
|
|
|
|
|
class Workflow:
|
|
|
|
"""Defines a workflow that contains a set of analysis stages.
|
|
|
|
|
|
|
|
A Workflow is a set of analysis stages for a certain type of analysis.
|
|
|
|
Each stage contains some possible operations to do accomplish that
|
|
|
|
task.
|
|
|
|
"""
|
|
|
|
|
2006-04-22 23:46:44 +02:00
|
|
|
name = "Workflow"
|
2006-04-23 00:29:02 +02:00
|
|
|
description = "Workflow Description"
|
2006-04-22 23:46:44 +02:00
|
|
|
|
2006-04-16 20:25:54 +02:00
|
|
|
def __init__(self, app):
|
|
|
|
self.stages = []
|
|
|
|
self.stages_by_id = {}
|
|
|
|
self.app = app
|
|
|
|
|
|
|
|
def add_stage(self, stage):
|
|
|
|
self.stages.append(stage)
|
|
|
|
self.stages_by_id[stage.id] = stage
|
|
|
|
|
|
|
|
def print_tree(self):
|
|
|
|
print self.name
|
|
|
|
for stage in self.stages:
|
|
|
|
print ' %s' % stage.name
|
|
|
|
for fun in stage.functions:
|
|
|
|
print ' %s' % fun.name
|
|
|
|
|
2006-04-20 17:30:29 +02:00
|
|
|
def add_project(self,project):
|
|
|
|
self.project = project
|
|
|
|
|
2006-04-22 23:46:44 +02:00
|
|
|
class EmptyWorkflow(Workflow):
|
|
|
|
name = 'Empty Workflow'
|
|
|
|
|
|
|
|
def __init__(self, app):
|
|
|
|
Workflow.__init__(self, None)
|
|
|
|
|
2006-04-16 20:25:54 +02:00
|
|
|
class Stage:
|
|
|
|
"""A stage is a part of the data analysis process.
|
|
|
|
|
|
|
|
Each stage contains a set of functions that can be used to
|
|
|
|
accomplish the task. A typical early stage is 'preprocessing', which
|
|
|
|
can be done in several ways, each represented by a function.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, id, name):
|
|
|
|
self.id = id
|
|
|
|
self.name = name
|
|
|
|
self.functions = []
|
|
|
|
self.functions_by_id = {}
|
|
|
|
|
|
|
|
def add_function(self, fun):
|
|
|
|
self.functions.append(fun)
|
|
|
|
self.functions_by_id[fun.id] = fun
|
|
|
|
|
|
|
|
class Function:
|
|
|
|
"""A Function object encapsulates a function on a data set.
|
|
|
|
|
|
|
|
Each Function instance encapsulates some function that can be applied
|
|
|
|
to one or more types of data.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, id, name):
|
|
|
|
self.id = id
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def valid_input(input):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def run(self, data):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class WorkflowView (gtk.VBox):
|
|
|
|
|
|
|
|
def __init__(self, wf):
|
|
|
|
gtk.VBox.__init__(self)
|
|
|
|
self.workflow = wf
|
2006-04-22 23:46:44 +02:00
|
|
|
self.setup_workflow(wf)
|
2006-04-16 20:25:54 +02:00
|
|
|
|
2006-04-22 23:46:44 +02:00
|
|
|
def setup_workflow(self, wf):
|
2006-04-16 20:25:54 +02:00
|
|
|
# Add stage in the process
|
|
|
|
for stage in wf.stages:
|
|
|
|
exp = gtk.Expander(stage.name)
|
|
|
|
btn_box = gtk.VBox()
|
|
|
|
btn_box.show()
|
|
|
|
exp.add(btn_box)
|
|
|
|
|
|
|
|
# Add functions in each stage
|
|
|
|
for fun in stage.functions:
|
|
|
|
btn = gtk.Button(fun.name)
|
|
|
|
btn.connect('clicked', self.button_click_handler)
|
|
|
|
btn.function = fun
|
|
|
|
|
|
|
|
btn_box.add(btn)
|
|
|
|
btn.show()
|
|
|
|
|
|
|
|
exp.show()
|
|
|
|
self.pack_start(exp, expand=False, fill=False)
|
|
|
|
|
2006-04-22 23:46:44 +02:00
|
|
|
def remove_workflow(self):
|
|
|
|
for c in self.get_children():
|
|
|
|
c.hide()
|
|
|
|
self.remove(c)
|
|
|
|
|
|
|
|
def set_workflow(self, workflow):
|
|
|
|
self.workflow = workflow
|
|
|
|
self.remove_workflow()
|
|
|
|
self.setup_workflow(workflow)
|
|
|
|
|
2006-04-19 21:59:55 +02:00
|
|
|
def run_function(self, function):
|
2006-04-16 20:25:54 +02:00
|
|
|
logger.log('debug', 'Starting function: %s' % function.name)
|
2006-04-19 21:59:55 +02:00
|
|
|
project = self.workflow.app.project
|
|
|
|
new_data = function.run(project.current_data)
|
|
|
|
if new_data != None:
|
2006-04-20 16:29:13 +02:00
|
|
|
project.add_data(None, new_data)
|
2006-04-16 20:25:54 +02:00
|
|
|
logger.log('debug', 'Function ended: %s' % function.name)
|
2006-04-19 21:59:55 +02:00
|
|
|
|
|
|
|
def button_click_handler(self, button):
|
|
|
|
self.run_function(function = button.function)
|
2006-04-16 20:25:54 +02:00
|
|
|
|