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.
This commit is contained in:
parent
82dacc3dd1
commit
1a4d73f26b
|
@ -174,7 +174,7 @@ class FluentApp:
|
||||||
wf_menuitem.set_submenu(self._wf_menu)
|
wf_menuitem.set_submenu(self._wf_menu)
|
||||||
wf_menuitem.show()
|
wf_menuitem.show()
|
||||||
|
|
||||||
self['menubar1'].insert(wf_menuitem, 3)
|
self['menubar1'].insert(wf_menuitem, 2)
|
||||||
|
|
||||||
# Connect signals
|
# Connect signals
|
||||||
signals = {'on_quit1_activate' : (gtk.main_quit),
|
signals = {'on_quit1_activate' : (gtk.main_quit),
|
||||||
|
|
|
@ -170,7 +170,7 @@ class WorkflowView (gtk.VBox):
|
||||||
for fun in stage.functions:
|
for fun in stage.functions:
|
||||||
btn = gtk.Button(fun.name)
|
btn = gtk.Button(fun.name)
|
||||||
btn.connect('clicked',
|
btn.connect('clicked',
|
||||||
lambda button, f=fun : self.run_function(f))
|
lambda button, f=fun : run_function(f))
|
||||||
|
|
||||||
btn_box.add(btn)
|
btn_box.add(btn)
|
||||||
btn.show()
|
btn.show()
|
||||||
|
@ -188,54 +188,6 @@ class WorkflowView (gtk.VBox):
|
||||||
self.remove_workflow()
|
self.remove_workflow()
|
||||||
self.setup_workflow(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):
|
class Options(dict):
|
||||||
"""Options base class.
|
"""Options base class.
|
||||||
|
@ -456,8 +408,59 @@ class WorkflowMenu (gtk.Menu):
|
||||||
stage_menu.append(self._create_function_item(fun))
|
stage_menu.append(self._create_function_item(fun))
|
||||||
return stage_menu_item
|
return stage_menu_item
|
||||||
|
|
||||||
def _create_function_item(self, function):
|
def _create_function_item(self, func):
|
||||||
menuitem = gtk.MenuItem(function.name)
|
menuitem = gtk.MenuItem(func.name)
|
||||||
|
menuitem.connect('activate',
|
||||||
|
lambda item, f=func : run_function(f))
|
||||||
menuitem.show()
|
menuitem.show()
|
||||||
return menuitem
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue