\r
# Command-specific postprocessing\r
\r
- def _postprocess_text(self, command, args, results):\r
+ def _postprocess_text(self, command, args={}, 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
self._c['output'].write(result.__class__.__name__+'\n')\r
self._c['output'].write(str(result).rstrip()+'\n')\r
\r
- def _postprocess_load_playlist(self, command, args, results):\r
+ def _postprocess_load_playlist(self, command, args={}, results=None):\r
"""Update `self` to show the playlist.\r
"""\r
if not isinstance(results[-1], Success):\r
- self._postprocess_text(command, results)\r
+ self._postprocess_text(command, results=results)\r
assert len(results) == 2, results\r
playlist = results[0]\r
self._c['playlists']._c['tree'].add_playlist(playlist)\r
\r
- def _postprocess_get_playlist(self, command, args, results):\r
+ def _postprocess_get_playlist(self, command, args={}, results=[]):\r
if not isinstance(results[-1], Success):\r
- self._postprocess_text(command, results)\r
+ self._postprocess_text(command, results=results)\r
assert len(results) == 2, results\r
playlist = results[0]\r
self._c['playlists']._c['tree'].update_playlist(playlist)\r
\r
- def _postprocess_get_curve(self, command, args, results):\r
+ def _postprocess_get_curve(self, command, args={}, results=[]):\r
"""Update `self` to show the curve.\r
"""\r
if not isinstance(results[-1], Success):\r
- self._postprocess_text(command, results)\r
+ self._postprocess_text(command, results=results)\r
assert len(results) == 2, results\r
curve = results[0]\r
if args.get('curve', None) == None:\r
self._c['playlists']._c['tree'].set_selected_curve(\r
playlist, curve)\r
\r
- def _postprocess_next_curve(self, command, args, results):\r
+ def _postprocess_next_curve(self, command, args={}, results=[]):\r
"""No-op. Only call 'next curve' via `self._next_curve()`.\r
"""\r
pass\r
\r
- def _postprocess_previous_curve(self, command, args, results):\r
+ def _postprocess_previous_curve(self, command, args={}, results=[]):\r
"""No-op. Only call 'previous curve' via `self._previous_curve()`.\r
"""\r
pass\r
for argument in command.arguments:\r
if argument.name == 'help':\r
continue\r
+\r
+ results = self.execute_command(\r
+ command=self._command_by_name('playlists'))\r
+ if not isinstance(results[-1], Success):\r
+ self._postprocess_text(command, results=results)\r
+ playlists = []\r
+ else:\r
+ playlists = results[0]\r
+\r
+ results = self.execute_command(\r
+ command=self._command_by_name('playlist curves'))\r
+ if not isinstance(results[-1], Success):\r
+ self._postprocess_text(command, results=results)\r
+ curves = []\r
+ else:\r
+ curves = results[0]\r
+\r
p = prop_from_argument(\r
- argument, curves=[], playlists=[]) # TODO: lookup playlists/curves\r
+ argument, curves=curves, playlists=playlists)\r
if p == None:\r
continue # property intentionally not handled (yet)\r
self._c['property'].append_property(p)\r
value='0',\r
help='This should probably go...'),\r
Setting(section=self.setting_section, option='main height',\r
- value=500,\r
+ value=450,\r
help='Height of main window in pixels.'),\r
Setting(section=self.setting_section, option='main width',\r
- value=500,\r
+ value=800,\r
help='Width of main window in pixels.'),\r
Setting(section=self.setting_section, option='main top',\r
value=0,\r
return _class(**kwargs)\r
elif type in ['curve', 'playlist']:\r
if type == 'curve':\r
- choices = curves # extract from a particular playlist?\r
+ choices = curves # extracted from the current playlist\r
else:\r
choices = playlists\r
- return ChoiceProperty(choices=[c.name for c in choices], **kwargs)\r
+ return ChoiceProperty(choices=choices, **kwargs)\r
raise NotImplementedError(argument.type)\r
\r
def prop_from_setting(setting):\r
class ChoiceProperty (Property):\r
def __init__(self, choices, **kwargs):\r
assert 'type' not in kwargs, kwargs\r
- if 'default' not in kwargs:\r
+ if 'default' in kwargs:\r
+ if kwargs['default'] not in choices:\r
+ choices.insert(0, kwargs['default'])\r
+ else:\r
kwargs['default'] = choices[0]\r
super(ChoiceProperty, self).__init__(type='choice', **kwargs)\r
self._choices = choices\r
\r
def get_editor(self):\r
- return wx.grid.GridCellChoiceEditor(choices=self._choices)\r
+ choices = [self.string_for_value(c) for c in self._choices]\r
+ return wx.grid.GridCellChoiceEditor(choices=choices)\r
\r
def get_renderer(self):\r
return None\r
#return wx.grid.GridCellChoiceRenderer()\r
\r
+ def string_for_value(self, value):\r
+ if hasattr(value, 'name'):\r
+ return value.name\r
+ return str(value)\r
+\r
+ def value_for_string(self, string):\r
+ for choice in self._choices:\r
+ if self.string_for_value(choice) == string:\r
+ return choice\r
+ raise ValueError(string)\r
+\r
+\r
class PathProperty (StringProperty):\r
"""Simple file or path property.\r
\r