Next: Widget Class Declaration Up: Widget Classes and Previous: Widget Classes and

 

Widget Instances

Each widget instance is composed of three integral parts: variables, methods and component widgets.

Variables
Each widget instance is associated with a set of variables. In the example of an instance of the TixArrowButton class, we may use a variable to store the direction to which the arrow is pointing to. We may also use a variable to count how many times the user has pressed the button.

Each variable can be public or private. Public variables may be accessed by the application programmer (usually via configure or cget methods) and their names usually start with a dash (-). They usually are used to represent some user-configurable options of the widget instance. Private variables, on the other hand, cannot be accessed by the application programmer. They are usually used to store information about the widget instance that are of interest only to the widget writer.

All the variables of an instance are stored in a global array (dictionary) that has the same name as the instance. For example, the variables of the instance .up are stored in the global array .up. The public variable -direction, which records the direction to which the arrow is pointing to, is stored in .up(-direction). The private variable count, which counts how many times the user has pressed the button, is stored in .up(count). In comparison, the same variables of the .down instance are stored in .down(-direction) and .down(count).

Methods
To carry out operations on the widget, you define a set of methods. Each method can be declared as public or private. Public methods can be called by the application programmer. For example, if the TixArrowButton class supports the public methods invoke and invert, the application programmer can issue the commands to call these method for the widget instance .up.

.up invert
.up invoke
In contrast, private methods are of interests only to widget writers and cannot be called by application programmers.

Component Widgets
A Tix mega-widget is composed of one or more component widgets. The main part of a mega-widget is called the root widget, which is usually a frame widget that encompasses all other component widgets. The other component widgets are called subwidgets.

The root widget has the same name as the mega-widget itself. In the above example, we have a mega-widget called .up. It has a root widget which is a frame widget and is also called .up. Inside .up we have a button subwidget called .up.button.

Similar to variables and methods, component widgets are also classified into public and private component widgets. Only public widgets may be accessed by the application programmer, via the subwidget method of each widget instance.


http://tix.sourceforge.net