1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 # Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke. If not, see
17 # <http://www.gnu.org/licenses/>.
19 """The ``playlists`` module provides :class:`PlaylistsPlugin` and
20 several associated :class:`hooke.command.Command`\s for handling
21 lists of :class:`hooke.playlist.Playlist` classes.
24 from ..command import Command, Argument, Failure
25 from ..playlist import FilePlaylist
27 from .playlist import PlaylistNameArgument, PlaylistAddingCommand
30 class PlaylistsPlugin (Builtin):
32 super(PlaylistsPlugin, self).__init__(name='playlists')
34 NextCommand(self), PreviousCommand(self), JumpCommand(self),
35 IndexCommand(self), PlaylistListCommand(self), NewCommand(self)]
40 class NextCommand (Command):
41 """Move `hooke.playlists` to the next playlist.
43 def __init__(self, plugin):
44 super(NextCommand, self).__init__(
46 help=self.__doc__, plugin=plugin)
48 def _run(self, hooke, inqueue, outqueue, params):
49 hooke.playlists.next()
51 class PreviousCommand (Command):
52 """Move `hooke.playlists` to the previous playlist.
54 def __init__(self, plugin):
55 super(PreviousCommand, self).__init__(
56 name='previous playlist',
57 help=self.__doc__, plugin=plugin)
59 def _run(self, hooke, inqueue, outqueue, params):
60 hooke.playlists.previous()
62 class JumpCommand (Command):
63 """Move `hooke.playlists` to a given playlist.
65 def __init__(self, plugin):
66 super(JumpCommand, self).__init__(
67 name='jump to playlist',
69 Argument(name='index', type='int', optional=False, help="""
70 Index of target curve.
73 help=self.__doc__, plugin=plugin)
75 def _run(self, hooke, inqueue, outqueue, params):
76 hooke.playlists.jump(params['index'])
78 class IndexCommand (Command):
79 """Print the index of the current playlist.
81 The first playlist has index 0.
83 def __init__(self, plugin):
84 super(IndexCommand, self).__init__(
85 name='playlist index',
86 help=self.__doc__, plugin=plugin)
88 def _run(self, hooke, inqueue, outqueue, params):
89 outqueue.put(hooke.playlists.index())
91 class PlaylistListCommand (Command):
92 """Get the playlists in `hooke.playlists`.
94 def __init__(self, plugin):
95 super(PlaylistListCommand, self).__init__(
97 help=self.__doc__, plugin=plugin)
99 def _run(self, hooke, inqueue, outqueue, params):
100 outqueue.put(list(hooke.playlists))
103 class NewCommand (PlaylistAddingCommand):
104 """Create a new playlist.
106 def __init__(self, plugin):
107 super(NewCommand, self).__init__(
110 Argument(name='file', type='file', optional=True,
112 Default filename for future saves.
115 help=self.__doc__, plugin=plugin)
117 def _run(self, hooke, inqueue, outqueue, params):
119 drivers=hooke.drivers,
122 self._set_playlist(hooke, params, p)