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')
35 return [AddNoteCommand(), ClearNoteCommand(), GetNoteCommand()]
37 def dependencies(self):
39 'playlist', # for current_playlist_callback
43 class AddNoteCommand (Command):
44 """Add a note to one of several Hooke objects.
47 super(AddNoteCommand, self).__init__(
51 name='target', type='object',
52 callback=current_playlist_callback,
54 Target object for the note. Defaults to the current playlist.
57 name='note', type='string', optional=False,
64 def _run(self, hooke, inqueue, outqueue, params):
65 params['target'].info['note'].append(params['note'])
67 class ClearNoteCommand (Command):
68 """Remove a note or notes from one of several Hooke objects.
71 super(ClearNoteCommand, self).__init__(
75 name='target', type='object',
76 callback=current_playlist_callback,
78 Target object for the note. Defaults to the current playlist.
80 Argument(name='count', type='int', default=-1,
82 Number of notes to remove. Defaults to all notes.
84 Argument(name='force', type='bool', default=False,
86 Run without prompting the user. Use if you save often or don't make
92 def _run(self, hooke, inqueue, outqueue, params):
93 num_notes = len(params['target'].info['note'])
94 if params['count'] == -1:
95 num_notes_removed = num_notes
97 num_notes_removed = min(num_notes, params['count'])
98 if params['force'] == False and num_notes_removed > 0:
99 msg = 'Remove %d notes?' % num_notes_removed
101 outqueue.put(BooleanRequest(msg, default))
102 result = inqueue.get()
103 assert result.type == 'boolean'
104 if result.value == False:
106 params['target'].info['note'] = \
107 params['target'].info['note'][:-num_notes_removed]
109 class GetNoteCommand (Command):
110 """Retrieve notes from one of several Hooke objects.
113 super(GetNoteCommand, self).__init__(
117 name='target', type='object',
118 callback=current_playlist_callback,
120 Target object for the note. Defaults to the current playlist.
125 def _run(self, hooke, inqueue, outqueue, params):
126 outqueue.put(params['target'].info['note'])