"""Defines :class:`CutPlugin` and :class:`CutCommand`.
"""
-from ..command import Command, Argument
+from ..command import Command, Argument, Failure
from ..plugin import Plugin
def commands(self):
return [CutCommand()]
+
+# Define common or complicated arguments
+
+def current_curve_callback(hooke, command, argument, value):
+ playlist = hooke.playlists.current()
+ if playlist == None:
+ raise Failure('No playlists loaded')
+ curve = playlist.current()
+ if curve == None:
+ raise Failure('No curves in playlist %s' % playlist.name)
+ return curve
+
+CurveArgument = Argument(
+ name='curve', type='curve', callback=current_curve_callback,
+ help="""
+:class:`hooke.curve.Curve` to cut from. Defaults to the current curve.
+""".strip())
+
+
+# Define commands
+
class CutCommand (Command):
"""Cut the selected signal between two points and write it to a file.
super(CutCommand, self).__init__(
name='cut',
arguments=[
- Argument(name='curve', type='curve', help="""
-:class:`hooke.curve.Curve` to cut from. Defaults to the current curve.
-""".strip()),
+ CurveArgument,
Argument(name='block', aliases=['set'], type='int', default=0,
help="""
Data block to save. For an approach/retract force curve, `0` selects