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