From 7f4c751d431b2e0f29733922cac10cd248347e48 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 29 Jul 2010 13:16:23 -0400 Subject: [PATCH] Fill out prop_from_arguments so PropertyPanel displays command args. --- hooke/ui/gui/__init__.py | 28 ++++---- hooke/ui/gui/panel/propertyeditor2.py | 94 +++++++++++---------------- 2 files changed, 49 insertions(+), 73 deletions(-) diff --git a/hooke/ui/gui/__init__.py b/hooke/ui/gui/__init__.py index 592e55e..85c73e7 100644 --- a/hooke/ui/gui/__init__.py +++ b/hooke/ui/gui/__init__.py @@ -36,14 +36,13 @@ 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.propertyeditor2 import prop_from_argument, prop_from_setting from . import prettyformat as prettyformat from . import statusbar as statusbar class HookeFrame (wx.Frame): - """The main Hooke-interface window. - - + """The main Hooke-interface window. """ def __init__(self, gui, commands, inqueue, outqueue, *args, **kwargs): super(HookeFrame, self).__init__(*args, **kwargs) @@ -659,19 +658,16 @@ class HookeFrame (wx.Frame): # Command panel interface def select_command(self, _class, method, command): - return - self.select_plugin(plugin=command.plugin) - plugin = self.GetItemText(selected_item) - if plugin != 'core': - doc_string = eval('plugins.' + plugin + '.' + plugin + 'Commands.__doc__') - else: - doc_string = 'The module "core" contains Hooke core functionality' - if doc_string is not None: - self.panelAssistant.ChangeValue(doc_string) - else: - self.panelAssistant.ChangeValue('') - panel.propertyeditor.PropertyEditor.Initialize(self.panelProperties, properties) - self.gui.config['selected command'] = command + #self.select_plugin(plugin=command.plugin) + if 'assistant' in self._c: + self._c['assitant'].ChangeValue(command.help) + self._c['property'].clear() + for argument in command.arguments: + if argument.name == 'help': + continue + self._c['property'].append_property(prop_from_argument( + argument, curves=[], playlists=[])) # TODO: lookup playlists/curves + self.gui.config['selected command'] = command # TODO: push to engine diff --git a/hooke/ui/gui/panel/propertyeditor2.py b/hooke/ui/gui/panel/propertyeditor2.py index 9ff7736..4efe182 100644 --- a/hooke/ui/gui/panel/propertyeditor2.py +++ b/hooke/ui/gui/panel/propertyeditor2.py @@ -17,14 +17,33 @@ import wx.grid from . import Panel -def prop_from_setting(setting): - """Convert a :class:`~hooke.config.Setting` to a :class:`Property`. - """ - raise NotImplementedError() - -def prop_from_argument(argument): +def prop_from_argument(argument, curves=None, playlists=None): """Convert a :class:`~hooke.command.Argument` to a :class:`Property`. """ + if argument.count != 1: + raise NotImplementedError(argument) + kwargs = { + 'label':argument.name, + 'default':argument.default, + 'help':argument.help, + } + type = argument.type + if type == 'file': + type = 'path' + if argument.type in ['string', 'bool', 'int', 'float', 'path']: + _class = globals()['%sProperty' % type.capitalize()] + return _class(**kwargs) + elif argument.type in ['curve', 'playlist']: + if argument.type == 'curve': + choices = curves # extract from a particular playlist? + else: + choices = playlists + return ChoiceProperty(choices=[c.name for c in choices], **kwargs) + raise NotImplementedError(argument.type) + +def prop_from_setting(setting): + """Convert a :class:`~hooke.config.Setting` to a :class:`Property`. + """ raise NotImplementedError() @@ -95,7 +114,6 @@ class BoolProperty (Property): def get_editor(self): return wx.grid.GridCellBoolEditor() - #return wx.grid.GridCellChoiceEditor(choices=['true', 'false']) def get_renderer(self): return wx.grid.GridCellBoolRenderer() @@ -170,6 +188,8 @@ class PathProperty (StringProperty): class PropertyPanel(Panel, wx.grid.Grid): + """UI to view/set config values and command argsuments. + """ def __init__(self, callbacks=None, **kwargs): super(PropertyPanel, self).__init__( name='propertyeditor', callbacks=callbacks, **kwargs) @@ -181,45 +201,6 @@ class PropertyPanel(Panel, wx.grid.Grid): self._last_tooltip = None self.GetGridWindow().Bind(wx.EVT_MOTION, self._on_mouse_over) - # add example properties for testing - self.append_property(StringProperty( - label='my string', - default='hithere', - help='help for my string', - )) - self.append_property(BoolProperty( - label='my bool', - default=True, - help='help for my bool', - )) - self.append_property(IntProperty( - label='my int', - default=5, - help='help for my int', - )) - self.append_property(FloatProperty( - label='my float', - default=3.14159, - help='help for my float', - )) - self.append_property(ChoiceProperty( - choices=['choice A', 'choice B', 'choice C'], - label='my choice', - default='choice B', - help='help for my choice', - )) - - def GetRowLabelValue(self, col=0): - """Retrieve the label for a particular column. - - Overrides the default labels, since 'SetRowLabelValue' seems - to be `ignored`_. - - .. _ignored: - http://wiki.wxpython.org/wxPyGridTableBase#Column.2BAC8-Row_Labels - """ - return self._column_labels[col] - def _on_mouse_over(self, event): """Enable tooltips. """ @@ -228,11 +209,10 @@ class PropertyPanel(Panel, wx.grid.Grid): if col == -1 or row == -1: msg = '' else: - msg = self._properties[row].help + msg = self._properties[row].help or '' if msg != self._last_tooltip: self._last_tooltip = msg event.GetEventObject().SetToolTipString(msg) - self._get_values() # for testing def append_property(self, property): if len([p for p in self._properties if p.label == property.label]) > 0: @@ -247,6 +227,15 @@ class PropertyPanel(Panel, wx.grid.Grid): self.SetCellRenderer(row=row, col=0, renderer=r) self.set_property(property.label, property.default) + def remove_property(self, label): + row,property = self._property_by_label(label) + self._properties.pop(row) + self.DeleteRows(pos=row) + + def clear(self): + while(len(self._properties) > 0): + self.remove_property(self._properties[-1].label) + def set_property(self, label, value): row,property = self._property_by_label(label) self.SetCellValue(row=row, col=0, s=property.string_for_value(value)) @@ -256,18 +245,9 @@ class PropertyPanel(Panel, wx.grid.Grid): string = self.GetCellValue(row=row, col=0) return property.value_for_string(string) - def remove_property(self, label): - row,property = self._property_by_label(label) - raise NotImplementedError() - def _property_by_label(self, label): props = [(i,p) for i,p in enumerate(self._properties) if p.label == label] assert len(props) == 1, props row,property = props[0] return (row, property) - - def _get_values(self): # for testing - for property in self._properties: - v = self.get_property(property.label) - print property.label, property.type, type(v), v -- 2.26.2