|
From: Kevin A. <al...@se...> - 2006-09-16 00:00:34
|
I'm not real happy with the additional if blocks for displayProperty
and updateComponent and all the other attribute hacks used to
interpret and write out resource files.
Ideally, the attribute type would be defined as part of the spec and
we would query the spec to find out how to handle each property
rather than having the resourceEditor and propertyEditor make guesses
based on a predefined list of attribute names. For example, the
Button spec (minus comment lines) looks like:
class ButtonSpec(widget.WidgetSpec):
def __init__(self):
events = list(ButtonEvents)
attributes = {
'label' : { 'presence' : 'optional', 'default':'Button' },
'default':{'presence':'optional', 'default':0} }
widget.WidgetSpec.__init__(self, 'Button', 'Widget', events,
attributes )
This should probably be:
class ButtonSpec(widget.WidgetSpec):
def __init__(self):
events = list(ButtonEvents)
attributes = {
'label' : { 'type': types.StringType, 'presence' :
'optional', 'default':'Button' },
'default':{'type', types.BooleanType,
'presence':'optional', 'default':False} }
widget.WidgetSpec.__init__(self, 'Button', 'Widget', events,
attributes )
Note that 'default' is really a boolean, but when we started
PythonCard True and False were not available which is why we were
using 0.
Adding a basic Python type doesn't completely solve the problem
because you need to know what type of editor to use for a given
attribute. We could provide an 'editor' item as part of the
dictionary, but it might more efficient to simply define our own
types which the property editor would then use to decide which editor
to be used. For example in addition to types.ListType and
types.DictionaryType which would use a TextArea for editing we might
have:
class MultiTextType(types.StringType):
pass
for 'userdata' and 'text' attributes. We would probably have
PositionType, SizeType, FontType, ColorType, and other special
classes to cover a variety of different editors.
Components are supposed to be self-describing and if we're able to
add enough information to the spec so that the resourceEditor loses
all special knowledge of the components that would be a big plus.
ka
|