diff --git a/fluent b/fluent index 3c3fcf1..4e8f237 100755 --- a/fluent +++ b/fluent @@ -2,7 +2,6 @@ import sys sys.path.append('system') -sys.path.append('workflows') import dialogs import pygtk @@ -19,8 +18,6 @@ import dataset import logger import plots import navigator -#import go_workflow -#import pca_workflow import scipy PROGRAM_NAME = 'fluent' @@ -37,7 +34,6 @@ class FluentApp: gtk.glade.set_custom_handler(self.custom_object_factory) self.widget_tree = gtk.glade.XML(GLADEFILENAME, 'appwindow') self.workflow = workflow.EmptyWorkflow(self) -# self.workflow.add_project(self.project) def set_project(self, project): logger.log('notice', 'Creating a new project') @@ -124,7 +120,6 @@ class FluentApp: return self.widget_tree.get_widget(key) def on_create_project(self, *rest): - logger.log('error', 'FIXME: Create project') d = dialogs.CreateProjectDruid(self) d.run() diff --git a/system/dialogs.py b/system/dialogs.py new file mode 100644 index 0000000..03c6fd9 --- /dev/null +++ b/system/dialogs.py @@ -0,0 +1,111 @@ +import pygtk +pygtk.require('2.0') +import gtk +import gobject +import logger +import project +import workflows +import workflow +import sys +import os + +GLADEFILENAME = 'system/fluent.glade' + +class CreateProjectDruid(gtk.Window): + """A druid for creating a new project. + + The CreateProjectDruid gets a list of all classes derived from + Workflow, and asks the user to select one of these. A new project of + the selected class is added to the application.""" + + def __init__(self, app): + gtk.Window.__init__(self) + self.app = app + self.widget_tree = gtk.glade.XML(GLADEFILENAME, 'new_project_druid') + self.workflows = self.make_workflow_list() + self.selected = None + + renderer = gtk.CellRendererText() + wf_name = gtk.TreeViewColumn('Workflow Name', renderer, text=0) + self['workflow_list'].insert_column(wf_name, 0) + + self.wf_info = gtk.TextBuffer() + self['workflow_info'].set_buffer(self.wf_info) + + def workflow_classes(self, modname): + """Returns a list of all subclasses of Workflow in a given module""" + workflow_classes = [] + + __import__('workflows.%s' % modname) + module = sys.modules['workflows.%s' % modname] + + d = module.__dict__ + for wf in d.values(): + try: + if issubclass(wf, workflow.Workflow): + workflow_classes.append(wf) + except TypeError, e: + pass + return workflow_classes + + def make_workflow_list(self): + """Returns a ListStore containing all new workflows""" + store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT) + + # List all .py files that can contain workflow classes + wf_path = sys.modules['workflows'].__path__ + wf_files = [] + + for dir in wf_path: + for fn in os.listdir(dir): + if fn.endswith('.py'): + wf_files.append(fn[:-3]) + + # Try to load each file and look for Workflow derived classes + for fn in wf_files: + try: + wf_info = self.workflow_classes(fn) + for wf in wf_info: + store.insert_after(None, (getattr(wf, 'name'), wf)) + except Exception, e: + logger.log('warning', 'Cannot load workflow: %s' % fn) + + return store + + def __getitem__(self, key): + return self.widget_tree.get_widget(key) + + def run(self): + self['workflow_list'].set_model(self.workflows) + + self['druidpagestart1'].show() + self['druidpagefinish1'].show() + self['new_project_druid'].show() + + self['druidpagefinish1'].connect('finish', self.finish) + self['workflow_list'].connect('cursor_changed', self.selection_updated) + self.connect('destroy', self.delete) + + def delete(self, widget): + return False + + def hide(self): + self['druidpagestart1'].hide() + self['druidpagefinish1'].hide() + self['new_project_druid'].hide() + gtk.Window.hide(self) + + def finish(self, *rest): + tree, it = self['workflow_list'].get_selection().get_selected() + wf = self.workflows.get_value(it, 1) + proj = project.Project() + self.app.set_workflow(wf(self.app)) + self.app.set_project(proj) + self.hide() + self.destroy() + + def selection_updated(self, *rest): + tree, it = self['workflow_list'].get_selection().get_selected() + wf = self.workflows.get_value(it, 1) + self.wf_info.set_text(wf.description) + diff --git a/system/fluent.glade b/system/fluent.glade index e6d9080..509637a 100644 --- a/system/fluent.glade +++ b/system/fluent.glade @@ -637,7 +637,7 @@ The functions of the workflow you select will be available on the right part of 0 - True + False True diff --git a/system/workflow.py b/system/workflow.py index 171495a..822f55c 100644 --- a/system/workflow.py +++ b/system/workflow.py @@ -11,6 +11,7 @@ class Workflow: """ name = "Workflow" + description = "Workflow Description" def __init__(self, app): self.stages = [] @@ -100,7 +101,6 @@ class WorkflowView (gtk.VBox): self.pack_start(exp, expand=False, fill=False) def remove_workflow(self): - print self.get_children() for c in self.get_children(): c.hide() self.remove(c) @@ -109,8 +109,6 @@ class WorkflowView (gtk.VBox): self.workflow = workflow self.remove_workflow() self.setup_workflow(workflow) - print workflow - logger.log('notice', 'Created new workflow') def run_function(self, function): logger.log('debug', 'Starting function: %s' % function.name) diff --git a/workflows/go_workflow.py b/workflows/go_workflow.py index eaaea64..d41c8f5 100644 --- a/workflows/go_workflow.py +++ b/workflows/go_workflow.py @@ -12,6 +12,7 @@ import cPickle class EinarsWorkflow (Workflow): name = 'Test Workflow' + description = 'Gene Ontology Workflow. This workflow currently serves as a general testing workflow.' def __init__(self, app): Workflow.__init__(self, app)