Use .index() instead of ._index for NoteIndexList access
[hooke.git] / hooke / plugin / playlists.py
1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
2 #
3 # This file is part of Hooke.
4 #
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.
9 #
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.
14 #
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/>.
18
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.
22 """
23
24 from ..command import Command, Argument, Failure
25 from ..plugin import Builtin
26
27
28 class PlaylistsPlugin (Builtin):
29     def __init__(self):
30         super(PlaylistsPlugin, self).__init__(name='playlists')
31         self._commands = [
32             NextCommand(self), PreviousCommand(self), JumpCommand(self),
33             IndexCommand(self), PlaylistListCommand(self)]
34
35
36 # Define commands
37
38 class NextCommand (Command):
39     """Move `hooke.playlists` to the next playlist.
40     """
41     def __init__(self, plugin):
42         super(NextCommand, self).__init__(
43             name='next playlist',
44             help=self.__doc__, plugin=plugin)
45
46     def _run(self, hooke, inqueue, outqueue, params):
47         hooke.playlists.next()
48
49 class PreviousCommand (Command):
50     """Move `hooke.playlists` to the previous playlist.
51     """
52     def __init__(self, plugin):
53         super(PreviousCommand, self).__init__(
54             name='previous playlist',
55             help=self.__doc__, plugin=plugin)
56
57     def _run(self, hooke, inqueue, outqueue, params):
58         hooke.playlists.previous()
59
60 class JumpCommand (Command):
61     """Move `hooke.playlists` to a given playlist.
62     """
63     def __init__(self, plugin):
64         super(JumpCommand, self).__init__(
65             name='jump to playlist',
66             arguments=[
67                 Argument(name='index', type='int', optional=False, help="""
68 Index of target curve.
69 """.strip()),
70                 ],
71             help=self.__doc__, plugin=plugin)
72
73     def _run(self, hooke, inqueue, outqueue, params):
74         hooke.playlists.jump(int(params['index'])) # HACK, int() should be handled by ui
75
76 class IndexCommand (Command):
77     """Print the index of the current playlist.
78
79     The first playlist has index 0.
80     """
81     def __init__(self, plugin):
82         super(IndexCommand, self).__init__(
83             name='playlist index',
84             help=self.__doc__, plugin=plugin)
85
86     def _run(self, hooke, inqueue, outqueue, params):
87         outqueue.put(hooke.playlists.index())
88
89 class PlaylistListCommand (Command):
90     """Get the playlists in `hooke.playlists`.
91     """
92     def __init__(self, plugin):
93         super(PlaylistListCommand, self).__init__(
94             name='playlists',
95             help=self.__doc__, plugin=plugin)
96
97     def _run(self, hooke, inqueue, outqueue, params):
98         outqueue.put(list(hooke.playlists))