Ran update_copyright.py.
[hooke.git] / hooke / plugin / playlist.py
index 36993017a4344113c9a61c6261c190eef021ffe7..4f9ae5226275056db86784bccd87031e2b9b4780 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
 #
 # This file is part of Hooke.
 #
@@ -38,7 +38,7 @@ class PlaylistPlugin (Builtin):
         self._commands = [
             NextCommand(self), PreviousCommand(self), JumpCommand(self),
             GetCommand(self), IndexCommand(self), CurveListCommand(self),
-            SaveCommand(self), LoadCommand(self),
+            NameCommand(self), SaveCommand(self), LoadCommand(self),
             AddCommand(self), AddGlobCommand(self),
             RemoveCommand(self), ApplyCommand(self),
             FilterCommand(self),
@@ -210,6 +210,26 @@ class CurveListCommand (PlaylistCommand):
        outqueue.put(list(self._playlist(hooke, params)))
 
 
+class NameCommand (PlaylistCommand):
+    """(Re)name a playlist.
+    """
+    def __init__(self, plugin):
+        super(NameCommand, self).__init__(
+            name='name playlist',
+            arguments=[
+                Argument(name='name', type='string', optional=False,
+                         help="""
+Name for the playlist.
+""".strip()),
+                ],
+            help=self.__doc__, plugin=plugin)
+
+    def _run(self, hooke, inqueue, outqueue, params):
+       p = self._playlist(hooke, params)
+        p.name = params['name']
+        outqueue.put(p)
+
+
 class SaveCommand (PlaylistCommand):
     """Save a playlist.
     """
@@ -250,7 +270,7 @@ Drivers for loading curves.
             help=self.__doc__, plugin=plugin)
 
     def _run(self, hooke, inqueue, outqueue, params):
-        p = load(path=params['input'], drivers=params['drivers'])
+        p = load(path=params['input'], drivers=params['drivers'], hooke=hooke)
         self._set_playlist(hooke, params, p)
        outqueue.put(p)
 
@@ -302,7 +322,7 @@ Additional information for the input :class:`hooke.curve.Curve`.
 
     def _run(self, hooke, inqueue, outqueue, params):
         p = self._playlist(hooke, params)
-        for path in sorted(glob.glob(params['input'])):
+        for path in sorted(glob.glob(os.path.expanduser(params['input']))):
             try:
                 p.append_curve_by_path(path, params['info'], hooke=hooke)
             except NotRecognized, e:
@@ -325,8 +345,9 @@ Index of target curve.
             help=self.__doc__, plugin=plugin)
 
     def _run(self, hooke, inqueue, outqueue, params):
-        self._playlist(hooke, params).pop(params['index'])
-        self._playlist(hooke, params).jump(params.index())
+        playlist = self._playlist(hooke, params)
+        playlist.pop(params['index'])
+        playlist.jump(playlist.index())
 
 
 class ApplyCommand (PlaylistCommand):
@@ -352,7 +373,7 @@ Evaluate the applied command stack immediately.
             help=self.__doc__, plugin=plugin)
 
     def _run(self, hooke, inqueue, outqueue, params):
-        params = self.__setup_params(hooke=hooke, params=params)
+        params = self._setup_params(hooke=hooke, params=params)
         p = self._playlist(hooke, params)
         if params['evaluate'] == True:
             exec_cmd = hooke.command_by_name['execute command stack']
@@ -365,9 +386,9 @@ Evaluate the applied command stack immediately.
                 for command in params['commands']:
                     curve.command_stack.append(command)
                 curve.set_hooke(hooke)
-                curve.unload()
+                p.unload(curve)
 
-    def __setup_params(self, hooke, params):
+    def _setup_params(self, hooke, params):
         if params['commands'] == None:
             cstack_plugin = [p for p in hooke.plugins
                              if p.name == 'command_stack'][0]