3 """The `note` module provides :class:`NotePlugin` the associated
4 :class:`hooke.command.Command`\s for annotating several Hooke classes
5 (:mod:`hooke.playlist.Playlist`, :mod:`hooke.curve.Curve`, ...).
8 from ..command import Command, Argument, Failure
9 from ..playlist import FilePlaylist
10 from ..plugin import Builtin
11 from ..plugin.playlist import current_playlist_callback
14 class NotePlugin (Builtin):
16 super(NotePlugin, self).__init__(name='note')
19 return [AddNoteCommand(), ClearNoteCommand(), GetNoteCommand()]
21 def dependencies(self):
23 'playlist', # for current_playlist_callback
27 class AddNoteCommand (Command):
28 """Add a note to one of several Hooke objects.
31 super(AddNoteCommand, self).__init__(
35 name='target', type='object',
36 callback=current_playlist_callback,
38 Target object for the note. Defaults to the current playlist.
41 name='note', type='string', optional=False,
48 def _run(self, hooke, inqueue, outqueue, params):
49 params['target'].info['note'].append(params['note'])
51 class ClearNoteCommand (Command):
52 """Remove a note or notes from one of several Hooke objects.
55 super(ClearNoteCommand, self).__init__(
59 name='target', type='object',
60 callback=current_playlist_callback,
62 Target object for the note. Defaults to the current playlist.
64 Argument(name='count', type='int', default=-1,
66 Number of notes to remove. Defaults to all notes.
68 Argument(name='force', type='bool', default=False,
70 Run without prompting the user. Use if you save often or don't make
76 def _run(self, hooke, inqueue, outqueue, params):
77 num_notes = len(params['target'].info['note'])
78 if params['count'] == -1:
79 num_notes_removed = num_notes
81 num_notes_removed = min(num_notes, params['count'])
82 if params['force'] == False and num_notes_removed > 0:
83 msg = 'Remove %d notes?' % num_notes_removed
85 outqueue.put(BooleanRequest(msg, default))
86 result = inqueue.get()
87 assert result.type == 'boolean'
88 if result.value == False:
90 params['target'].info['note'] = \
91 params['target'].info['note'][:-num_notes_removed]
93 class GetNoteCommand (Command):
94 """Retrieve notes from one of several Hooke objects.
97 super(GetNoteCommand, self).__init__(
101 name='target', type='object',
102 callback=current_playlist_callback,
104 Target object for the note. Defaults to the current playlist.
109 def _run(self, hooke, inqueue, outqueue, params):
110 outqueue.put(params['target'].info['note'])