Initial work on hooke.command_stack and hooke.playlist integration.
[hooke.git] / hooke / playlist.py
index dcd85b8797cabb0cc2696a548d700cb092a13445..906cb061a7c089220cfb49e07b679dd880c12b8a 100644 (file)
@@ -107,6 +107,7 @@ class NoteIndexList (list):
             c._index = 0
         return c
 
+
 class Playlist (NoteIndexList):
     """A :class:`NoteIndexList` of :class:`hooke.curve.Curve`\s.
 
@@ -117,6 +118,8 @@ class Playlist (NoteIndexList):
         self.drivers = drivers
         self._loaded = [] # List of loaded curves, see :meth:`._setup_item`.
         self._max_loaded = 100 # curves to hold in memory simultaneously.
+        self._curve_load_args = ()
+        self._curve_load_kwargs = {}
 
     def append_curve_by_path(self, path, info=None, identify=True):
         path = os.path.normpath(path)
@@ -126,6 +129,10 @@ class Playlist (NoteIndexList):
         self.append(c)
         return c
 
+    def set_curve_load_args(self, *args, **kwargs):
+        self._curve_load_args = args
+        self._curve_load_kwargs = kwargs
+
     def _setup_item(self, curve):
         if curve != None and curve not in self._loaded:
             if curve not in self:
@@ -133,12 +140,13 @@ class Playlist (NoteIndexList):
             if curve.driver == None:
                 c.identify(self.drivers)
             if curve.data == None:
-                curve.load()
+                curve.load(*self._curve_load_args, **self._curve_load_kwargs)
             self._loaded.append(curve)
             if len(self._loaded) > self._max_loaded:
                 oldest = self._loaded.pop(0)
                 oldest.unload()
 
+
 class FilePlaylist (Playlist):
     version = '0.1'
 
@@ -348,6 +356,6 @@ class FilePlaylist (Playlist):
         """Saves the playlist in a XML file.
         """
         self.set_path(path)
-        f = file(self.path, 'w')
-        f.write(self.flatten())
-        f.close()
+        with open(self.path, 'w') as f:
+            f.write(self.flatten())
+            self._digest = self.digest()