Chapter 8. Range Widgets

Table of Contents

8.1. Scrollbar Widgets
8.2. Scale Widgets
8.2.1. Creating a Scale Widget
8.2.2. Methods and Signals (well, methods, at least)
8.3. Common Range Methods
8.3.1. Setting the Update Policy
8.3.2. Getting and Setting Adjustments
8.4. Key and Mouse Bindings
8.5. Range Widget Example

The category of range widgets includes the ubiquitous scrollbar widget and the less common "scale" widget. Though these two types of widgets are generally used for different purposes, they are quite similar in function and implementation. All range widgets share a set of common graphic elements, each of which has its own X window and receives events. They all contain a "trough" and a "slider" (what is sometimes called a "thumbwheel" in other GUI environments). Dragging the slider with the pointer moves it back and forth within the trough, while clicking in the trough advances the slider towards the location of the click, either completely, or by a designated amount, depending on which mouse button is used.

As mentioned in Chapter 7, Adjustments above, all range widgets are associated with an Adjustment object, from which they calculate the length of the slider and its position within the trough. When the user manipulates the slider, the range widget will change the value of the adjustment.

8.1. Scrollbar Widgets

These are your standard, run-of-the-mill scrollbars. These should be used only for scrolling some other widget, such as a list, a text box, or a viewport (and it's generally easier to use the scrolled window widget in most cases). For other purposes, you should use scale widgets, as they are friendlier and more featureful.

There are separate types for horizontal and vertical scrollbars. There really isn't much to say about these. You create them with the following methods:

  hscrollbar = gtk.HSscrollbar(adjustment=None)

  vscrollbar = gtk.VSscrollbar(adjustment=None)

and that's about it. The adjustment argument can either be a reference to an existing Adjustment (see Chapter 7, Adjustments), or nothing, in which case one will be created for you. Specifying nothing might be useful in the case, where you wish to pass the newly-created adjustment to the constructor function of some other widget which will configure it for you, such as a text widget.