1 # Copyright (C) 2010-2012 W. Trevor King <wking@tremily.us>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option) any
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with Hooke. If not, see <http://www.gnu.org/licenses/>.
18 """The ``playlists`` module provides :class:`PlaylistsPlugin` and
19 several associated :class:`hooke.command.Command`\s for handling
20 lists of :class:`hooke.playlist.Playlist` classes.
23 from ..command import Command, Argument, Failure
24 from ..playlist import FilePlaylist
26 from .playlist import PlaylistNameArgument, PlaylistAddingCommand
29 class PlaylistsPlugin (Builtin):
31 super(PlaylistsPlugin, self).__init__(name='playlists')
33 NextCommand(self), PreviousCommand(self), JumpCommand(self),
34 IndexCommand(self), PlaylistListCommand(self), NewCommand(self)]
39 class NextCommand (Command):
40 """Move `hooke.playlists` to the next playlist.
42 def __init__(self, plugin):
43 super(NextCommand, self).__init__(
45 help=self.__doc__, plugin=plugin)
47 def _run(self, hooke, inqueue, outqueue, params):
48 hooke.playlists.next()
50 class PreviousCommand (Command):
51 """Move `hooke.playlists` to the previous playlist.
53 def __init__(self, plugin):
54 super(PreviousCommand, self).__init__(
55 name='previous playlist',
56 help=self.__doc__, plugin=plugin)
58 def _run(self, hooke, inqueue, outqueue, params):
59 hooke.playlists.previous()
61 class JumpCommand (Command):
62 """Move `hooke.playlists` to a given playlist.
64 def __init__(self, plugin):
65 super(JumpCommand, self).__init__(
66 name='jump to playlist',
68 Argument(name='index', type='int', optional=False, help="""
69 Index of target curve.
72 help=self.__doc__, plugin=plugin)
74 def _run(self, hooke, inqueue, outqueue, params):
75 hooke.playlists.jump(params['index'])
77 class IndexCommand (Command):
78 """Print the index of the current playlist.
80 The first playlist has index 0.
82 def __init__(self, plugin):
83 super(IndexCommand, self).__init__(
84 name='playlist index',
85 help=self.__doc__, plugin=plugin)
87 def _run(self, hooke, inqueue, outqueue, params):
88 outqueue.put(hooke.playlists.index())
90 class PlaylistListCommand (Command):
91 """Get the playlists in `hooke.playlists`.
93 def __init__(self, plugin):
94 super(PlaylistListCommand, self).__init__(
96 help=self.__doc__, plugin=plugin)
98 def _run(self, hooke, inqueue, outqueue, params):
99 outqueue.put(list(hooke.playlists))
102 class NewCommand (PlaylistAddingCommand):
103 """Create a new playlist.
105 def __init__(self, plugin):
106 super(NewCommand, self).__init__(
109 Argument(name='file', type='file', optional=True,
111 Default filename for future saves.
114 help=self.__doc__, plugin=plugin)
116 def _run(self, hooke, inqueue, outqueue, params):
118 drivers=hooke.drivers,
121 self._set_playlist(hooke, params, p)