From ce619a116294cc11241e41c9c8832f0e47aae929 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 30 Jul 2010 07:08:24 -0400 Subject: [PATCH] Filled in the playlist panel's _on_delete handling --- hooke/ui/gui/__init__.py | 24 ++++++++++++- hooke/ui/gui/panel/playlist.py | 61 ++++++++++++++++++++++++---------- 2 files changed, 67 insertions(+), 18 deletions(-) diff --git a/hooke/ui/gui/__init__.py b/hooke/ui/gui/__init__.py index 120d36a..d250dbd 100644 --- a/hooke/ui/gui/__init__.py +++ b/hooke/ui/gui/__init__.py @@ -117,7 +117,12 @@ class HookeFrame (wx.Frame): # filter=self.gui.config['folders-filters'], # defaultFilter=int(self.gui.config['folders-filter-index'])), 'left'), #HACK: config should convert ('playlists', panel.PANELS['playlist']( - callbacks={}, + callbacks={ + 'delete_playlist':self._on_user_delete_playlist, + '_delete_playlist':self._on_delete_playlist, + 'delete_curve':self._on_user_delete_curve, + '_delete_curve':self._on_delete_curve, + }, config=self.gui.config, parent=self, style=wx.WANTS_CHARS|wx.NO_BORDER, @@ -678,6 +683,23 @@ class HookeFrame (wx.Frame): + # Playlist panel interface + + def _on_user_delete_playlist(self, _class, method, playlist): + pass + + def _on_delete_playlist(self, _class, method, playlist): + if hasattr(playlist, 'path') and playlist.path != None: + os.remove(playlist.path) + + def _on_user_delete_curve(self, _class, method, playlist, curve): + pass + + def _on_delete_curve(self, _class, method, playlist, curve): + os.remove(curve.path) + + + # Navbar interface def _next_curve(self, *args): diff --git a/hooke/ui/gui/panel/playlist.py b/hooke/ui/gui/panel/playlist.py index b0c837d..53eb998 100644 --- a/hooke/ui/gui/panel/playlist.py +++ b/hooke/ui/gui/panel/playlist.py @@ -91,7 +91,7 @@ class Tree (wx.TreeCtrl): for c_id in self._name_for_id.keys(): if c_id == _id: return c_id - return _id + raise KeyError(_id) def _on_curve_select(self, event): """Act on playlist/curve selection. @@ -160,6 +160,7 @@ class Tree (wx.TreeCtrl): text=self._name(playlist.name), image=self.image['playlist']) self._id_for_name[playlist.name] = p_id + self._name_for_id[p_id] = playlist.name # temporarily disable any add_curve callbacks acc = self._callbacks.get('add_curve', None) @@ -184,35 +185,61 @@ class Tree (wx.TreeCtrl): text=self._name(curve.name), image=self.image['curve']) self._id_for_name[(p.name, curve.name)] = c_id + self._name_for_id[c_id] = (p.name, curve.name) in_callback(self, p, curve) def delete_playlist(self, name): """Delete a :class:`hooke.playlist.Playlist` by name. + + Called by the :meth:`_on_delete` handler. + + Removes the playlist and its curves from the tree, then calls + :meth:`_delete_playlist`. """ - _id = self._id_for_name.pop(name) + _id = self._id_for_name[name] self.Delete(_id) - playlist = self._playlists.pop(name) + playlist = self._playlists[name] + self._delete_playlist(playlist) + in_callback(self, playlist) + + def _delete_playlist(self, playlist): + """Adjust name/id caches for the playlist and its curves. + + Called on *every* playlist deletion. + """ + self._playlists.pop(playlist.name) + _id = self._id_for_name.pop(playlist.name) del(self._name_for_id[_id]) for curve in playlist: - _id = self._id_for_name.pop((name, curve.name)) - del(self._name_for_id[_id]) + self._delete_curve(playlist, curve) in_callback(self, playlist) def delete_curve(self, playlist_name, name): """Delete a :class:`hooke.curve.Curve` by name. + + Called by the :meth:`_on_delete` handler. + + Removes the curve from the tree, then calls + :meth:`_delete_curve`. """ - if playlist is not None: - if playlist.count == 1: - notebook = self.Parent.plotNotebook - index = self.Parent._GetPlaylistTab(playlist.name) - notebook.SetSelection(index) - notebook.DeletePage(notebook.GetSelection()) - self.Parent.DeleteFromPlaylists(playlist.name) - else: - file_name = self.GetItemText(item) - playlist.delete_file(file_name) - self.Delete(item) - self.Parent.UpdatePlaylistsTreeSelection() + _id = self._id_for_name[(playlist_name, name)] + self.Delete(_id) + playlist = self._playlists[playlist_name] + curve = None + for i,c in enumerate(playlist): + if c.name == name: + curve = c + break + self._delete_curve(playlist, curve) + in_callback(self, playlist, curve) + + def _delete_curve(self, playlist, curve): + """Adjust name/id caches. + + Called on _every_ curve deletion. + """ + _id = self._id_for_name.pop((playlist.name, curve.name)) + del(self._name_for_id[_id]) in_callback(self, playlist, curve) def get_selected_playlist(self): -- 2.26.2