Adjust fit-parameter handling for the polymer_fit plugin.
[hooke.git] / hooke / plugin / playlist.py
index 086fa971e5155c42647033cb54da500d0097a156..f9d7f31ffa68b75db4ee4af9ec7943ff90d9ad4d 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2010-2011 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.
     """
@@ -352,7 +372,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 +385,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]