Moved QueueMessage and subclasses from hooke.ui to the more central hooke.engine.
[hooke.git] / hooke / ui / gui / __init__.py
index 5247f93ce3f932811c3e0d13a3402cd2e9f3fa02..8f1e41bfcf81635bf999539bc221d359dfcbae27 100644 (file)
@@ -46,8 +46,9 @@ import wx.lib.evtmgr as evtmgr
 
 from ...command import CommandExit, Exit, Success, Failure, Command, Argument
 from ...config import Setting
+from ...engine import CommandMessage
 from ...interaction import Request, BooleanRequest, ReloadUserInterfaceConfig
-from ...ui import UserInterface, CommandMessage
+from ...ui import UserInterface
 from .dialog.selection import Selection as SelectionDialog
 from .dialog.save_file import select_save_file
 from . import menu as menu
@@ -114,21 +115,7 @@ 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
         #load default list, if possible
         self.do_loadlist(self.GetStringFromConfig('core', 'preferences', 'playlists'))
@@ -194,11 +181,6 @@ 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,
@@ -217,7 +199,10 @@ class HookeFrame (wx.Frame):
 #            ('results', panel.results.Results(self), 'bottom'),
             ]:
             self._add_panel(p, style)
-        #self._c['assistant'].SetEditable(False)
+        self.execute_command(  # setup already loaded playlists
+            command=self._command_by_name('playlists'))
+        self.execute_command(  # setup already loaded curve
+            command=self._command_by_name('get curve'))
 
     def _add_panel(self, panel, style):
         self._c[panel.name] = panel
@@ -336,11 +321,20 @@ class HookeFrame (wx.Frame):
                 index = int(name[len(arg.name):])
                 args[arg.name][index] = value
             for arg in command.arguments:
-                if arg.count != 1 and arg.name in args:
+                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(arg.count), keys
+                    assert keys == range(count), keys
                     args[arg.name] = [args[arg.name][i]
-                                      for i in range(arg.count)]
+                                      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 = []
@@ -406,6 +400,22 @@ class HookeFrame (wx.Frame):
                 self._c['output'].write(result.__class__.__name__+'\n')
             self._c['output'].write(str(result).rstrip()+'\n')
 
+    def _postprocess_playlists(self, command, args={}, results=None):
+        """Update `self` to show the playlists.
+        """
+        if not isinstance(results[-1], Success):
+            self._postprocess_text(command, results=results)
+            return
+        assert len(results) == 2, results
+        playlists = results[0]
+        loaded_playlists = []  # TODO
+        if 'playlist' in self._c:
+            for playlist in playlists:
+                if playlist in loaded_playlists:
+                    self._c['playlist'].update_playlist(playlist)
+                else:
+                    self._c['playlist'].add_playlist(playlist)
+
     def _postprocess_load_playlist(self, command, args={}, results=None):
         """Update `self` to show the playlist.
         """
@@ -414,7 +424,7 @@ class HookeFrame (wx.Frame):
             return
         assert len(results) == 2, results
         playlist = results[0]
-        self._c['playlist']._c['tree'].add_playlist(playlist)
+        self._c['playlist'].add_playlist(playlist)
 
     def _postprocess_get_playlist(self, command, args={}, results=[]):
         if not isinstance(results[-1], Success):
@@ -422,7 +432,7 @@ class HookeFrame (wx.Frame):
             return
         assert len(results) == 2, results
         playlist = results[0]
-        self._c['playlist']._c['tree'].update_playlist(playlist)
+        self._c['playlist'].update_playlist(playlist)
 
     def _postprocess_get_curve(self, command, args={}, results=[]):
         """Update `self` to show the curve.
@@ -442,7 +452,7 @@ class HookeFrame (wx.Frame):
         if 'note' in self._c:
             self._c['note'].set_text(curve.info['note'])
         if 'playlist' in self._c:
-            self._c['playlist']._c['tree'].set_selected_curve(
+            self._c['playlist'].set_selected_curve(
                 playlist, curve)
         if 'plot' in self._c:
             self._c['plot'].set_curve(curve, config=self.gui.config)
@@ -674,8 +684,6 @@ 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: