From: W. Trevor King Date: Wed, 4 Aug 2010 17:36:40 +0000 (-0400) Subject: Add support to GUI's property editor for argument.count > 1. X-Git-Url: http://git.tremily.us/?p=hooke.git;a=commitdiff_plain;h=f6ece66e5850e6b2d8743faa532552097e60bfd7 Add support to GUI's property editor for argument.count > 1. Now we only bail if the argument count is -1 (infinite). Also fix a col,row -> row,col bug that was goofing up property tooltips. --- diff --git a/hooke/ui/gui/__init__.py b/hooke/ui/gui/__init__.py index 5eeff7d..ed03c2f 100644 --- a/hooke/ui/gui/__init__.py +++ b/hooke/ui/gui/__init__.py @@ -53,7 +53,7 @@ from .dialog.save_file import select_save_file from . import menu as menu from . import navbar as navbar from . import panel as panel -from .panel.propertyeditor import prop_from_argument, prop_from_setting +from .panel.propertyeditor import props_from_argument, props_from_setting from . import statusbar as statusbar @@ -115,6 +115,10 @@ class HookeFrame (wx.Frame): self._setup_perspectives() self._bind_events() + self.execute_command( + command=self._command_by_name('load playlist'), + args={'input':'test/data/test'},#vclamp_picoforce/playlist'}, + ) self.execute_command( command=self._command_by_name('load playlist'), args={'input':'test/data/vclamp_picoforce/playlist'}, @@ -313,10 +317,25 @@ class HookeFrame (wx.Frame): args = {} if ('property editor' in self._c and self.gui.config['selected command'] == command): - arg_names = [arg.name for arg in command.arguments] for name,value in self._c['property editor'].get_values().items(): - if name in arg_names: - args[name] = value + arg = self._c['property editor']._argument_from_label.get( + name, None) + if arg == None: + continue + elif arg.count == 1: + args[arg.name] = value + continue + # deal with counted arguments + if arg.name not in args: + args[arg.name] = {} + index = int(name[len(arg.name):]) + args[arg.name][index] = value + for arg in command.arguments: + if arg.count != 1 and arg.name in args: + keys = sorted(args[arg.name].keys()) + assert keys == range(arg.count), keys + args[arg.name] = [args[arg.name][i] + for i in range(arg.count)] self.log.debug('executing %s with %s' % (command.name, args)) self.inqueue.put(CommandMessage(command, args)) results = [] @@ -653,6 +672,7 @@ class HookeFrame (wx.Frame): if 'assistant' in self._c: self._c['assitant'].ChangeValue(command.help) self._c['property editor'].clear() + self._c['property editor']._argument_from_label = {} for argument in command.arguments: if argument.name == 'help': continue @@ -673,11 +693,14 @@ class HookeFrame (wx.Frame): else: curves = results[0] - p = prop_from_argument( + ret = props_from_argument( argument, curves=curves, playlists=playlists) - if p == None: + if ret == None: continue # property intentionally not handled (yet) - self._c['property editor'].append_property(p) + for label,p in ret: + self._c['property editor'].append_property(p) + self._c['property editor']._argument_from_label[label] = ( + argument) self.gui.config['selected command'] = command # TODO: push to engine diff --git a/hooke/ui/gui/panel/propertyeditor.py b/hooke/ui/gui/panel/propertyeditor.py index 559ba42..4c45891 100644 --- a/hooke/ui/gui/panel/propertyeditor.py +++ b/hooke/ui/gui/panel/propertyeditor.py @@ -32,39 +32,48 @@ widely installed (or at least released ;). import wx.grid from . import Panel +from ....plugin import argument_to_setting +from ....util.convert import ANALOGS -def prop_from_argument(argument, curves=None, playlists=None): - """Convert a :class:`~hooke.command.Argument` to a :class:`Property`. +def props_from_argument(argument, curves=None, playlists=None): + """Convert a :class:`~hooke.command.Argument` to a list of + :class:`Property`\s. """ type = argument.type if type in ['driver']: # intentionally not handled (yet) return None - if argument.count != 1: - raise NotImplementedError(argument) + if argument.count == -1: + raise NotImplementedError(argument) # TODO: maybe just set count to 1? kwargs = { - 'label':argument.name, + #'label':argument.name, 'default':argument.default, 'help':argument.help(), } - # type consolidation - if type == 'file': - type = 'path' + type = ANALOGS.get(type, type) # type consolidation # type handling if type in ['string', 'bool', 'int', 'float', 'path']: _class = globals()['%sProperty' % type.capitalize()] - return _class(**kwargs) elif type in ['curve', 'playlist']: if type == 'curve': choices = curves # extracted from the current playlist else: choices = playlists - return ChoiceProperty(choices=choices, **kwargs) - raise NotImplementedError(argument.type) - -def prop_from_setting(setting): - """Convert a :class:`~hooke.config.Setting` to a :class:`Property`. + properties = [] + _class = ChoiceProperty + kwargs['choices'] = choices + else: + raise NotImplementedError(argument.type) + labels = ['%s %d' % (argument.name, i) for i in range(argument.count)] + return [(label, _class(label=label, **kwargs)) for label in labels] + + +def props_from_setting(setting): + """Convert a :class:`~hooke.config.Setting` to a list of + :class:`Property`\s. """ + # TODO: move props_from_argument code here and use + # argument_to_setting there. raise NotImplementedError() @@ -242,7 +251,7 @@ class PropertyPanel(Panel, wx.grid.Grid): """Enable tooltips. """ x,y = self.CalcUnscrolledPosition(event.GetPosition()) - col,row = self.XYToCell(x, y) + row,col = self.XYToCell(x, y) if col == -1 or row == -1: msg = '' else: