Patch GUI to handle 'new playlist' and 'glob curves to playlist'
[hooke.git] / hooke / ui / gui / __init__.py
index 38bf191d4a2629377bdbec58fff0e1757d1b324b..034003b7d5278539d417b1dcddf19c06f7a3de20 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
@@ -115,7 +116,6 @@ class HookeFrame (wx.Frame):
         self._setup_perspectives()
         self._bind_events()
         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'))
@@ -199,6 +199,10 @@ class HookeFrame (wx.Frame):
 #            ('results', panel.results.Results(self), 'bottom'),
             ]:
             self._add_panel(p, style)
+        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
@@ -317,6 +321,8 @@ class HookeFrame (wx.Frame):
                 index = int(name[len(arg.name):])
                 args[arg.name][index] = value
             for arg in command.arguments:
+                if arg.name not in args:
+                    continue  # undisplayed argument, e.g. 'driver' types.
                 count = arg.count
                 if hasattr(arg, '_display_count'):  # support HACK in props_from_argument()
                     count = arg._display_count
@@ -331,8 +337,8 @@ class HookeFrame (wx.Frame):
                         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))
+        cm = CommandMessage(command.name, args)
+        self.gui._submit_command(cm, self.inqueue)
         results = []
         while True:
             msg = self.outqueue.get()
@@ -396,6 +402,34 @@ 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]
+        if 'playlist' in self._c:
+            for playlist in playlists:
+                if self._c['playlist'].is_playlist_loaded(playlist):
+                    self._c['playlist'].update_playlist(playlist)
+                else:
+                    self._c['playlist'].add_playlist(playlist)
+
+    def _postprocess_new_playlist(self, command, args={}, results=None):
+        """Update `self` to show the new playlist.
+        """
+        if not isinstance(results[-1], Success):
+            self._postprocess_text(command, results=results)
+            return
+        assert len(results) == 2, results
+        playlist = results[0]
+        if 'playlist' in self._c:
+            loaded = self._c['playlist'].is_playlist_loaded(playlist)
+            assert loaded == False, loaded
+            self._c['playlist'].add_playlist(playlist)
+
     def _postprocess_load_playlist(self, command, args={}, results=None):
         """Update `self` to show the playlist.
         """
@@ -404,7 +438,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):
@@ -412,7 +446,10 @@ class HookeFrame (wx.Frame):
             return
         assert len(results) == 2, results
         playlist = results[0]
-        self._c['playlist']._c['tree'].update_playlist(playlist)
+        if 'playlist' in self._c:
+            loaded = self._c['playlist'].is_playlist_loaded(playlist)
+            assert loaded == True, loaded
+            self._c['playlist'].update_playlist(playlist)
 
     def _postprocess_get_curve(self, command, args={}, results=[]):
         """Update `self` to show the curve.
@@ -430,9 +467,9 @@ class HookeFrame (wx.Frame):
         else:
             raise NotImplementedError()
         if 'note' in self._c:
-            self._c['note'].set_text(curve.info['note'])
+            self._c['note'].set_text(curve.info.get('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)
@@ -447,6 +484,25 @@ class HookeFrame (wx.Frame):
         """
         pass
 
+    def _postprocess_glob_curves_to_playlist(
+        self, command, args={}, results=[]):
+        """Update `self` to show new curves.
+        """
+        if not isinstance(results[-1], Success):
+            self._postprocess_text(command, results=results)
+            return
+        if 'playlist' in self._c:
+            if args.get('playlist', None) != None:
+                playlist = args['playlist']
+                pname = playlist.name
+                loaded = self._c['playlist'].is_playlist_name_loaded(pname)
+                assert loaded == True, loaded
+                for curve in results[:-1]:
+                    self._c['playlist']._add_curve(pname, curve)
+            else:
+                self.execute_command(
+                    command=self._command_by_name('get playlist'))
+
     def _postprocess_zero_block_surface_contact_point(
         self, command, args={}, results=[]):
         """Update the curve, since the available columns may have changed.