Added 'get playlist' and hooke.plugin.playlists
authorW. Trevor King <wking@drexel.edu>
Fri, 30 Jul 2010 19:57:11 +0000 (15:57 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 30 Jul 2010 19:57:11 +0000 (15:57 -0400)
hooke/plugin/__init__.py
hooke/plugin/playlist.py
hooke/plugin/playlists.py [new file with mode: 0644]

index 4ce90209e03f936c728ea047db83e4b96e15c472..80c2b52816411b12275b635ab6778a46d99b066a 100644 (file)
@@ -61,6 +61,7 @@ BUILTIN_MODULES = [
     'license',
     'note',
     'playlist',
+    'playlists',
     'system',
     ]
 """List of builtin modules.  TODO: autodiscovery
index 62137d0159e40213e78af5a4a97c6b645ace4d65..b9d5240da7fe69d214fc4b5549aaa5a0b176ca1b 100644 (file)
@@ -34,7 +34,7 @@ class PlaylistPlugin (Builtin):
         super(PlaylistPlugin, self).__init__(name='playlist')
         self._commands = [
             NextCommand(self), PreviousCommand(self), JumpCommand(self),
-            IndexCommand(self), CurveListCommand(self),
+            GetCommand(self), IndexCommand(self), CurveListCommand(self),
             SaveCommand(self), LoadCommand(self),
             AddCommand(self), AddGlobCommand(self),
             RemoveCommand(self), FilterCommand(self), NoteFilterCommand(self)]
@@ -135,19 +135,29 @@ class IndexCommand (Command):
     def _run(self, hooke, inqueue, outqueue, params):
        outqueue.put(params['playlist']._index)
 
+class GetCommand (Command):
+    """Return a :class:`hooke.playlist.Playlist`.
+    """
+    def __init__(self, plugin):
+        super(GetCommand, self).__init__(
+            name='get playlist',
+            arguments=[PlaylistArgument],
+            help=self.__doc__, plugin=plugin)
+
+    def _run(self, hooke, inqueue, outqueue, params):
+        outqueue.put(params['playlist'])
+
 class CurveListCommand (Command):
     """Get the curves in a playlist.
     """
     def __init__(self, plugin):
         super(CurveListCommand, self).__init__(
             name='playlist curves',
-            arguments=[
-                PlaylistArgument,
-                ],
+            arguments=[PlaylistArgument],
             help=self.__doc__, plugin=plugin)
 
     def _run(self, hooke, inqueue, outqueue, params):
-       outqueue.put([c for c in params['playlist']])
+       outqueue.put(list(params['playlist']))
 
 class SaveCommand (Command):
     """Save a playlist.
diff --git a/hooke/plugin/playlists.py b/hooke/plugin/playlists.py
new file mode 100644 (file)
index 0000000..485904f
--- /dev/null
@@ -0,0 +1,98 @@
+# Copyright (C) 2010 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 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/>.
+
+"""The ``playlists`` module provides :class:`PlaylistsPlugin` and
+several associated :class:`hooke.command.Command`\s for handling
+lists of :class:`hooke.playlist.Playlist` classes.
+"""
+
+from ..command import Command, Argument, Failure
+from ..plugin import Builtin
+
+
+class PlaylistsPlugin (Builtin):
+    def __init__(self):
+        super(PlaylistsPlugin, self).__init__(name='playlists')
+        self._commands = [
+            NextCommand(self), PreviousCommand(self), JumpCommand(self),
+            IndexCommand(self), PlaylistListCommand(self)]
+
+
+# Define commands
+
+class NextCommand (Command):
+    """Move `hooke.playlists` to the next playlist.
+    """
+    def __init__(self, plugin):
+        super(NextCommand, self).__init__(
+            name='next playlist',
+            help=self.__doc__, plugin=plugin)
+
+    def _run(self, hooke, inqueue, outqueue, params):
+       hooke.playlists.next()
+
+class PreviousCommand (Command):
+    """Move `hooke.playlists` to the previous playlist.
+    """
+    def __init__(self, plugin):
+        super(PreviousCommand, self).__init__(
+            name='previous playlist',
+            help=self.__doc__, plugin=plugin)
+
+    def _run(self, hooke, inqueue, outqueue, params):
+       hooke.playlists.previous()
+
+class JumpCommand (Command):
+    """Move `hooke.playlists` to a given playlist.
+    """
+    def __init__(self, plugin):
+        super(JumpCommand, self).__init__(
+            name='jump to playlist',
+            arguments=[
+                Argument(name='index', type='int', optional=False, help="""
+Index of target curve.
+""".strip()),
+                ],
+            help=self.__doc__, plugin=plugin)
+
+    def _run(self, hooke, inqueue, outqueue, params):
+       hooke.playlists.jump(int(params['index'])) # HACK, int() should be handled by ui
+
+class IndexCommand (Command):
+    """Print the index of the current playlist.
+
+    The first playlist has index 0.
+    """
+    def __init__(self, plugin):
+        super(IndexCommand, self).__init__(
+            name='playlist index',
+            help=self.__doc__, plugin=plugin)
+
+    def _run(self, hooke, inqueue, outqueue, params):
+       outqueue.put(hooke.playlists._index)
+
+class PlaylistListCommand (Command):
+    """Get the playlists in `hooke.playlists`.
+    """
+    def __init__(self, plugin):
+        super(PlaylistListCommand, self).__init__(
+            name='playlists',
+            help=self.__doc__, plugin=plugin)
+
+    def _run(self, hooke, inqueue, outqueue, params):
+       outqueue.put(list(hooke.playlists))