From 1a4d73f26b6dee4cf5cb2a9fd58c427c0d61186b Mon Sep 17 00:00:00 2001 From: einarr Date: Mon, 10 Dec 2007 16:57:38 +0000 Subject: [PATCH] Fixed the function menu. It now works, is placed before "Help", and the method for running a function is moved to the workflow module instead of being hidden the WorkflowView. --- fluents/fluents.py | 2 +- fluents/workflow.py | 105 +++++++++++++++++++++++--------------------- 2 files changed, 55 insertions(+), 52 deletions(-) diff --git a/fluents/fluents.py b/fluents/fluents.py index 4ab1a27..9e8138f 100644 --- a/fluents/fluents.py +++ b/fluents/fluents.py @@ -174,7 +174,7 @@ class FluentApp: wf_menuitem.set_submenu(self._wf_menu) wf_menuitem.show() - self['menubar1'].insert(wf_menuitem, 3) + self['menubar1'].insert(wf_menuitem, 2) # Connect signals signals = {'on_quit1_activate' : (gtk.main_quit), diff --git a/fluents/workflow.py b/fluents/workflow.py index d21fcbf..6509e51 100644 --- a/fluents/workflow.py +++ b/fluents/workflow.py @@ -170,7 +170,7 @@ class WorkflowView (gtk.VBox): for fun in stage.functions: btn = gtk.Button(fun.name) btn.connect('clicked', - lambda button, f=fun : self.run_function(f)) + lambda button, f=fun : run_function(f)) btn_box.add(btn) btn.show() @@ -188,54 +188,6 @@ class WorkflowView (gtk.VBox): self.remove_workflow() self.setup_workflow(workflow) - def run_function(self, function): - logger.log('debug', 'Starting function: %s' % function.name) - parent_data = main.project.current_data - - validation = function.validate_input() - - if not validation.succeeded: - logger.log('warning','Invalid Inputdata: ' + str(reason)) - return - - args, varargs, varkw, defaults = inspect.getargspec(function.run) - - # first argument is 'self' and second should be the selection - # and we don't care about those... - args.remove('self') - if "selection" in args: - pass_selection = True - args.remove('selection') - else: - pass_selection = False - - if varargs and len(parent_data) < len(args): - logger.log('warning', "Function requires minimum %d datasets selected." % len(args)) - return - elif not varargs and args and len(args) != len(parent_data): - # functions requiring datasets have to have the right number - logger.log('warning', "Function requires %d datasets, but only %d selected." % (len(args), len(parent_data))) - return - - if not args: - # we allow functions requiring no data to be run even if a - # dataset is is selected - data = [] - else: - data = parent_data - - 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) - else: - new_data = function.run(*data) - - if new_data != None: - main.project.add_data(parent_data, new_data, function.name) - - logger.log('debug', 'Function ended: %s' % function.name) - class Options(dict): """Options base class. @@ -456,8 +408,59 @@ class WorkflowMenu (gtk.Menu): stage_menu.append(self._create_function_item(fun)) return stage_menu_item - def _create_function_item(self, function): - menuitem = gtk.MenuItem(function.name) + def _create_function_item(self, func): + menuitem = gtk.MenuItem(func.name) + menuitem.connect('activate', + lambda item, f=func : run_function(f)) menuitem.show() return menuitem +def run_function(function): + logger.log('debug', 'Starting function: %s' % function.name) + parent_data = main.project.current_data + + validation = function.validate_input() + + if not validation.succeeded: + logger.log('warning','Invalid Inputdata: ' + str(reason)) + return + + args, varargs, varkw, defaults = inspect.getargspec(function.run) + + # first argument is 'self' and second should be the selection + # and we don't care about those... + args.remove('self') + if "selection" in args: + pass_selection = True + args.remove('selection') + else: + pass_selection = False + + if varargs and len(parent_data) < len(args): + logger.log('warning', "Function requires minimum %d datasets selected." % len(args)) + return + elif not varargs and args and len(args) != len(parent_data): + # functions requiring datasets have to have the right number + logger.log('warning', "Function requires %d datasets, but only %d selected." % (len(args), len(parent_data))) + return + + if not args: + # we allow functions requiring no data to be run even if a + # dataset is is selected + data = [] + else: + data = parent_data + + 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) + else: + new_data = function.run(*data) + + if new_data != None: + main.project.add_data(parent_data, new_data, function.name) + + logger.log('debug', 'Function ended: %s' % function.name) + +