+ self._commands = [
+ NextCommand(self), PreviousCommand(self), JumpCommand(self),
+ GetCommand(self), IndexCommand(self), CurveListCommand(self),
+ NameCommand(self), SaveCommand(self), LoadCommand(self),
+ AddCommand(self), AddGlobCommand(self),
+ RemoveCommand(self), ApplyCommand(self),
+ FilterCommand(self),
+ ]
+
+
+# Define common or complicated arguments
+
+def current_playlist_callback(hooke, command, argument, value):
+ if value != None:
+ return value
+ playlist = hooke.playlists.current()
+ if playlist == None:
+ raise Failure('No playlists loaded')
+ return playlist
+
+PlaylistArgument = Argument(
+ name='playlist', type='playlist', callback=current_playlist_callback,
+ help="""
+:class:`hooke.playlist.Playlist` to act on. Defaults to the current
+playlist.
+""".strip())
+
+def playlist_name_callback(hooke, command, argument, value):
+ if value != None:
+ return value
+ i = 0
+ names = [p.name for p in hooke.playlists]
+ while True:
+ name = 'playlist-%d' % i
+ if name not in names:
+ return name
+ i += 1
+
+PlaylistNameArgument = Argument(
+ name='output playlist', type='string', optional=True,
+ callback=playlist_name_callback,
+ help="""
+Name of the new playlist (defaults to an auto-generated name).
+""".strip())
+
+def all_drivers_callback(hooke, command, argument, value):
+ return hooke.drivers
+
+
+# Define useful command subclasses
+
+class PlaylistCommand (Command):
+ """A :class:`~hooke.command.Command` operating on a
+ :class:`~hooke.playlist.Playlist`.
+ """
+ def __init__(self, **kwargs):
+ if 'arguments' in kwargs:
+ kwargs['arguments'].insert(0, PlaylistArgument)
+ else:
+ kwargs['arguments'] = [PlaylistArgument]
+ super(PlaylistCommand, self).__init__(**kwargs)
+
+ def _playlist(self, hooke, params):
+ """Get the selected playlist.
+
+ Notes
+ -----
+ `hooke` is intended to attach the selected playlist to the
+ local hooke instance; the returned playlist should not be
+ effected by the state of `hooke`.
+ """
+ # HACK? rely on params['playlist'] being bound to the local
+ # hooke (i.e. not a copy, as you would get by passing a
+ # playlist through the queue). Ugh. Stupid queues. As an
+ # alternative, we could pass lookup information through the
+ # queue...
+ return params['playlist']
+
+
+class PlaylistAddingCommand (Command):
+ """A :class:`~hooke.command.Command` adding a
+ :class:`~hooke.playlist.Playlist`.
+ """
+ def __init__(self, **kwargs):
+ if 'arguments' in kwargs:
+ kwargs['arguments'].insert(0, PlaylistNameArgument)
+ else:
+ kwargs['arguments'] = [PlaylistNameArgument]
+ super(PlaylistAddingCommand, self).__init__(**kwargs)