If argument 'selection' exists in function.run, pass current selection to it.
This commit is contained in:
		@@ -177,8 +177,14 @@ class WorkflowView (gtk.VBox):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        args, varargs, varkw, defaults = inspect.getargspec(function.run)
 | 
					        args, varargs, varkw, defaults = inspect.getargspec(function.run)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # first argument is 'self' and we don't care about that...
 | 
					        # first argument is 'self' and second should be the selection
 | 
				
			||||||
        args = args[1:]
 | 
					        # 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):
 | 
					        if varargs and len(parent_data) < len(args):
 | 
				
			||||||
            logger.log('warning', "Function requires minimum %d datasets selected." % len(args))
 | 
					            logger.log('warning', "Function requires minimum %d datasets selected." % len(args))
 | 
				
			||||||
@@ -188,13 +194,19 @@ class WorkflowView (gtk.VBox):
 | 
				
			|||||||
            logger.log('warning', "Function requires %d datasets, but only %d selected." % (len(args), len(parent_data)))
 | 
					            logger.log('warning', "Function requires %d datasets, but only %d selected." % (len(args), len(parent_data)))
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # we allow functions requiring no data to be run even if
 | 
					 | 
				
			||||||
        # something is selected
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if not args:
 | 
					        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:
 | 
					        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:
 | 
					        if new_data != None:
 | 
				
			||||||
            project.add_data(parent_data, new_data, function.name)
 | 
					            project.add_data(parent_data, new_data, function.name)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user