From 98445498b5b5eb9525355227b79f2733c373e95e Mon Sep 17 00:00:00 2001 From: tangstad Date: Fri, 5 May 2006 13:10:54 +0000 Subject: [PATCH] If argument 'selection' exists in function.run, pass current selection to it. --- system/workflow.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/system/workflow.py b/system/workflow.py index 6780224..b993a2d 100644 --- a/system/workflow.py +++ b/system/workflow.py @@ -177,8 +177,14 @@ class WorkflowView (gtk.VBox): args, varargs, varkw, defaults = inspect.getargspec(function.run) - # first argument is 'self' and we don't care about that... - args = args[1:] + # 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)) @@ -188,14 +194,20 @@ class WorkflowView (gtk.VBox): logger.log('warning', "Function requires %d datasets, but only %d selected." % (len(args), len(parent_data))) return - # we allow functions requiring no data to be run even if - # something is selected - if not args: - new_data = function.run() + # we allow functions requiring no data to be run even if a + # dataset is is selected + data = [] else: - new_data = function.run(*parent_data) - + data = parent_data + + if pass_selection: + # if the function has a 'selection' argument, we pass in + # the selection + new_data = function.run(selection=project.get_selection(), *data) + else: + new_data = function.run(*data) + if new_data != None: project.add_data(parent_data, new_data, function.name)