Updated FlatFilterCommand's argument handling.
authorW. Trevor King <wking@drexel.edu>
Wed, 11 Aug 2010 23:46:46 +0000 (19:46 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 11 Aug 2010 23:46:46 +0000 (19:46 -0400)
hooke/plugin/flatfilt.py

index 7c0b5346f9b659d7ec145df7b86b95b716b5539a..2688bba32dff41b1b531463304de47188197d414 100644 (file)
@@ -84,7 +84,10 @@ Minimum number of peaks for curve acceptance.
             self._settings.append(argument_to_setting(
                     self.setting_section, argument))
             argument.default = None # if argument isn't given, use the config.
-        self._commands = [FlatPeaksCommand(self), FlatFilterCommand(self)]
+        self._commands = [FlatPeaksCommand(self)]
+        # append FlatFilterCommand so it can steal arguments from
+        # FlatPeaksCommand.
+        self._commands.append(FlatFilterCommand(self))
 
     def dependencies(self):
         return ['vclamp']
@@ -171,7 +174,8 @@ dictionary.
             raise Failure('%s operates on VelocityClamp experiments, not %s'
                           % (self.name, curve.info['experiment']))
         for key,value in params.items():
-            if value == None: # Use configured default value.
+            if value == None and key in self.plugin.config:
+                # Use configured default value.
                 params[key] = self.plugin.config[key]
         # TODO: convert 'see double' from nm to points
         name,def_unit = split_data_label(params['deflection column'])
@@ -209,9 +213,15 @@ class FlatFilterCommand (FilterCommand):
     FlatPeaksCommand : Underlying flat-based peak detection.
     """
     def __init__(self, plugin):
+        flat_peaks = [c for c in plugin._commands
+                      if c.name == 'flat filter peaks'][0]
+        flat_peaks_arg_names = [a.name for a in flat_peaks.arguments]
+        plugin_arguments = [a for a in plugin._arguments
+                            if a.name not in flat_peaks_arg_names]
+        arguments = flat_peaks.arguments + plugin_arguments
         super(FlatFilterCommand, self).__init__(
             plugin, name='flat filter playlist')
-        self.arguments.extend(plugin._arguments)  # TODO: curve & block arguments
+        self.arguments.extend(arguments)
 
     def filter(self, curve, hooke, inqueue, outqueue, params):
         params['curve'] = curve
@@ -226,7 +236,8 @@ class FlatFilterCommand (FilterCommand):
             return False
         if not (isinstance(peaks, list) and (len(peaks) == 0
                                              or isinstance(peaks[0], Peak))):
-            raise Failure('Expected a list of Peaks, not %s' % peaks)
+            raise Failure('Expected a list of Peaks, not %s: %s'
+                          % (type(peaks), peaks))
         ret = outq.get()
         if not isinstance(ret, Success):
             raise ret