Added automagic argument checking when running functions.
This commit is contained in:
parent
9f7ee74189
commit
aa3a9ab619
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
import gtk
|
import gtk
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import inspect
|
||||||
from system import logger
|
from system import logger
|
||||||
|
|
||||||
def _workflow_classes(modname):
|
def _workflow_classes(modname):
|
||||||
|
@ -175,16 +175,26 @@ class WorkflowView (gtk.VBox):
|
||||||
logger.log('warning','Invalid Inputdata: ' + str(reason))
|
logger.log('warning','Invalid Inputdata: ' + str(reason))
|
||||||
return
|
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:
|
# first argument is 'self' and we don't care about that...
|
||||||
logger.log('warning','Method requires ' + str(argcount) + ' Data. ' + str(len(parent_data)) + ' selected')
|
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
|
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()
|
new_data = function.run()
|
||||||
else:
|
else:
|
||||||
new_data = function.run(*project.current_data)
|
new_data = function.run(*parent_data)
|
||||||
|
|
||||||
if new_data != None:
|
if new_data != None:
|
||||||
project.add_data(parent_data, new_data, function.name)
|
project.add_data(parent_data, new_data, function.name)
|
||||||
|
|
|
@ -82,13 +82,7 @@ class DatasetSaveFunction(workflow.Function):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
workflow.Function.__init__(self, 'save_data', 'Save Pickled Dataset')
|
workflow.Function.__init__(self, 'save_data', 'Save Pickled Dataset')
|
||||||
|
|
||||||
def run(self):
|
def run(self, data):
|
||||||
if not data:
|
|
||||||
logger.log("notice", "No data to save.")
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
data = data[0]
|
|
||||||
|
|
||||||
chooser = gtk.FileChooserDialog(title="Save pickled data...", parent=None,
|
chooser = gtk.FileChooserDialog(title="Save pickled data...", parent=None,
|
||||||
action=gtk.FILE_CHOOSER_ACTION_SAVE,
|
action=gtk.FILE_CHOOSER_ACTION_SAVE,
|
||||||
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
||||||
|
@ -116,7 +110,7 @@ class CelFileImportFunction(workflow.Function):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
workflow.Function.__init__(self, 'cel_import', 'Import Affy')
|
workflow.Function.__init__(self, 'cel_import', 'Import Affy')
|
||||||
|
|
||||||
def run(self,data):
|
def run(self):
|
||||||
import rpy
|
import rpy
|
||||||
chooser = gtk.FileChooserDialog(title="Select cel files...", parent=None,
|
chooser = gtk.FileChooserDialog(title="Select cel files...", parent=None,
|
||||||
action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||||
|
|
Reference in New Issue