X-Git-Url: http://git.tremily.us/?p=hooke.git;a=blobdiff_plain;f=hooke%2Fplugin%2Fnote.py;h=b982075daa17cab895d8a63204b9d1d6a25417d9;hp=1da2dc086ad53ecdc882064357fbdb7803838149;hb=226c1eeae314e3148c4d25074794c86d947129fd;hpb=8b12d7d77256982cf9a228901e1e9ed511b43d36 diff --git a/hooke/plugin/note.py b/hooke/plugin/note.py index 1da2dc0..b982075 100644 --- a/hooke/plugin/note.py +++ b/hooke/plugin/note.py @@ -1,4 +1,20 @@ -# Copyright +# Copyright (C) 2010 W. Trevor King +# +# This file is part of Hooke. +# +# Hooke is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Hooke is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General +# Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with Hooke. If not, see +# . """The `note` module provides :class:`NotePlugin` the associated :class:`hooke.command.Command`\s for annotating several Hooke classes @@ -6,36 +22,31 @@ """ from ..command import Command, Argument, Failure -from ..playlist import FilePlaylist -from ..plugin import Builtin -from ..plugin.playlist import current_playlist_callback - +from . import Builtin +from .curve import current_curve_callback +from .playlist import FilterCommand class NotePlugin (Builtin): def __init__(self): super(NotePlugin, self).__init__(name='note') - - def commands(self): - return [AddNoteCommand(), ClearNoteCommand(), GetNoteCommand()] - - def dependencies(self): - return [ - 'playlist', # for current_playlist_callback + self._commands = [ + SetNoteCommand(self), GetNoteCommand(self), + NoteFilterCommand(self), ] -class AddNoteCommand (Command): - """Add a note to one of several Hooke objects. +class SetNoteCommand (Command): + """Set the note on one of several Hooke objects. """ - def __init__(self): - super(AddNoteCommand, self).__init__( - name='add note', + def __init__(self, plugin): + super(SetNoteCommand, self).__init__( + name='set note', arguments=[ Argument( name='target', type='object', - callback=current_playlist_callback, + callback=current_curve_callback, help=""" -Target object for the note. Defaults to the current playlist. +Target object for the note. Defaults to the current curve. """.strip()), Argument( name='note', type='string', optional=False, @@ -43,68 +54,38 @@ Target object for the note. Defaults to the current playlist. The note text. """.strip()), ], - help=self.__doc__) + help=self.__doc__, plugin=plugin) def _run(self, hooke, inqueue, outqueue, params): - params['target'].info['note'].append(params['note']) + params['target'].info['note'] = params['note'] -class ClearNoteCommand (Command): - """Remove a note or notes from one of several Hooke objects. - """ - def __init__(self): - super(ClearNoteCommand, self).__init__( - name='clear note', - arguments=[ - Argument( - name='target', type='object', - callback=current_playlist_callback, - help=""" -Target object for the note. Defaults to the current playlist. -""".strip()), - Argument(name='count', type='int', default=-1, - help=""" -Number of notes to remove. Defaults to all notes. -""".strip()), - Argument(name='force', type='bool', default=False, - help=""" -Run without prompting the user. Use if you save often or don't make -typing mistakes ;). -""".strip()), - ], - help=self.__doc__) - - def _run(self, hooke, inqueue, outqueue, params): - num_notes = len(params['target'].info['note']) - if params['count'] == -1: - num_notes_removed = num_notes - else: - num_notes_removed = min(num_notes, params['count']) - if params['force'] == False and num_notes_removed > 0: - msg = 'Remove %d notes?' % num_notes_removed - default = False - outqueue.put(BooleanRequest(msg, default)) - result = inqueue.get() - assert result.type == 'boolean' - if result.value == False: - return - params['target'].info['note'] = \ - params['target'].info['note'][:-num_notes_removed] class GetNoteCommand (Command): - """Retrieve notes from one of several Hooke objects. + """Retrieve the note from one of several Hooke objects. """ - def __init__(self): + def __init__(self, plugin): super(GetNoteCommand, self).__init__( name='get note', arguments=[ Argument( name='target', type='object', - callback=current_playlist_callback, + callback=current_curve_callback, help=""" -Target object for the note. Defaults to the current playlist. +Target object for the note. Defaults to the current curve. """.strip()), ], - help=self.__doc__) + help=self.__doc__, plugin=plugin) def _run(self, hooke, inqueue, outqueue, params): outqueue.put(params['target'].info['note']) + + +class NoteFilterCommand (FilterCommand): + """Create a subset playlist of curves with `.info['note'] != None`. + """ + def __init__(self, plugin): + super(NoteFilterCommand, self).__init__( + plugin, name='note filter playlist') + + def filter(self, curve, hooke, inqueue, outqueue, params): + return 'note' in curve.info and curve.info['note'] != None