I've been experimenting with adding properties to wxPython. (Properties are
attributes that magically turn into Get or Set method calls.) They let you
do things like
print window.size
window.size = (300,200)
instead of
print window.GetSize()
window.SetSize( (300,200) )
It acutally turned out to be a bit easier than I was expecting. It is even
possible for classes implemented in Python to add their own properties or
override those in the base classes.
A potential problem is name clashes. (The demo has a few already.) It can
be a bit suprizing sometimes that assigning something to self.sizer doesn't
actually save a local reference to the something but calls a method instead.
Especially if it worked fine yesterday before the properties and acts
wierdly today...
So what's your opinion on properties? Is the syntactic sugar worth the
potential hassles? Should it wait until there is Python specific
documentation so you don't have to search the sources to know what names are
magic?
FYI, here are the properties for wxWindow and the methods that would be
called to access or set them:
_prop_list_ = {
'size' : ('GetSize', 'SetSize'),
'enabled' : ('IsEnabled', 'Enable'),
'background' : ('GetBackgroundColour',
'SetBackgroundColour'),
'foreground' : ('GetForegroundColour',
'SetForegroundColour'),
'children' : ('GetChildren', None),
'charHeight' : ('GetCharHeight', None),
'charWidth' : ('GetCharWidth', None),
'clientSize' : ('GetClientSize', 'SetClientSize'),
'font' : ('GetFont', 'SetFont'),
'grandParent' : ('GetGrandParent', None),
'handle' : ('GetHandle', None),
'label' : ('GetLabel', 'SetLabel'),
'name' : ('GetName', 'SetName'),
'parent' : ('GetParent', None),
'position' : ('GetPosition', 'SetPosition'),
'title' : ('GetTitle', 'SetTitle'),
'style' : ('GetWindowStyleFlag',
'SetWindowStyleFlag'),
'visible' : ('IsShown', 'Show'),
'shown' : ('IsShown', 'Show'),
'toolTip' : ('GetToolTip', 'SetToolTip'),
'sizer' : ('GetSizer', 'SetSizer'),
'validator' : ('GetValidator', 'SetValidator'),
'dropTarget' : ('GetDropTarget', 'SetDropTarget'),
'caret' : ('GetCaret', 'SetCaret'),
'autoLayout' : ('GetAutoLayout', 'SetAutoLayout'),
'constraints' : ('GetConstraints', 'SetConstraints'),
}
···
--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxpython.org Java give you jitters?
http://wxpros.com Relax with wxPython!