get prev/next playlist buttons working in the navbar
authorW. Trevor King <wking@drexel.edu>
Fri, 30 Jul 2010 13:14:10 +0000 (09:14 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 30 Jul 2010 13:14:10 +0000 (09:14 -0400)
hooke/ui/gui/__init__.py
hooke/ui/gui/panel/playlist.py

index f677171d12df3de96a3461733ce7e3e0eae56056..be0c7f2a33b5ea5eff7883b6ce173495ea0e692d 100644 (file)
@@ -122,7 +122,8 @@ class HookeFrame (wx.Frame):
                         '_delete_playlist':self._on_delete_playlist,\r
                         'delete_curve':self._on_user_delete_curve,\r
                         '_delete_curve':self._on_delete_curve,\r
                         '_delete_playlist':self._on_delete_playlist,\r
                         'delete_curve':self._on_user_delete_curve,\r
                         '_delete_curve':self._on_delete_curve,\r
-                        '_set_selected_curve':self._on_set_selected_curve,\r
+                        '_on_set_selected_playlist':self._on_set_selected_playlist,\r
+                        '_on_set_selected_curve':self._on_set_selected_curve,\r
                         },\r
                     config=self.gui.config,\r
                     parent=self,\r
                         },\r
                     config=self.gui.config,\r
                     parent=self,\r
@@ -332,19 +333,6 @@ class HookeFrame (wx.Frame):
 \r
     # Command-specific postprocessing\r
 \r
 \r
     # Command-specific postprocessing\r
 \r
-    def _postprocess_text(self, command, results):\r
-        """Print the string representation of the results to the Results window.\r
-\r
-        This is similar to :class:`~hooke.ui.commandline.DoCommand`'s\r
-        approach, except that :class:`~hooke.ui.commandline.DoCommand`\r
-        doesn't print some internally handled messages\r
-        (e.g. :class:`~hooke.interaction.ReloadUserInterfaceConfig`).\r
-        """\r
-        for result in results:\r
-            if isinstance(result, CommandExit):\r
-                self._c['output'].write(result.__class__.__name__+'\n')\r
-            self._c['output'].write(str(result).rstrip()+'\n')\r
-\r
     def _postprocess_text(self, command, results):\r
         """Print the string representation of the results to the Results window.\r
 \r
     def _postprocess_text(self, command, results):\r
         """Print the string representation of the results to the Results window.\r
 \r
@@ -362,13 +350,42 @@ class HookeFrame (wx.Frame):
         """Update `self` to show the playlist.\r
         """\r
         if not isinstance(results[-1], Success):\r
         """Update `self` to show the playlist.\r
         """\r
         if not isinstance(results[-1], Success):\r
-            return  # error executing 'load playlist'\r
+            self._postprocess_text(command, results)\r
         assert len(results) == 2, results\r
         playlist = results[0]\r
         print playlist\r
         assert len(results) == 2, results\r
         playlist = results[0]\r
         print playlist\r
-\r
         self._c['playlists']._c['tree'].add_playlist(playlist)\r
 \r
         self._c['playlists']._c['tree'].add_playlist(playlist)\r
 \r
+    def _postprocess_get_playlist(self, command, results):\r
+        if not isinstance(results[-1], Success):\r
+            self._postprocess_text(command, results)\r
+        assert len(results) == 2, results\r
+        playlist = results[0]\r
+        print playlist\r
+        self._c['playlists']._c['tree'].update_playlist(playlist)\r
+\r
+    def _postprocess_get_curve(self, command, results):\r
+        """Update `self` to show the curve.\r
+        """\r
+        if not isinstance(results[-1], Success):\r
+            self._postprocess_text(command, results)\r
+        assert len(results) == 2, results\r
+        curve = results[0]\r
+        playlist = self._c['playlists']._c['tree'].get_selected_playlist()\r
+        if playlist != None:  # TODO: fix once we have hooke.plugin.playlists\r
+            self._c['playlists']._c['tree'].set_selected_curve(\r
+                playlist, curve)\r
+\r
+    def _postprocess_next_curve(self, command, results):\r
+        """No-op.  Only call 'next curve' via `self._next_curve()`.\r
+        """\r
+        pass\r
+\r
+    def _postprocess_previous_curve(self, command, results):\r
+        """No-op.  Only call 'previous curve' via `self._previous_curve()`.\r
+        """\r
+        pass\r
+\r
 \r
     # TODO: cruft\r
 \r
 \r
     # TODO: cruft\r
 \r
@@ -699,8 +716,29 @@ class HookeFrame (wx.Frame):
     def _on_delete_curve(self, _class, method, playlist, curve):\r
         os.remove(curve.path)\r
 \r
     def _on_delete_curve(self, _class, method, playlist, curve):\r
         os.remove(curve.path)\r
 \r
+    def _on_set_selected_playlist(self, _class, method, playlist):\r
+        """TODO: playlists plugin with `jump to playlist`.\r
+        """\r
+        pass\r
+\r
     def _on_set_selected_curve(self, _class, method, playlist, curve):\r
     def _on_set_selected_curve(self, _class, method, playlist, curve):\r
-        print 'selected', playlist.name, curve.name\r
+        """Call the `jump to curve` command.\r
+\r
+        TODO: playlists plugin.\r
+        """\r
+        # TODO: jump to playlist, get playlist\r
+        index = playlist.index(curve)\r
+        results = self.execute_command(\r
+            command=self._command_by_name('jump to curve'),\r
+            args={'index':index})\r
+        if not isinstance(results[-1], Success):\r
+            return\r
+        #results = self.execute_command(\r
+        #    command=self._command_by_name('get playlist'))\r
+        #if not isinstance(results[-1], Success):\r
+        #    return\r
+        self.execute_command(\r
+            command=self._command_by_name('get curve'))\r
 \r
 \r
 \r
 \r
 \r
 \r
@@ -718,7 +756,7 @@ class HookeFrame (wx.Frame):
     def _previous_curve(self, *args):\r
         """Call the `previous curve` command.\r
         """\r
     def _previous_curve(self, *args):\r
         """Call the `previous curve` command.\r
         """\r
-        self.execute_command(\r
+        results = self.execute_command(\r
             command=self._command_by_name('previous curve'))\r
         if isinstance(results[-1], Success):\r
             self.execute_command(\r
             command=self._command_by_name('previous curve'))\r
         if isinstance(results[-1], Success):\r
             self.execute_command(\r
index 37782c30f2acb7d2021d4dfc25965cb4e2bb03e2..5cbeda1b9570e5d188d59b6775203b443d8c9d0c 100644 (file)
@@ -250,7 +250,11 @@ class Tree (wx.TreeCtrl):
         """Return the selected :class:`hooke.playlist.Playlist`.\r
         """\r
         _id = self.GetSelection()\r
         """Return the selected :class:`hooke.playlist.Playlist`.\r
         """\r
         _id = self.GetSelection()\r
-        name = self._name_for_id[self._canonical_id(_id)]\r
+        try:\r
+            _id = self._canonical_id(_id)\r
+        except KeyError:  # no playlist selected\r
+            return None\r
+        name = self._name_for_id[_id]\r
         if self._is_curve(name):\r
             name = name[0]\r
         return self._playlists[name]\r
         if self._is_curve(name):\r
             name = name[0]\r
         return self._playlists[name]\r
@@ -269,13 +273,10 @@ class Tree (wx.TreeCtrl):
             playlist = self._playlists[name]\r
         return playlist.current()\r
 \r
             playlist = self._playlists[name]\r
         return playlist.current()\r
 \r
-    # Set selection\r
-    #  set_* called by HookeFrame, includes tree display updates\r
-    #  _set_* called on every selection (including _on_select)\r
+    # Set selection (via user interaction with this panel)\r
     #\r
     #\r
-    # Selection is a bit tricky, because playlists are never selected\r
-    # directly.  Selecting a playlist is equivalent to selecting its\r
-    # current curve.\r
+    # These are hooks for HookeFrame callbacks which will send\r
+    # the results back via 'get curve' calling 'set_selected_curve'.\r
 \r
     def _on_select(self, event):\r
         """Select the clicked-on curve/playlist.\r
 \r
     def _on_select(self, event):\r
         """Select the clicked-on curve/playlist.\r
@@ -284,55 +285,40 @@ class Tree (wx.TreeCtrl):
         name = self._name_for_id[self._canonical_id(_id)]\r
         if self._is_curve(name):\r
             p_name,c_name = name\r
         name = self._name_for_id[self._canonical_id(_id)]\r
         if self._is_curve(name):\r
             p_name,c_name = name\r
-            self._set_selected_curve(p_name, c_name)\r
+            self._on_set_selected_curve(p_name, c_name)\r
         else:\r
         else:\r
-            self._set_selected_playlist(name)\r
-\r
-    def set_selected_playlist(self, name):\r
-        """Set the selected :class:`hooke.playlist.Playlist` by name.\r
-\r
-        Just a wrapper around :meth:`_set_selected_playlist`.\r
-        """\r
-        #  Selection would be overridden by _set_select_playlist\r
-        #self.SelectItem(self._id_for_name[name])\r
-        self.Expand(self._id_for_name[name])\r
-        self._set_selected_playlist(name)\r
-\r
-    def _set_selected_playlist(self, name):\r
-        """Selects the playlist's current :class:`hooke.curve.Curve`.\r
+            self._on_set_selected_playlist(name)\r
 \r
 \r
-        Updates the tree to display, which calls\r
-        :meth:`_set_selected_curvet` via :meth:`_on_select`.\r
-        """\r
-        playlist = self._playlists[name]\r
-        curve = playlist.current()\r
-        self.SelectItem(self._id_for_name[(name, curve.name)])\r
-        # triggers _set_selected_curve\r
-        \r
-    def set_selected_curve(self, playlist_name, name):\r
-        """Set the selected :class:`hooke.curve.Curve` by name.\r
-\r
-        Updates the tree display, which calls\r
-        :meth:`_set_selected_curvet` via :meth:`_on_select`.\r
-        """\r
-        self.Expand(self._id_for_name[playlist_name])\r
-        self.SelectItem(self._id_for_name[(playlist_name, name)])\r
-        # triggers _set_selected_curve\r
+    def _on_set_selected_playlist(self, name):\r
+        in_callback(self, self._playlists[name])\r
 \r
 \r
-    def _set_selected_curve(self, playlist_name, name):\r
-        """Make the curve the playlist's current curve.\r
-        """\r
+    def _on_set_selected_curve(self, playlist_name, name):\r
         playlist = self._playlists[playlist_name]\r
         curve = None\r
         for i,c in enumerate(playlist):\r
             if c.name == name:\r
                 curve = c\r
         playlist = self._playlists[playlist_name]\r
         curve = None\r
         for i,c in enumerate(playlist):\r
             if c.name == name:\r
                 curve = c\r
-                playlist.jump(i)\r
                 break\r
         if curve == None:\r
             raise ValueError(name)\r
                 break\r
         if curve == None:\r
             raise ValueError(name)\r
-        curve = playlist.current()\r
         in_callback(self, playlist, curve)\r
         in_callback(self, playlist, curve)\r
+        \r
+    # Set selection (from the HookeFrame)\r
+\r
+    def set_selected_curve(self, playlist, curve):\r
+        """Make the curve the playlist's current curve.\r
+        """\r
+        print 'expanding', playlist.name\r
+        self.Expand(self._id_for_name[playlist.name])\r
+        self.Unbind(wx.EVT_TREE_SEL_CHANGED)\r
+        print 'selecting', curve.name\r
+        self.SelectItem(self._id_for_name[(playlist.name, curve.name)])\r
+        self.Bind(wx.EVT_TREE_SEL_CHANGED, self._on_select)\r
+\r
+    def update_playlist(self, playlist):\r
+        """Absorb changed `._index`, etc.\r
+        """\r
+        self._playlists[playlist.name] = playlist\r
 \r
 \r
 class Playlist (Panel, wx.Panel):\r
 \r
 \r
 class Playlist (Panel, wx.Panel):\r