fa699be7306f9b4de974a55d28c8a54cbb345242
[hooke.git] / hooke / plugin / note.py
1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
2 #
3 # This file is part of Hooke.
4 #
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.
9 #
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.
14 #
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/>.
18
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`, ...).
22 """
23
24 from ..command import Command, Argument, Failure
25 from . import Builtin
26 from .curve import current_curve_callback
27
28
29 class NotePlugin (Builtin):
30     def __init__(self):
31         super(NotePlugin, self).__init__(name='note')
32         self._commands = [
33             SetNoteCommand(self), GetNoteCommand(self)]
34
35
36 class SetNoteCommand (Command):
37     """Set the note on one of several Hooke objects.
38     """
39     def __init__(self, plugin):
40         super(SetNoteCommand, self).__init__(
41             name='set note',
42             arguments=[
43                 Argument(
44                     name='target', type='object',
45                     callback=current_curve_callback,
46                     help="""
47 Target object for the note.  Defaults to the current curve.
48 """.strip()),
49                 Argument(
50                     name='note', type='string', optional=False,
51                     help="""
52 The note text.
53 """.strip()),
54                 ],
55             help=self.__doc__, plugin=plugin)
56
57     def _run(self, hooke, inqueue, outqueue, params):
58         params['target'].info['note'] = params['note']
59
60
61 class GetNoteCommand (Command):
62     """Retrieve the note from one of several Hooke objects.
63     """
64     def __init__(self, plugin):
65         super(GetNoteCommand, self).__init__(
66             name='get note',
67             arguments=[
68                 Argument(
69                     name='target', type='object',
70                     callback=current_curve_callback,
71                     help="""
72 Target object for the note.  Defaults to the current curve.
73 """.strip()),
74                 ],
75             help=self.__doc__, plugin=plugin)
76
77     def _run(self, hooke, inqueue, outqueue, params):
78         outqueue.put(params['target'].info['note'])