1 # Copyright (C) 2010-2012 W. Trevor King <wking@tremily.us>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option) any
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with Hooke. If not, see <http://www.gnu.org/licenses/>.
18 """The `note` module provides :class:`NotePlugin` the associated
19 :class:`hooke.command.Command`\s for annotating several Hooke classes
20 (:mod:`hooke.playlist.Playlist`, :mod:`hooke.curve.Curve`, ...).
23 from ..command import Command, Argument, Failure
25 from .curve import current_curve_callback
26 from .playlist import FilterCommand
28 class NotePlugin (Builtin):
30 super(NotePlugin, self).__init__(name='note')
32 SetNoteCommand(self), GetNoteCommand(self),
33 NoteFilterCommand(self),
37 class SetNoteCommand (Command):
38 """Set the note on one of several Hooke objects.
40 def __init__(self, plugin):
41 super(SetNoteCommand, self).__init__(
45 name='target', type='object',
46 callback=current_curve_callback,
48 Target object for the note. Defaults to the current curve.
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'] = params['note']
62 class GetNoteCommand (Command):
63 """Retrieve the note from one of several Hooke objects.
65 def __init__(self, plugin):
66 super(GetNoteCommand, self).__init__(
70 name='target', type='object',
71 callback=current_curve_callback,
73 Target object for the note. Defaults to the current curve.
76 help=self.__doc__, plugin=plugin)
78 def _run(self, hooke, inqueue, outqueue, params):
79 outqueue.put(params['target'].info.get('note', None))
82 class NoteFilterCommand (FilterCommand):
83 """Create a subset playlist of curves with `.info['note'] != None`.
85 def __init__(self, plugin):
86 super(NoteFilterCommand, self).__init__(
87 plugin, name='note filter playlist', load_curves=False)
89 def filter(self, curve, hooke, inqueue, outqueue, params):
90 return 'note' in curve.info and curve.info['note'] != None