Run update-copyright.py.
[hooke.git] / hooke / ui / gui / panel / playlist.py
index fd46d2dc526ad56043e9155a5d01de35de73be5c..e8c8f844e7c51f4d104efb1e62ff083e20e11a94 100644 (file)
@@ -1,21 +1,19 @@
-# Copyright (C) 2010 Massimo Sandal <devicerandom@gmail.com>
-#                    W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
 #
 # This file is part of Hooke.
 #
-# Hooke is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
+# Hooke is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
 #
-# Hooke is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
-# Public License for more details.
+# Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
 #
-# You should have received a copy of the GNU Lesser General Public
-# License along with Hooke.  If not, see
-# <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public License
+# along with Hooke.  If not, see <http://www.gnu.org/licenses/>.
 
 """Playlist panel for Hooke.
 
@@ -244,7 +242,9 @@ class Tree (wx.TreeCtrl):
             if c.name == name:
                 curve = c
                 break
-        self._delete_curve(playlist, curve)
+        if curve is None:
+            raise ValueError(name)
+        self._delete_curve(playlist=playlist, curve=curve)
         in_callback(self, playlist, curve)
 
     def _delete_curve(self, playlist, curve):
@@ -254,7 +254,7 @@ class Tree (wx.TreeCtrl):
         """
         _id = self._id_for_name.pop((playlist.name, curve.name))
         del(self._name_for_id[_id])
-        in_callback(self, playlistcurve)
+        in_callback(self, playlist=playlist, curve=curve)
 
     # Get selection
 
@@ -334,6 +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 `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 name in self._playlists
 
 
 class Playlist (Panel, wx.Panel):