Collapse None entries for Argument.count == -1 in the GUI
[hooke.git] / hooke / ui / gui / __init__.py
index 5eeff7da16ebc680343581d9dbd9af4b8d86941d..1c646f4396cc82429da7eb82cc55a601902b18f8 100644 (file)
@@ -53,7 +53,7 @@ from .dialog.save_file import select_save_file
 from . import menu as menu
 from . import navbar as navbar
 from . import panel as panel
-from .panel.propertyeditor import prop_from_argument, prop_from_setting
+from .panel.propertyeditor import props_from_argument, props_from_setting
 from . import statusbar as statusbar
 
 
@@ -115,10 +115,18 @@ class HookeFrame (wx.Frame):
         self._setup_perspectives()
         self._bind_events()
 
+        self.execute_command(
+                command=self._command_by_name('load playlist'),
+                args={'input':'test/data/test'},#vclamp_picoforce/playlist'},
+                )
         self.execute_command(
                 command=self._command_by_name('load playlist'),
                 args={'input':'test/data/vclamp_picoforce/playlist'},
                 )
+        self.execute_command(
+                command=self._command_by_name('polymer fit'),
+                args={'block':1, 'bounds':[918, 1103]},
+                )
         return # TODO: cleanup
         self.playlists = self._c['playlist'].Playlists
         self._displayed_plot = None
@@ -186,13 +194,9 @@ class HookeFrame (wx.Frame):
                     style=wx.WANTS_CHARS,
                     # WANTS_CHARS so the panel doesn't eat the Return key.
                     ), 'center'),
-#            ('assistant', wx.TextCtrl(
-#                    parent=self,
-#                    pos=wx.Point(0, 0),
-#                    size=wx.Size(150, 90),
-#                    style=wx.NO_BORDER|wx.TE_MULTILINE), 'right'),
             (panel.PANELS['plot'](
                     callbacks={
+                        '_set_status_text': self._on_plot_status_text,
                         },
                     parent=self,
                     style=wx.WANTS_CHARS|wx.NO_BORDER,
@@ -208,7 +212,6 @@ class HookeFrame (wx.Frame):
 #            ('results', panel.results.Results(self), 'bottom'),
             ]:
             self._add_panel(p, style)
-        #self._c['assistant'].SetEditable(False)
 
     def _add_panel(self, panel, style):
         self._c[panel.name] = panel
@@ -313,10 +316,34 @@ class HookeFrame (wx.Frame):
             args = {}
         if ('property editor' in self._c
             and self.gui.config['selected command'] == command):
-            arg_names = [arg.name for arg in command.arguments]
             for name,value in self._c['property editor'].get_values().items():
-                if name in arg_names:
-                    args[name] = value
+                arg = self._c['property editor']._argument_from_label.get(
+                    name, None)
+                if arg == None:
+                    continue
+                elif arg.count == 1:
+                    args[arg.name] = value
+                    continue
+                # deal with counted arguments
+                if arg.name not in args:
+                    args[arg.name] = {}
+                index = int(name[len(arg.name):])
+                args[arg.name][index] = value
+            for arg in command.arguments:
+                count = arg.count
+                if hasattr(arg, '_display_count'):  # support HACK in props_from_argument()
+                    count = arg._display_count
+                if count != 1 and arg.name in args:
+                    keys = sorted(args[arg.name].keys())
+                    assert keys == range(count), keys
+                    args[arg.name] = [args[arg.name][i]
+                                      for i in range(count)]
+                if arg.count == -1:
+                    while (len(args[arg.name]) > 0
+                           and args[arg.name][-1] == None):
+                        args[arg.name].pop()
+                    if len(args[arg.name]) == 0:
+                        args[arg.name] = arg.default
         self.log.debug('executing %s with %s' % (command.name, args))
         self.inqueue.put(CommandMessage(command, args))
         results = []
@@ -650,9 +677,8 @@ class HookeFrame (wx.Frame):
 
     def select_command(self, _class, method, command):
         #self.select_plugin(plugin=command.plugin)
-        if 'assistant' in self._c:
-            self._c['assitant'].ChangeValue(command.help)
         self._c['property editor'].clear()
+        self._c['property editor']._argument_from_label = {}
         for argument in command.arguments:
             if argument.name == 'help':
                 continue
@@ -673,11 +699,14 @@ class HookeFrame (wx.Frame):
             else:
                 curves = results[0]
 
-            p = prop_from_argument(
+            ret = props_from_argument(
                 argument, curves=curves, playlists=playlists)
-            if p == None:
+            if ret == None:
                 continue  # property intentionally not handled (yet)
-            self._c['property editor'].append_property(p)
+            for label,p in ret:
+                self._c['property editor'].append_property(p)
+                self._c['property editor']._argument_from_label[label] = (
+                    argument)
 
         self.gui.config['selected command'] = command  # TODO: push to engine
 
@@ -707,6 +736,7 @@ class HookeFrame (wx.Frame):
         pass
 
     def _on_delete_curve(self, _class, method, playlist, curve):
+        # TODO: execute_command 'remove curve from playlist'
         os.remove(curve.path)
 
     def _on_set_selected_playlist(self, _class, method, playlist):
@@ -744,6 +774,14 @@ class HookeFrame (wx.Frame):
 
 
 
+    # Plot panel interface
+
+    def _on_plot_status_text(self, _class, method, text):
+        if 'status bar' in self._c:
+            self._c['status bar'].set_plot_text(text)
+
+
+
     # Navbar interface
 
     def _next_curve(self, *args):
@@ -885,6 +923,8 @@ class HookeFrame (wx.Frame):
             style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
         dialog.CenterOnScreen()
         dialog.ShowModal()
+        if dialog.canceled == True:
+            return
         names = [options[i] for i in dialog.selected]
         dialog.Destroy()
         self._delete_perspectives(