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
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation, either
8 # version 3 of the License, or (at your option) any later version.
10 # Hooke is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General 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 `note` module provides :class:`NotePlugin` the associated
20 :class:`hooke.command.Command`\s for annotating several Hooke classes
21 (:mod:`hooke.playlist.Playlist`, :mod:`hooke.curve.Curve`, ...).
24 from ..command import Command, Argument, Failure
25 from ..playlist import FilePlaylist
26 from ..plugin import Builtin
27 from ..plugin.playlist import current_playlist_callback
30 class NotePlugin (Builtin):
32 super(NotePlugin, self).__init__(name='note')
34 AddNoteCommand(self), ClearNoteCommand(self), GetNoteCommand(self)]
37 class AddNoteCommand (Command):
38 """Add a note to one of several Hooke objects.
40 def __init__(self, plugin):
41 super(AddNoteCommand, self).__init__(
45 name='target', type='object',
46 callback=current_playlist_callback,
48 Target object for the note. Defaults to the current playlist.
51 name='note', type='string', optional=False,
56 help=self.__doc__, plugin=plugin)
58 def _run(self, hooke, inqueue, outqueue, params):
59 params['target'].info['note'].append(params['note'])
61 class ClearNoteCommand (Command):
62 """Remove a note or notes from one of several Hooke objects.
64 def __init__(self, plugin):
65 super(ClearNoteCommand, self).__init__(
69 name='target', type='object',
70 callback=current_playlist_callback,
72 Target object for the note. Defaults to the current playlist.
74 Argument(name='count', type='int', default=-1,
76 Number of notes to remove. Defaults to all notes.
78 Argument(name='force', type='bool', default=False,
80 Run without prompting the user. Use if you save often or don't make
84 help=self.__doc__, plugin=plugin)
86 def _run(self, hooke, inqueue, outqueue, params):
87 num_notes = len(params['target'].info['note'])
88 if params['count'] == -1:
89 num_notes_removed = num_notes
91 num_notes_removed = min(num_notes, params['count'])
92 if params['force'] == False and num_notes_removed > 0:
93 msg = 'Remove %d notes?' % num_notes_removed
95 outqueue.put(BooleanRequest(msg, default))
96 result = inqueue.get()
97 assert result.type == 'boolean'
98 if result.value == False:
100 params['target'].info['note'] = \
101 params['target'].info['note'][:-num_notes_removed]
103 class GetNoteCommand (Command):
104 """Retrieve notes from one of several Hooke objects.
106 def __init__(self, plugin):
107 super(GetNoteCommand, self).__init__(
111 name='target', type='object',
112 callback=current_playlist_callback,
114 Target object for the note. Defaults to the current playlist.
117 help=self.__doc__, plugin=plugin)
119 def _run(self, hooke, inqueue, outqueue, params):
120 outqueue.put(params['target'].info['note'])