From: W. Trevor King Date: Sat, 31 Jul 2010 12:36:29 +0000 (-0400) Subject: Fixed curve/playlist choice argument handling in panel.propertyeditor2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ac94344d559d3eb35cd5eb04c02b198a4a81bbac;p=hooke.git Fixed curve/playlist choice argument handling in panel.propertyeditor2 --- diff --git a/hooke/ui/gui/__init__.py b/hooke/ui/gui/__init__.py index 231b054..b1e854d 100644 --- a/hooke/ui/gui/__init__.py +++ b/hooke/ui/gui/__init__.py @@ -335,7 +335,7 @@ class HookeFrame (wx.Frame): # Command-specific postprocessing - def _postprocess_text(self, command, args, results): + def _postprocess_text(self, command, args={}, results=[]): """Print the string representation of the results to the Results window. This is similar to :class:`~hooke.ui.commandline.DoCommand`'s @@ -348,27 +348,27 @@ class HookeFrame (wx.Frame): self._c['output'].write(result.__class__.__name__+'\n') self._c['output'].write(str(result).rstrip()+'\n') - def _postprocess_load_playlist(self, command, args, results): + def _postprocess_load_playlist(self, command, args={}, results=None): """Update `self` to show the playlist. """ if not isinstance(results[-1], Success): - self._postprocess_text(command, results) + self._postprocess_text(command, results=results) assert len(results) == 2, results playlist = results[0] self._c['playlists']._c['tree'].add_playlist(playlist) - def _postprocess_get_playlist(self, command, args, results): + def _postprocess_get_playlist(self, command, args={}, results=[]): if not isinstance(results[-1], Success): - self._postprocess_text(command, results) + self._postprocess_text(command, results=results) assert len(results) == 2, results playlist = results[0] self._c['playlists']._c['tree'].update_playlist(playlist) - def _postprocess_get_curve(self, command, args, results): + def _postprocess_get_curve(self, command, args={}, results=[]): """Update `self` to show the curve. """ if not isinstance(results[-1], Success): - self._postprocess_text(command, results) + self._postprocess_text(command, results=results) assert len(results) == 2, results curve = results[0] if args.get('curve', None) == None: @@ -381,12 +381,12 @@ class HookeFrame (wx.Frame): self._c['playlists']._c['tree'].set_selected_curve( playlist, curve) - def _postprocess_next_curve(self, command, args, results): + def _postprocess_next_curve(self, command, args={}, results=[]): """No-op. Only call 'next curve' via `self._next_curve()`. """ pass - def _postprocess_previous_curve(self, command, args, results): + def _postprocess_previous_curve(self, command, args={}, results=[]): """No-op. Only call 'previous curve' via `self._previous_curve()`. """ pass @@ -696,8 +696,25 @@ class HookeFrame (wx.Frame): for argument in command.arguments: if argument.name == 'help': continue + + results = self.execute_command( + command=self._command_by_name('playlists')) + if not isinstance(results[-1], Success): + self._postprocess_text(command, results=results) + playlists = [] + else: + playlists = results[0] + + results = self.execute_command( + command=self._command_by_name('playlist curves')) + if not isinstance(results[-1], Success): + self._postprocess_text(command, results=results) + curves = [] + else: + curves = results[0] + p = prop_from_argument( - argument, curves=[], playlists=[]) # TODO: lookup playlists/curves + argument, curves=curves, playlists=playlists) if p == None: continue # property intentionally not handled (yet) self._c['property'].append_property(p) @@ -1012,10 +1029,10 @@ class GUI (UserInterface): value='0', help='This should probably go...'), Setting(section=self.setting_section, option='main height', - value=500, + value=450, help='Height of main window in pixels.'), Setting(section=self.setting_section, option='main width', - value=500, + value=800, help='Width of main window in pixels.'), Setting(section=self.setting_section, option='main top', value=0, diff --git a/hooke/ui/gui/panel/propertyeditor2.py b/hooke/ui/gui/panel/propertyeditor2.py index 0bf04a3..759441e 100644 --- a/hooke/ui/gui/panel/propertyeditor2.py +++ b/hooke/ui/gui/panel/propertyeditor2.py @@ -39,10 +39,10 @@ def prop_from_argument(argument, curves=None, playlists=None): return _class(**kwargs) elif type in ['curve', 'playlist']: if type == 'curve': - choices = curves # extract from a particular playlist? + choices = curves # extracted from the current playlist else: choices = playlists - return ChoiceProperty(choices=[c.name for c in choices], **kwargs) + return ChoiceProperty(choices=choices, **kwargs) raise NotImplementedError(argument.type) def prop_from_setting(setting): @@ -168,18 +168,34 @@ class FloatProperty (Property): class ChoiceProperty (Property): def __init__(self, choices, **kwargs): assert 'type' not in kwargs, kwargs - if 'default' not in kwargs: + if 'default' in kwargs: + if kwargs['default'] not in choices: + choices.insert(0, kwargs['default']) + else: kwargs['default'] = choices[0] super(ChoiceProperty, self).__init__(type='choice', **kwargs) self._choices = choices def get_editor(self): - return wx.grid.GridCellChoiceEditor(choices=self._choices) + choices = [self.string_for_value(c) for c in self._choices] + return wx.grid.GridCellChoiceEditor(choices=choices) def get_renderer(self): return None #return wx.grid.GridCellChoiceRenderer() + def string_for_value(self, value): + if hasattr(value, 'name'): + return value.name + return str(value) + + def value_for_string(self, string): + for choice in self._choices: + if self.string_for_value(choice) == string: + return choice + raise ValueError(string) + + class PathProperty (StringProperty): """Simple file or path property.