Patch GUI to handle 'new playlist' and 'glob curves to playlist'
[hooke.git] / hooke / ui / gui / __init__.py
index 271b00a05877a8ab0854fdb9158b3ec0d37ca722..034003b7d5278539d417b1dcddf19c06f7a3de20 100644 (file)
@@ -417,6 +417,19 @@ class HookeFrame (wx.Frame):
                 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.
         """
@@ -433,7 +446,10 @@ class HookeFrame (wx.Frame):
             return
         assert len(results) == 2, results
         playlist = results[0]
-        self._c['playlist'].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.
@@ -451,7 +467,7 @@ 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'].set_selected_curve(
                 playlist, curve)
@@ -468,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.