Common widget operations - the BaseWidget

The BaseWidget is the most basic class of all widgets and contains common attributes and methods, each widget of the ocempui.widgets module has to include. Every widget inherits from it, so that any description and explanation in this section also to the widgets, which are explained later on.

Positioning and sizing

A widget can be set to a specific position on the main screen using the position attribute.

widget.position = 10, 15
        
Using the above code, the topleft corner of the widget will bo positioned at the x-coordinate 10 and the y-coordinate 15 of the main screen, of which 0, 0 denotes the topleft corner.

Note

This will not work as supposed using widgets, that are bound to a Container or Bin widget, which will be explained in one of the following sections.

If you read the current position value of a widget, keep in mind, that it will return a tuple containing the both, x and y, coordinates.

Every widget supports a minimum size, that will be respected by the default drawing methods.

widget.size = 80, 20
        
The minimum size is the guaranteed width and height, the widget should occupy on the screen. It can grow bexond that minimum size, if this is needed to display all of its contents according to its drawing method, but will never be smaller than this value.

The currently used width and height, which can differ from its size can be retrieved using the width and height attributes.

if (widget.width == widget.size[0]) and (widget.height == widget.size[1]):
    print "Widget does not exceed its minimum size."
        

Keyboard support

To allow an easy and logical keyboard navigation, widgets have an index attribute, which influences the navigation order using the keyboard.

widget.index = 3
        
A higher index will cause the widget to receive the input focues earlier. It is highly recommended, that you set this value in your own code to provide the user a better keyboard accessibility.

The input focus mentioned above denotes a state of the widget, in which the user can interact with it using the keyboard only. A Button widget will react upon pressing the space bar with a click while an Entry widget will let the user type text. You can set the input focus of a widget manually with the focus attribute.

widget.focus = True
        
This however will not work with any widget (e.g. layout containers such as the Table). Depedant on the widget the set_focus() method of it will return either True or False, which indicates, that the input focus could be sucessfully set for that widget or not.
frame = VFrame ()
focusok = frame.set_focus (True)
if not focusok:
    print "Focus could not be set."
        

Other features

Widgets can be disabled from user interaction and receiving events, if you set their sensitive attribute to False.

widget.sensitive = False
        
They will be set in a different state then to indicate, that the user cannot interact with them anymore. Of course you can reset the sensitivity at any time.

The renderering system of the ocempgui.widgets module can use different layers, on which widgets are drawn. This is especially useful and often necessary to place widgets above others (e.g. to place a Window widget above another one).

widget.depth = 3
        
The above code causes the widget to be drawn above all widgets, which have a depth value smaller than three, but under any widget, that has a higher depth. You can find an example demonstrating this in the section called “Window”.