Widget
This class encapsulates a ../PicoGUI widget. It allows you to write object-oriented code.
Instantiation
You can instantiate a widget by the normal means. The constructor accepts two arguments, server (a Server object) and handle (the ../PicoGUI handle for the widget in the server).
However, this isn't the recommended way of creating
widgets. Instead, you can call the addWidget()
method of an
existing widget object, giving only the widget type string as
argument; this method will create the new widget and attach it to
the parent. Check HelloWorldRecipe for an example.
(Of course, that creates a chicken-and-egg problem, as you need a
widget to create a widget; but for that purpose, the Application
object is also a widget and has an addWidget()
method.)
Optionally, you can give an additional argument to addWidget()
, to
be given to attachwidget
. This can be "after"
, "inside"
, and
"before"
. It defaults to "after"
, but this default is stored in
the editable default_relationship
attribute. The Application
class sets this to "inside"
, as you can't attach widgets "after"
an application.
Low-level hacking
The world is not a perfect place, and you may one day need to do
low-level stuff to your widget. To do that, you can get the Server
object and the widget's handle from the server
and handle
attributes. Please, treat this attributes as read-only or things
will break.
Property handling
Finally, if you try to get or set an attribute with the same name as a property constant (seel the Server documentation), case-insensitive, the widget object will get or set the corresponding widget property on the server. WishList: results from getting properties are untranslated and aren't always valid input for setting the same property again. This should be fixed, but requires some intelligence in property handling that wasn't yet written (or designed). See PropertiesModule?.
Examples
See CodingRecipes - all of them use Widget objects.