Filled in the playlist panel's _on_delete handling
authorW. Trevor King <wking@drexel.edu>
Fri, 30 Jul 2010 11:08:24 +0000 (07:08 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 30 Jul 2010 11:08:24 +0000 (07:08 -0400)
hooke/ui/gui/__init__.py
hooke/ui/gui/panel/playlist.py

index 120d36af147b140d7bbaa5b6535b59897b1a30e0..d250dbd86b0b47888175095d65939d7aec1200e4 100644 (file)
@@ -117,7 +117,12 @@ class HookeFrame (wx.Frame):
 #                    filter=self.gui.config['folders-filters'],\r
 #                    defaultFilter=int(self.gui.config['folders-filter-index'])), 'left'),  #HACK: config should convert\r
             ('playlists', panel.PANELS['playlist'](\r
-                    callbacks={},\r
+                    callbacks={\r
+                        'delete_playlist':self._on_user_delete_playlist,\r
+                        '_delete_playlist':self._on_delete_playlist,\r
+                        'delete_curve':self._on_user_delete_curve,\r
+                        '_delete_curve':self._on_delete_curve,\r
+                        },\r
                     config=self.gui.config,\r
                     parent=self,\r
                     style=wx.WANTS_CHARS|wx.NO_BORDER,\r
@@ -678,6 +683,23 @@ class HookeFrame (wx.Frame):
 \r
 \r
 \r
+    # Playlist panel interface\r
+\r
+    def _on_user_delete_playlist(self, _class, method, playlist):\r
+        pass\r
+\r
+    def _on_delete_playlist(self, _class, method, playlist):\r
+        if hasattr(playlist, 'path') and playlist.path != None:\r
+            os.remove(playlist.path)\r
+\r
+    def _on_user_delete_curve(self, _class, method, playlist, curve):\r
+        pass\r
+\r
+    def _on_delete_curve(self, _class, method, playlist, curve):\r
+        os.remove(curve.path)\r
+\r
+\r
+\r
     # Navbar interface\r
 \r
     def _next_curve(self, *args):\r
index b0c837d43f5e64abfbfe4b3eda7352222cc7e0c2..53eb9980a44251451dd2ce99d3163319a85c46e4 100644 (file)
@@ -91,7 +91,7 @@ class Tree (wx.TreeCtrl):
         for c_id in self._name_for_id.keys():\r
             if c_id == _id:\r
                 return c_id\r
-        return _id\r
+        raise KeyError(_id)\r
 \r
     def _on_curve_select(self, event):\r
         """Act on playlist/curve selection.\r
@@ -160,6 +160,7 @@ class Tree (wx.TreeCtrl):
             text=self._name(playlist.name),\r
             image=self.image['playlist'])\r
         self._id_for_name[playlist.name] = p_id\r
+        self._name_for_id[p_id] = playlist.name\r
 \r
         # temporarily disable any add_curve callbacks\r
         acc = self._callbacks.get('add_curve', None)\r
@@ -184,35 +185,61 @@ class Tree (wx.TreeCtrl):
             text=self._name(curve.name),\r
             image=self.image['curve'])\r
         self._id_for_name[(p.name, curve.name)] = c_id\r
+        self._name_for_id[c_id] = (p.name, curve.name)\r
         in_callback(self, p, curve)\r
 \r
     def delete_playlist(self, name):\r
         """Delete a :class:`hooke.playlist.Playlist` by name.\r
+\r
+        Called by the :meth:`_on_delete` handler.\r
+\r
+        Removes the playlist and its curves from the tree, then calls\r
+        :meth:`_delete_playlist`.\r
         """\r
-        _id = self._id_for_name.pop(name)\r
+        _id = self._id_for_name[name]\r
         self.Delete(_id)\r
-        playlist = self._playlists.pop(name)\r
+        playlist = self._playlists[name]\r
+        self._delete_playlist(playlist)\r
+        in_callback(self, playlist)\r
+\r
+    def _delete_playlist(self, playlist):\r
+        """Adjust name/id caches for the playlist and its curves.\r
+\r
+        Called on *every* playlist deletion.\r
+        """\r
+        self._playlists.pop(playlist.name)\r
+        _id = self._id_for_name.pop(playlist.name)\r
         del(self._name_for_id[_id])\r
         for curve in playlist:\r
-            _id = self._id_for_name.pop((name, curve.name))\r
-            del(self._name_for_id[_id])\r
+            self._delete_curve(playlist, curve)\r
         in_callback(self, playlist)\r
 \r
     def delete_curve(self, playlist_name, name):\r
         """Delete a :class:`hooke.curve.Curve` by name.\r
+\r
+        Called by the :meth:`_on_delete` handler.\r
+\r
+        Removes the curve from the tree, then calls\r
+        :meth:`_delete_curve`.\r
         """\r
-        if playlist is not None:\r
-            if playlist.count == 1:\r
-                notebook = self.Parent.plotNotebook\r
-                index = self.Parent._GetPlaylistTab(playlist.name)\r
-                notebook.SetSelection(index)\r
-                notebook.DeletePage(notebook.GetSelection())\r
-                self.Parent.DeleteFromPlaylists(playlist.name)\r
-            else:\r
-                file_name = self.GetItemText(item)\r
-                playlist.delete_file(file_name)\r
-                self.Delete(item)\r
-                self.Parent.UpdatePlaylistsTreeSelection()\r
+        _id = self._id_for_name[(playlist_name, name)]\r
+        self.Delete(_id)\r
+        playlist = self._playlists[playlist_name]\r
+        curve = None\r
+        for i,c in enumerate(playlist):\r
+            if c.name == name:\r
+                curve = c\r
+                break\r
+        self._delete_curve(playlist, curve)\r
+        in_callback(self, playlist, curve)\r
+\r
+    def _delete_curve(self, playlist, curve):\r
+        """Adjust name/id caches.\r
+\r
+        Called on _every_ curve deletion.\r
+        """\r
+        _id = self._id_for_name.pop((playlist.name, curve.name))\r
+        del(self._name_for_id[_id])\r
         in_callback(self, playlist, curve)\r
 \r
     def get_selected_playlist(self):\r