From 14dc5541bca5edec1127ada8cf7a10ab110f2e82 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 12 May 2010 14:00:57 -0400 Subject: [PATCH] Run hooke.command.Argument.callback every time (if defined). The previous implemtation which only ran the callback if a value was given was too confusing. Also: * Added hooke.plugin.playlist.NoteFilterCommand. In general, I think running commands this way is pretty awkward. We should probably just use a Python interpreter instead of cmd.Cmd, but for now, NoteFilterCommand provides something like the old 'copylog' functionality. * Removed a bunch of superseded code from hooke.hooke_cli. --- hooke/command.py | 8 ++-- hooke/hooke_cli.py | 80 ---------------------------------------- hooke/plugin/playlist.py | 16 +++++++- hooke/ui/commandline.py | 2 +- 4 files changed, 20 insertions(+), 86 deletions(-) diff --git a/hooke/command.py b/hooke/command.py index 82ab53f..1cdb56f 100644 --- a/hooke/command.py +++ b/hooke/command.py @@ -88,7 +88,7 @@ class Command (object): self.aliases = aliases self.arguments = [ Argument(name='help', type='bool', default=False, count=1, - callback=StoreValue(True), help='Print a help message.'), + help='Print a help message.'), ] + arguments self._help = help @@ -150,9 +150,9 @@ class Command (object): if name != argument.name: params.remove(name) params[argument.name] = value - if argument.callback != None: - value = argument.callback(hooke, self, argument, value) - params[argument.name] = value + if argument.callback != None: + value = argument.callback(hooke, self, argument, value) + params[argument.name] = value argument.validate(value) return params diff --git a/hooke/hooke_cli.py b/hooke/hooke_cli.py index b283353..02c5ce2 100644 --- a/hooke/hooke_cli.py +++ b/hooke/hooke_cli.py @@ -1,52 +1,3 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -''' -hooke_cli.py - -Command line module of Hooke. - -Copyright (C) 2006 Massimo Sandal (University of Bologna, Italy). - -This program is released under the GNU General Public License version 2. -''' - -from .libhooke import HOOKE_VERSION, WX_GOOD - -import wxversion -wxversion.select(WX_GOOD) -import wx - -from wx.lib.newevent import NewEvent -from matplotlib.numerix import * #FIXME - -import xml.dom.minidom -import sys, os, os.path, glob, shutil -import Queue -import cmd -import time - -global __version__ -global __codename__ -global __releasedate__ -__version__ = HOOKE_VERSION[0] -__codename__ = HOOKE_VERSION[1] -__releasedate__ = HOOKE_VERSION[2] - -from matplotlib import __version__ as mpl_version -from wx import __version__ as wx_version -from wxmpl import __version__ as wxmpl_version -from scipy import __version__ as scipy_version -from numpy import __version__ as numpy_version -from sys import version as python_version -import platform - -from .libhooke import PlaylistXML -from . import curve as lhc -from . import libinput as linp -from . import liboutlet as lout - - class HookeCli(cmd.Cmd, object): def __init__(self,frame,list_of_events,events_from_gui,config,drivers): @@ -662,34 +613,3 @@ Syntax copylog [directory] shutil.copy(item.path, mydir) except (OSError, IOError): print 'Cannot copy file. '+item.path+' Perhaps you gave me a wrong directory?' - -#OUTLET management -#----------------- - def do_outlet_show(self,args): - '''OUTLET_SHOW - --------- - Shows current content of outlet with index for reference - ''' - self.outlet.printbuf() - - def do_outlet_undo(self, args): - '''OUTLET_UNDO - --------- - Eliminates last entry in outlet - ''' - print 'Erasing last entry' - self.outlet.pop() - - def do_outlet_delete(self, args): - '''OUTLET_DELETE - Eliminates a particular entry from outlet - Syntax: outlet_delete n - ''' - if len(args)==0: - print 'Index needed!, use outlet_show to know it' - else: - self.outlet.delete(args) - -if __name__ == '__main__': - mycli=HookeCli(0) - mycli.cmdloop() diff --git a/hooke/plugin/playlist.py b/hooke/plugin/playlist.py index 7474bf5..343b964 100644 --- a/hooke/plugin/playlist.py +++ b/hooke/plugin/playlist.py @@ -18,7 +18,7 @@ class PlaylistPlugin (Builtin): return [NextCommand(), PreviousCommand(), JumpCommand(), SaveCommand(), LoadCommand(), AddCommand(), AddGlobCommand(), - RemoveCommand(), FilterCommand()] + RemoveCommand(), FilterCommand(), NoteFilterCommand()] # Define common or complicated arguments @@ -225,3 +225,17 @@ Function returning `True` for "good" curves. `filter(curve) -> True/False`. p = params['playlist'].filter(params['filter']) hooke.playlists.add(p) outqueue.put(p) + +class NoteFilterCommand (FilterCommand): + """Create a subset playlist of curves with `.info['note'] != None`. + """ + def __init__(self): + super(NoteFilterCommand, self).__init__() + self.name = 'note filter playlist' + self.arguments = [a for a in self.arguments if a.name != 'filter'] + + def _run(self, hooke, inqueue, outqueue, params): + params['filter'] = lambda curve : \ + 'note' in curve.info and curve.info['note'] != None + return super(NoteFilterCommand, self)._run( + hooke, inqueue, outqueue, params) diff --git a/hooke/ui/commandline.py b/hooke/ui/commandline.py index 95b4bb4..3ab755d 100644 --- a/hooke/ui/commandline.py +++ b/hooke/ui/commandline.py @@ -279,7 +279,7 @@ class LocalExitCommand (Command): name='exit', aliases=['quit', 'EOF'], help=self.__doc__, arguments = [ Argument(name='force', type='bool', default=False, - callback=StoreValue(True), help=""" + help=""" Exit without prompting the user. Use if you save often or don't make typing mistakes ;). """.strip()), -- 2.26.2