[wxPython-users] Getters, Setters, and Python
Werner F. Bruhin
werner.bruhin at free.fr
Mon Nov 20 08:42:17 PST 2006
Hi Dan,
Dan Eloff wrote:
> I didn't notice this documented anywhere, so maybe someone searching
> about this in the future will find this thread. It's more a comment
> than a question.
>
> I notice the wx objects have lots of Get* and Set* methods, this is
> from their C++ heritage. I notice they also seem to have Python
> properites that correspond to them.
They are new in wxPython 2.7, quote from the 2.7.2 changes.html:
Added Python properties for many of the getter/setter methods of wx
classes. In order for the names to be predicatble for somebody already
familiar with wxPython the property names are simply the name of the
getter with the "Get" dropped. For example, wx.Window has a property
named "Size" that maps to GetSize and SetSize. So far there is only one
known name conflict using this naming convention, and that is
wx.KeyEvent.KeyCode, however since KeyCode was formerly a compatibility
alias for GetKeyCode (and has been for a long time) it was decided to
just switch it to a property. If you want to use the method then change
your calls to event.KeyCode() to event.GetKeyCode(), otherwise you can
use it as a property just by dropping the parentheses.
> This is more Pythonic, and is
> good. I don't know how consistent that is, but it seems to work
> wherever I've tried it, so probably it's most everywhere. The two
> strange exceptions are the Size and Point objects. Point has no GetX,
> SetX methods, but has a "x" property that supports both. Size on the
> other hand has GetWidth/SetWidth but has no Width property. It does
> have a width property with a lower-case w.
>
> Probably I should use properties where they are available. Are there
> other exceptions I should be aware of other than the two I mentioned
> above?
If you find any I am sure Robin would want to know about it.
Werner
More information about the wxpython-users
mailing list