Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Added automagic argument checking when running functions.

This commit is contained in:
Truls Alexander Tangstad 2006-05-05 10:10:03 +00:00
parent 9f7ee74189
commit aa3a9ab619
2 changed files with 20 additions and 16 deletions

View File

@ -1,7 +1,7 @@
import gtk
import sys
import os
import inspect
from system import logger
def _workflow_classes(modname):
@ -175,16 +175,26 @@ class WorkflowView (gtk.VBox):
logger.log('warning','Invalid Inputdata: ' + str(reason))
return
argcount =function.run.func_code.co_argcount - 1
args, varargs, varkw, defaults = inspect.getargspec(function.run)
if argcount != len(parent_data) and argcount != 0:
logger.log('warning','Method requires ' + str(argcount) + ' Data. ' + str(len(parent_data)) + ' selected')
# first argument is 'self' and we don't care about that...
args = args[1:]
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 project.current_data or argcount == 0:
# we allow functions requiring no data to be run even if
# something is selected
if not args:
new_data = function.run()
else:
new_data = function.run(*project.current_data)
new_data = function.run(*parent_data)
if new_data != None:
project.add_data(parent_data, new_data, function.name)

View File

@ -82,13 +82,7 @@ class DatasetSaveFunction(workflow.Function):
def __init__(self):
workflow.Function.__init__(self, 'save_data', 'Save Pickled Dataset')
def run(self):
if not data:
logger.log("notice", "No data to save.")
return
else:
data = data[0]
def run(self, data):
chooser = gtk.FileChooserDialog(title="Save pickled data...", parent=None,
action=gtk.FILE_CHOOSER_ACTION_SAVE,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
@ -116,7 +110,7 @@ class CelFileImportFunction(workflow.Function):
def __init__(self):
workflow.Function.__init__(self, 'cel_import', 'Import Affy')
def run(self,data):
def run(self):
import rpy
chooser = gtk.FileChooserDialog(title="Select cel files...", parent=None,
action=gtk.FILE_CHOOSER_ACTION_OPEN,