Patch GUI to handle 'new playlist' and 'glob curves to playlist'
authorW. Trevor King <wking@drexel.edu>
Thu, 19 Aug 2010 17:47:56 +0000 (13:47 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 19 Aug 2010 17:47:56 +0000 (13:47 -0400)
hooke/ui/gui/__init__.py
hooke/ui/gui/panel/playlist.py
hooke/ui/gui/panel/propertyeditor.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.
index a863dca9e2f84ac5d42e4ed00a596ec78a3f32c1..e69f248fc2fb4dca943d218827d95c7b60690e77 100644 (file)
@@ -334,11 +334,36 @@ class Tree (wx.TreeCtrl):
         """Absorb changed `.index()`, etc.
         """
         self._playlists[playlist.name] = playlist
+        cnames = []
+        for curve in playlist:
+            if (playlist.name, curve.name) not in self._id_for_name:
+                self._add_curve(playlist.name, curve)
+            cnames.append(curve.name)
+        dc = self._callbacks['delete_curve']
+        _dc = self._callbacks['_delete_curve']
+        self._callbacks['delete_curve'] = None
+        self._callbacks['_delete_curve'] = None
+        for name in self._id_for_name.keys():
+            if not self._is_curve(name):
+                continue
+            pname,cname = name
+            if pname != playlist.name:
+                continue
+            if cname not in cnames:
+                self.delete_curve(playlist.name, cname)
+        self._callbacks['delete_curve'] = dc
+        self._callbacks['_delete_curve'] = _dc
 
     def is_playlist_loaded(self, playlist):
-        """Return `True` if a playlist is loaded, `False` otherwise.
+        """Return `True` if `playlist` is loaded, `False` otherwise.
+        """
+        return self.is_playlist_name_loaded(playlist.name)
+
+    def is_playlist_name_loaded(self, name):
+        """Return `True` if a playlist named `name` is loaded, `False`
+        otherwise.
         """
-        return playlist.name in self._playlists
+        return name in self._playlists
 
 
 class Playlist (Panel, wx.Panel):
index 95233fcf8bf1daca8e94a0ad8d3931d4a9c24f8a..b991c81618f040c9a51366f7814cc79c2d558371 100644 (file)
@@ -41,7 +41,7 @@ def props_from_argument(argument, curves=None, playlists=None):
     :class:`Property`\s.
     """
     type = argument.type
-    if type in ['driver']:  # intentionally not handled (yet)
+    if type in ['driver', 'dict']:  # intentionally not handled (yet)
         return None
     count = argument.count
     if count == -1: