Table of Contents
GTK has various widgets that can be visually adjusted by the user using the mouse or the keyboard, such as the range widgets, described in the Range Widgets section. There are also a few widgets that display some adjustable portion of a larger area of data, such as the text widget and the viewport widget.
Obviously, an application needs to be able to react to changes the user makes in range widgets. One way to do this would be to have each widget emit its own type of signal when its adjustment changes, and either pass the new value to the signal handler, or require it to look inside the widget's data structure in order to ascertain the value. But you may also want to connect the adjustments of several widgets together, so that adjusting one adjusts the others. The most obvious example of this is connecting a scrollbar to a panning viewport or a scrolling text area. If each widget has its own way of setting or getting the adjustment value, then the programmer may have to write their own signal handlers to translate between the output of one widget's signal and the "input" of another's adjustment setting method.
GTK solves this problem using the
Adjustment object, which is not a widget but a way
for widgets to store and pass adjustment information in an abstract and
flexible form. The most obvious use of
to store the configuration parameters and values of range widgets, such as
scrollbars and scale controls. However, since
Adjustments are derived from
Object, they have some special powers beyond those of
normal data structures. Most importantly, they can emit signals, just like
widgets, and these signals can be used not only to allow your program to
react to user input on adjustable widgets, but also to propagate adjustment
values transparently between adjustable widgets.
You will see how adjustments fit in when you see the other widgets that incorporate them: Progress Bars, Viewports, Scrolled Windows, and others.
Many of the widgets which use adjustment objects do so automatically, but some cases will be shown in later examples where you may need to create one yourself. You create an adjustment using:
adjustment = gtk.Adjustment(
value argument is the initial value
you want to give to the
corresponding to the topmost or leftmost position of an adjustable
lower argument specifies the lowest value
adjustment can hold. The
step_incr argument specifies the "smaller" of the two
increments by which the user can change the value, while the
page_incr is the "larger" one. The
page_size argument usually corresponds somehow to the
visible area of a panning widget. The
is used to represent the bottom most or right most coordinate in a panning
widget's child. Therefore it is not always the largest number that
value can take, since the
page_size of such widgets is usually non-zero.