1 # Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 # 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
26 from .curve import current_curve_callback
27 from .playlist import FilterCommand
29 class NotePlugin (Builtin):
31 super(NotePlugin, self).__init__(name='note')
33 SetNoteCommand(self), GetNoteCommand(self),
34 NoteFilterCommand(self),
38 class SetNoteCommand (Command):
39 """Set the note on one of several Hooke objects.
41 def __init__(self, plugin):
42 super(SetNoteCommand, self).__init__(
46 name='target', type='object',
47 callback=current_curve_callback,
49 Target object for the note. Defaults to the current curve.
52 name='note', type='string', optional=False,
57 help=self.__doc__, plugin=plugin)
59 def _run(self, hooke, inqueue, outqueue, params):
60 params['target'].info['note'] = params['note']
63 class GetNoteCommand (Command):
64 """Retrieve the note from one of several Hooke objects.
66 def __init__(self, plugin):
67 super(GetNoteCommand, self).__init__(
71 name='target', type='object',
72 callback=current_curve_callback,
74 Target object for the note. Defaults to the current curve.
77 help=self.__doc__, plugin=plugin)
79 def _run(self, hooke, inqueue, outqueue, params):
80 outqueue.put(params['target'].info.get('note', None))
83 class NoteFilterCommand (FilterCommand):
84 """Create a subset playlist of curves with `.info['note'] != None`.
86 def __init__(self, plugin):
87 super(NoteFilterCommand, self).__init__(
88 plugin, name='note filter playlist', load_curves=False)
90 def filter(self, curve, hooke, inqueue, outqueue, params):
91 return 'note' in curve.info and curve.info['note'] != None