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(), ClearNoteCommand(), GetNoteCommand()]
35 self._setup_commands()
38 class AddNoteCommand (Command):
39 """Add a note to one of several Hooke objects.
42 super(AddNoteCommand, self).__init__(
46 name='target', type='object',
47 callback=current_playlist_callback,
49 Target object for the note. Defaults to the current playlist.
52 name='note', type='string', optional=False,
59 def _run(self, hooke, inqueue, outqueue, params):
60 params['target'].info['note'].append(params['note'])
62 class ClearNoteCommand (Command):
63 """Remove a note or notes from one of several Hooke objects.
66 super(ClearNoteCommand, self).__init__(
70 name='target', type='object',
71 callback=current_playlist_callback,
73 Target object for the note. Defaults to the current playlist.
75 Argument(name='count', type='int', default=-1,
77 Number of notes to remove. Defaults to all notes.
79 Argument(name='force', type='bool', default=False,
81 Run without prompting the user. Use if you save often or don't make
87 def _run(self, hooke, inqueue, outqueue, params):
88 num_notes = len(params['target'].info['note'])
89 if params['count'] == -1:
90 num_notes_removed = num_notes
92 num_notes_removed = min(num_notes, params['count'])
93 if params['force'] == False and num_notes_removed > 0:
94 msg = 'Remove %d notes?' % num_notes_removed
96 outqueue.put(BooleanRequest(msg, default))
97 result = inqueue.get()
98 assert result.type == 'boolean'
99 if result.value == False:
101 params['target'].info['note'] = \
102 params['target'].info['note'][:-num_notes_removed]
104 class GetNoteCommand (Command):
105 """Retrieve notes from one of several Hooke objects.
108 super(GetNoteCommand, self).__init__(
112 name='target', type='object',
113 callback=current_playlist_callback,
115 Target object for the note. Defaults to the current playlist.
120 def _run(self, hooke, inqueue, outqueue, params):
121 outqueue.put(params['target'].info['note'])