Pseudo-properties

Many Wax controls have a number of methods starting with Get and Set: GetSize/SetSize, GetPosition/SetPosition, GetFont/SetFont, etc. This is one of the areas where you can clearly see the underlying C++: objects have various private attributes that can be set via separate getter and setter methods.

This is not very Pythonic, so in addition to these methods, it is also possible to set these attributes like they were properties. For x.SetFoo(y), you can substitute x.Foo = y, and for print x.GetFoo() you can say print x.Foo. The following constructs are equivalent:

widget.SetSize((100, 100))
widget.Size = (100, 100)

and:

print widget.GetSize()
print widget.Size

How it works

This construct does not use the properties that were introduced in Python 2.2. Rather, it uses __getattr__ and __setattr__ to look up names dynamically. Hence the name pseudo-properties. If a pseudo-property Foo is used, and there isn't an existing attribute with that name, then the mechanism looks if there are methods GetFoo or SetFoo (depending on if we're getting or setting the value). If found, the method is called (otherwise an AttributeError is raised).

Pseudo-properties will work "partially"; if a widget has a method GetThis, but not SetThis, then widget.This will work, but widget.This = 42 will not. They will also work automatically for user-defined methods whose names start with Get and Set.

Note that the names of pseudo-properties start with an uppercase letter. The reason is, that the names used are simply method names without the "Get" or "Set". So, for SetSize, the property name is Size, not size. (This is actually a Good Thing, since it distinguishes the properties from "real" attributes that Wax controls might have, whose names usually start with a lowercase letter.)

Restrictions