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.
26 from ..command import Command, Argument, Failure
27 from ..playlist import FilePlaylist
29 from .playlist import PlaylistNameArgument, PlaylistAddingCommand
32 class PlaylistsPlugin (Builtin):
34 super(PlaylistsPlugin, self).__init__(name='playlists')
36 NextCommand(self), PreviousCommand(self), JumpCommand(self),
37 IndexCommand(self), PlaylistListCommand(self), NewCommand(self)]
42 class NextCommand (Command):
43 """Move `hooke.playlists` to the next playlist.
45 def __init__(self, plugin):
46 super(NextCommand, self).__init__(
48 help=self.__doc__, plugin=plugin)
50 def _run(self, hooke, inqueue, outqueue, params):
51 hooke.playlists.next()
53 class PreviousCommand (Command):
54 """Move `hooke.playlists` to the previous playlist.
56 def __init__(self, plugin):
57 super(PreviousCommand, self).__init__(
58 name='previous playlist',
59 help=self.__doc__, plugin=plugin)
61 def _run(self, hooke, inqueue, outqueue, params):
62 hooke.playlists.previous()
64 class JumpCommand (Command):
65 """Move `hooke.playlists` to a given playlist.
67 def __init__(self, plugin):
68 super(JumpCommand, self).__init__(
69 name='jump to playlist',
71 Argument(name='index', type='int', optional=False, help="""
72 Index of target curve.
75 help=self.__doc__, plugin=plugin)
77 def _run(self, hooke, inqueue, outqueue, params):
78 hooke.playlists.jump(params['index'])
80 class IndexCommand (Command):
81 """Print the index of the current playlist.
83 The first playlist has index 0.
85 def __init__(self, plugin):
86 super(IndexCommand, self).__init__(
87 name='playlist index',
88 help=self.__doc__, plugin=plugin)
90 def _run(self, hooke, inqueue, outqueue, params):
91 outqueue.put(hooke.playlists.index())
93 class PlaylistListCommand (Command):
94 """Get the playlists in `hooke.playlists`.
96 def __init__(self, plugin):
97 super(PlaylistListCommand, self).__init__(
99 help=self.__doc__, plugin=plugin)
101 def _run(self, hooke, inqueue, outqueue, params):
102 outqueue.put(list(hooke.playlists))
105 class NewCommand (PlaylistAddingCommand):
106 """Create a new playlist.
108 def __init__(self, plugin):
109 super(NewCommand, self).__init__(
112 Argument(name='file', type='file', optional=True,
114 Default filename for future saves.
117 help=self.__doc__, plugin=plugin)
119 def _run(self, hooke, inqueue, outqueue, params):
121 drivers=hooke.drivers,
122 path=os.path.expanduser(params['file']),
124 self._set_playlist(hooke, params, p)