"""Defines :class:`PlaylistPlugin` several associated :class:`hooke.plugin.Command`\s. """ from ..playlist import FilePlaylist from ..plugin import Builtin, Command, Argument class PlaylistPlugin (Builtin): def __init__(self): super(PlaylistPlugin, self).__init__(name='playlist') def commands(self): return [NextCommand(), PreviousCommand(), JumpCommand(), SaveCommand(), LoadCommand(), AddCommand(), RemoveCommand(), FilterCommand()] class NextCommand (Command): """Move playlist to the next curve. """ def __init__(self): super(NextCommand, self).__init__( name='next curve', arguments=[ Argument(name='playlist', type='playlist', optional=False, help=""" :class:``hooke.plugin.playlist.Playlist`` to act on. """.strip()), ], help=self.__doc__) def _run(inqueue, outqueue, params): params['playlist'].next() class PreviousCommand (Command): """Move playlist to the previous curve. """ def __init__(self): super(PreviousCommand, self).__init__( name='previous curve', arguments=[ Argument(name='playlist', type='playlist', optional=False, help=""" :class:``hooke.plugin.playlist.Playlist`` to act on. """.strip()), ], help=self.__doc__) def _run(inqueue, outqueue, params): params['playlist'].previous() class JumpCommand (Command): """Move playlist to a given curve. """ def __init__(self): super(JumpCommand, self).__init__( name='jump to curve', arguments=[ Argument(name='playlist', type='playlist', optional=False, help=""" :class:``hooke.plugin.playlist.Playlist`` to act on. """.strip()), Argument(name='index', type='int', optional=False, help=""" Index of target curve. """.strip()), ], help=self.__doc__) def _run(inqueue, outqueue, params): params['playlist'].jump(params['index']) class SaveCommand (Command): """Save a playlist. """ def __init__(self): super(SaveCommand, self).__init__( name='save playlist', arguments=[ Argument(name='playlist', type='playlist', optional=False, help=""" :class:``hooke.plugin.playlist.Playlist`` to act on. """.strip()), Argument(name='output', type='file', help=""" File name for the output playlist. Defaults to overwring the input playlist. """.strip()), ], help=self.__doc__) def _run(inqueue, outqueue, params): params['playlist'].save(params['output']) class LoadCommand (Command): """Load a playlist. """ def __init__(self): super(LoadCommand, self).__init__( name='load playlist', arguments=[ Argument(name='input', type='file', optional=False, help=""" File name for the input playlist. """.strip()), Argument(name='digests', type='digest', optional=False, count=-1, help=""" Digests for loading curves. """.strip()), ], help=self.__doc__) def _run(inqueue, outqueue, params): p = FilePlaylist(drivers=params['drivers'], path=params['input']) p.load() outqueue.put(p) class AddCommand (Command): """Add a curve to a playlist. """ def __init__(self): super(AddCommand, self).__init__( name='add curve to playlist', arguments=[ Argument(name='playlist', type='playlist', optional=False, help=""" :class:``hooke.plugin.playlist.Playlist`` to act on. """.strip()), Argument(name='input', type='file', optional=False, help=""" File name for the input :class:`hooke.curve.Curve`. """.strip()), Argument(name='info', type='dict', optional=True, help=""" Additional information for the input :class:`hooke.curve.Curve`. """.strip()), ], help=self.__doc__) def _run(inqueue, outqueue, params): params['playlist'].append_curve_by_path(params['input'], params['info']) class RemoveCommand (Command): """Remove a curve from a playlist. """ def __init__(self): super(RemoveCommand, self).__init__( name='remove curve from playlist', arguments=[ Argument(name='playlist', type='playlist', optional=False, help=""" :class:``hooke.plugin.playlist.Playlist`` to act on. """.strip()), Argument(name='index', type='int', optional=False, help=""" Index of target curve. """.strip()), ], help=self.__doc__) def _run(inqueue, outqueue, params): params['playlist'].pop(params['index']) params['playlist'].jump(params._index) class FilterCommand (Command): """Create a subset playlist via a selection function. """ def __init__(self): super(FilterCommand, self).__init__( name='filter playlist', arguments=[ Argument(name='playlist', type='playlist', optional=False, help=""" :class:``hooke.plugin.playlist.Playlist`` to act on. """.strip()), Argument(name='filter', type='function', optional=False, help=""" Function returning `True` for "good" curves. """.strip()), ], help=self.__doc__) def _run(inqueue, outqueue, params): p = params['playlist'].filter(params['filter']) outqueue.put(p)