From 218a587304ca1387cbefb24fedc4b371c4125472 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 7 Aug 2010 13:55:05 -0400 Subject: [PATCH] Add 'new playlist' command and clean up 'Creating a playlist' in tutorial.txt. --- doc/tutorial.txt | 39 ++++++++++++++++++++++++++++++++++----- hooke/playlist.py | 8 ++++++-- hooke/plugin/playlist.py | 5 ++++- hooke/plugin/playlists.py | 29 ++++++++++++++++++++++++++++- hooke/ui/gui/__init__.py | 1 + 5 files changed, 73 insertions(+), 9 deletions(-) diff --git a/doc/tutorial.txt b/doc/tutorial.txt index 7b302f5..4bcb0be 100644 --- a/doc/tutorial.txt +++ b/doc/tutorial.txt @@ -51,9 +51,14 @@ also check that the current working directory (`.`) is in your As Hooke launches, you should see something like the following in your terminal:: - Hooke version 0.8.0 Seinei + Hooke version 0.9.0.devel (Kenzo) - COPYRIGHT + Copyright (C) 2006-2010 A. Seeholzer, Alberto Gomez-Casado, Allen + Chen, Fabrizio Benedetti, Francesco Musiani, Marco Brucale, Massimo + Sandal, Pancaldi Paolo, Richard Naud, Rolf Schmidt, W. Trevor King + + Hooke comes with ABSOLUTELY NO WARRANTY and is licensed under the GNU + Lesser General Public License. For details, run `license`. ---- hooke> @@ -116,8 +121,32 @@ You can list the files in the directory using ``ls`` or ``dir`` mycurve.001 ... -Now you are ready to generate the playlist. The command to use is -``glob_curves_to_playlist``.:: +Now you are ready to generate the playlist. First, create a blank playlist: + + hooke> new_playlist --name mylist + +Ensure that the new playlist is active: + + hooke> jump_to_playlist -- -1 + hooke> get_playlist + + +The ``--`` in the ``jump_to_playlist`` command lets +``jump_to_playlist`` know that ``-1`` is an argument and not an +option. Using the bare ``--`` is a POSIX specification [#]_ supported +by the `optparse module`_. + +.. _optparse module: + http://docs.python.org/library/optparse.html#callback-example-6-variable-arguments + +.. [#]: `Guideline 10 of POSIX:2008's section 12.2 ` states: + + "The first -- argument that is not an option-argument should be + accepted as a delimiter indicating the end of options. Any + following arguments should be treated as operands, even if they + begin with the '-' character." + +Then glob your curves onto the new list hooke> glob_curves_to_playlist mycurve.* @@ -127,7 +156,7 @@ You can also be more specific with wildcards. For example will take only curves from :file:`mycurve.050` to :file:`mycurve.059`. -Note that by using ``glob_curve_to_playlist`` you just generate the +Note that by using ``glob_curves_to_playlist`` you just generate the playlist in the local session. To save your playlist to a file for future reuse, type:: diff --git a/hooke/playlist.py b/hooke/playlist.py index ab32bed..dcd85b8 100644 --- a/hooke/playlist.py +++ b/hooke/playlist.py @@ -119,8 +119,6 @@ class Playlist (NoteIndexList): self._max_loaded = 100 # curves to hold in memory simultaneously. def append_curve_by_path(self, path, info=None, identify=True): - if self.path != None: - path = os.path.join(os.path.dirname(self.path), path) path = os.path.normpath(path) c = curve.Curve(path, info=info) if identify == True: @@ -146,6 +144,7 @@ class FilePlaylist (Playlist): def __init__(self, drivers, name=None, path=None): super(FilePlaylist, self).__init__(drivers, name) + self.path = None self.set_path(path) self._digest = None self._ignored_keys = [ @@ -160,6 +159,11 @@ class FilePlaylist (Playlist): if self.name == None: self.name = os.path.basename(path) + def append_curve_by_path(self, path, *args, **kwargs): + if self.path != None: + path = os.path.join(os.path.dirname(self.path), path) + super(FilePlaylist, self).append_curve_by_path(path, *args, **kwargs) + def is_saved(self): return self.digest() == self._digest diff --git a/hooke/plugin/playlist.py b/hooke/plugin/playlist.py index dccc572..9f0d9e1 100644 --- a/hooke/plugin/playlist.py +++ b/hooke/plugin/playlist.py @@ -58,6 +58,8 @@ 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: @@ -170,7 +172,8 @@ class SaveCommand (Command): Argument(name='output', type='file', help=""" File name for the output playlist. Defaults to overwriting the input -playlist. +playlist. If the playlist does not have an input file (e.g. it was +created from scratch with 'new playlist'), this option is required. """.strip()), ], help=self.__doc__, plugin=plugin) diff --git a/hooke/plugin/playlists.py b/hooke/plugin/playlists.py index 2ba4ecf..8de9ec1 100644 --- a/hooke/plugin/playlists.py +++ b/hooke/plugin/playlists.py @@ -22,7 +22,9 @@ lists of :class:`hooke.playlist.Playlist` classes. """ from ..command import Command, Argument, Failure +from ..playlist import FilePlaylist from ..plugin import Builtin +from .playlist import PlaylistNameArgument class PlaylistsPlugin (Builtin): @@ -30,7 +32,7 @@ class PlaylistsPlugin (Builtin): super(PlaylistsPlugin, self).__init__(name='playlists') self._commands = [ NextCommand(self), PreviousCommand(self), JumpCommand(self), - IndexCommand(self), PlaylistListCommand(self)] + IndexCommand(self), PlaylistListCommand(self), NewCommand(self)] # Define commands @@ -96,3 +98,28 @@ class PlaylistListCommand (Command): def _run(self, hooke, inqueue, outqueue, params): outqueue.put(list(hooke.playlists)) + + +class NewCommand (Command): + """Create a new playlist. + """ + def __init__(self, plugin): + super(NewCommand, self).__init__( + name='new playlist', + arguments=[ + PlaylistNameArgument, + Argument(name='file', type='file', optional=True, + help=""" +Default filename for future saves. +""".strip()), + ], + help=self.__doc__, plugin=plugin) + + def _run(self, hooke, inqueue, outqueue, params): + print 'PP', params['name'] + hooke.playlists.append( + FilePlaylist( + drivers=hooke.drivers, + name=params['name'], + path=params['file'], + )) diff --git a/hooke/ui/gui/__init__.py b/hooke/ui/gui/__init__.py index fecc90d..5247f93 100644 --- a/hooke/ui/gui/__init__.py +++ b/hooke/ui/gui/__init__.py @@ -735,6 +735,7 @@ class HookeFrame (wx.Frame): pass def _on_delete_curve(self, _class, method, playlist, curve): + # TODO: execute_command 'remove curve from playlist' os.remove(curve.path) def _on_set_selected_playlist(self, _class, method, playlist): -- 2.26.2