Run hooke.command.Argument.callback every time (if defined).
authorW. Trevor King <wking@drexel.edu>
Wed, 12 May 2010 18:00:57 +0000 (14:00 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 12 May 2010 18:00:57 +0000 (14:00 -0400)
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
hooke/hooke_cli.py
hooke/plugin/playlist.py
hooke/ui/commandline.py

index 82ab53ffc85c62af267bdccbf1064d589423aec8..1cdb56f80f43647c63d4f9b198a2cc78e090bf93 100644 (file)
@@ -88,7 +88,7 @@ class Command (object):
         self.aliases = aliases
         self.arguments = [
             Argument(name='help', type='bool', default=False, count=1,
         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
 
             ] + arguments
         self._help = help
 
@@ -150,9 +150,9 @@ class Command (object):
                 if name != argument.name:
                     params.remove(name)
                     params[argument.name] = value
                 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
 
             argument.validate(value)
         return params
 
index b2833535f6819e5929778126247f93dc4c678e3d..02c5ce2163d29b932989ba70673e9d3f08b6e359 100644 (file)
@@ -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):
 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?'
                     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()
index 7474bf534ac76fbde56a2ba8a63118a3fbc3fbb3..343b9643e31512996696b150471cfdb7ca12f551 100644 (file)
@@ -18,7 +18,7 @@ class PlaylistPlugin (Builtin):
         return [NextCommand(), PreviousCommand(), JumpCommand(),
                 SaveCommand(), LoadCommand(),
                 AddCommand(), AddGlobCommand(),
         return [NextCommand(), PreviousCommand(), JumpCommand(),
                 SaveCommand(), LoadCommand(),
                 AddCommand(), AddGlobCommand(),
-                RemoveCommand(), FilterCommand()]
+                RemoveCommand(), FilterCommand(), NoteFilterCommand()]
 
 
 # Define common or complicated arguments
 
 
 # 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)
         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)
index 95b4bb419852a55528837044f6e76a47411666c7..3ab755d61b6180c5175acebdf71b26ab7448491a 100644 (file)
@@ -279,7 +279,7 @@ class LocalExitCommand (Command):
             name='exit', aliases=['quit', 'EOF'], help=self.__doc__,
             arguments = [
                 Argument(name='force', type='bool', default=False,
             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()),
 Exit without prompting the user.  Use if you save often or don't make
 typing mistakes ;).
 """.strip()),