1 """The `note` module provides :class:`NotePlugin` the associated
2 :class:`hooke.command.Command`\s for annotating several Hooke classes
3 (:mod:`hooke.playlist.Playlist`, :mod:`hooke.curve.Curve`, ...).
6 from ..command import Command, Argument, Failure
7 from ..playlist import FilePlaylist
8 from ..plugin import Builtin
9 from ..plugin.playlist import current_playlist_callback
12 class NotePlugin (Builtin):
14 super(NotePlugin, self).__init__(name='note')
17 return [AddNoteCommand(), ClearNoteCommand(), GetNoteCommand()]
19 def dependencies(self):
21 'playlist', # for current_playlist_callback
25 class AddNoteCommand (Command):
26 """Add a note to one of several Hooke objects.
29 super(AddNoteCommand, self).__init__(
33 name='target', type='object',
34 callback=current_playlist_callback,
36 Target object for the note. Defaults to the current playlist.
39 name='note', type='string', optional=False,
46 def _run(self, hooke, inqueue, outqueue, params):
47 params['target'].info['note'].append(params['note'])
49 class ClearNoteCommand (Command):
50 """Remove a note or notes from one of several Hooke objects.
53 super(ClearNoteCommand, self).__init__(
57 name='target', type='object',
58 callback=current_playlist_callback,
60 Target object for the note. Defaults to the current playlist.
62 Argument(name='count', type='int', default=-1,
64 Number of notes to remove. Defaults to all notes.
66 Argument(name='force', type='bool', default=False,
68 Run without prompting the user. Use if you save often or don't make
74 def _run(self, hooke, inqueue, outqueue, params):
75 num_notes = len(params['target'].info['note'])
76 if params['count'] == -1:
77 num_notes_removed = num_notes
79 num_notes_removed = min(num_notes, params['count'])
80 if params['force'] == False and num_notes_removed > 0:
81 msg = 'Remove %d notes?' % num_notes_removed
83 outqueue.put(BooleanRequest(msg, default))
84 result = inqueue.get()
85 assert result.type == 'boolean'
86 if result.value == False:
88 params['target'].info['note'] = \
89 params['target'].info['note'][:-num_notes_removed]
91 class GetNoteCommand (Command):
92 """Retrieve notes from one of several Hooke objects.
95 super(GetNoteCommand, self).__init__(
99 name='target', type='object',
100 callback=current_playlist_callback,
102 Target object for the note. Defaults to the current playlist.
107 def _run(self, hooke, inqueue, outqueue, params):
108 outqueue.put(params['target'].info['note'])