'_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
# 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
"""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
-\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
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
- 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
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
"""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
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
- # 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
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
- 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
- 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
- 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.jump(i)\r
break\r
if curve == None:\r
raise ValueError(name)\r
- curve = playlist.current()\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