Add 'new playlist' command and clean up 'Creating a playlist' in tutorial.txt.
authorW. Trevor King <wking@drexel.edu>
Sat, 7 Aug 2010 17:55:05 +0000 (13:55 -0400)
committerW. Trevor King <wking@drexel.edu>
Sat, 7 Aug 2010 17:55:05 +0000 (13:55 -0400)
doc/tutorial.txt
hooke/playlist.py
hooke/plugin/playlist.py
hooke/plugin/playlists.py
hooke/ui/gui/__init__.py

index 7b302f5379a6888c5a2cbdf8b0b080f92d3dcd3a..4bcb0bee02b898c08c2622e474df54f536d926a4 100644 (file)
@@ -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
+    <FilePlaylist mylist>
+
+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 <http://www.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02>` 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::
 
index ab32bed4be4b25ec731829eab04dc445ebe3f2bf..dcd85b8797cabb0cc2696a548d700cb092a13445 100644 (file)
@@ -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
 
index dccc572ff86d12aa5c834709c810cda30761d754..9f0d9e15674abdd79c21a3587ebae183aa18b18e 100644 (file)
@@ -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)
index 2ba4ecfe342cab3ec6c27af3ac5748ff4e33fc77..8de9ec1f643323d5fa1fb555f9e1203dcbda2665 100644 (file)
@@ -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'],
+                ))
index fecc90d312c8680546d438af29c9e57a2d15851b..5247f93ce3f932811c3e0d13a3402cd2e9f3fa02 100644 (file)
@@ -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):