+# 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)
+
+ def _set_playlist(self, hooke, params, playlist):
+ """Attach a new playlist.
+ """
+ playlist.name = params['output playlist']
+ hooke.playlists.append(playlist)
+
+