Skip to content

Gtk.Range

class — extends Widget, Accessible, AccessibleRange, Buildable, ConstraintTarget, Orientable

Base class for widgets which visualize an adjustment.

Widgets that are derived from GtkRange include Scale and Scrollbar.

Apart from signals for monitoring the parameters of the adjustment, GtkRange provides properties and methods for setting a “fill level” on range widgets. See Range.set_fill_level.

Shortcuts and Gestures

The GtkRange slider is draggable. Holding the <kbd>Shift</kbd> key while dragging, or initiating the drag with a long-press will enable the fine-tuning mode.

Methods

get_adjustment

def get_adjustment(self) -> Adjustment

Get the adjustment which is the “model” object for GtkRange.

get_fill_level

def get_fill_level(self) -> float

Gets the current position of the fill level indicator.

get_flippable

def get_flippable(self) -> bool

Gets whether the GtkRange respects text direction.

See Range.set_flippable.

get_inverted

def get_inverted(self) -> bool

Gets whether the range is inverted.

See Range.set_inverted.

get_range_rect

def get_range_rect(self) -> Gdk.Rectangle

This function returns the area that contains the range’s trough, in coordinates relative to range's origin.

This function is useful mainly for GtkRange subclasses.

get_restrict_to_fill_level

def get_restrict_to_fill_level(self) -> bool

Gets whether the range is restricted to the fill level.

get_round_digits

def get_round_digits(self) -> int

Gets the number of digits to round the value to when it changes.

See Range.change-value.

get_show_fill_level

def get_show_fill_level(self) -> bool

Gets whether the range displays the fill level graphically.

get_slider_range

def get_slider_range(self) -> tuple[int, int]

This function returns sliders range along the long dimension, in widget->window coordinates.

This function is useful mainly for GtkRange subclasses.

get_slider_size_fixed

def get_slider_size_fixed(self) -> bool

This function is useful mainly for GtkRange subclasses.

See Range.set_slider_size_fixed.

get_value

def get_value(self) -> float

Gets the current value of the range.

set_adjustment

def set_adjustment(self, adjustment: Adjustment) -> None

Sets the adjustment to be used as the “model” object for the GtkRange

The adjustment indicates the current range value, the minimum and maximum range values, the step/page increments used for keybindings and scrolling, and the page size.

The page size is normally 0 for GtkScale and nonzero for GtkScrollbar, and indicates the size of the visible area of the widget being scrolled. The page size affects the size of the scrollbar slider.

Parameters:

  • adjustment — a GtkAdjustment

set_fill_level

def set_fill_level(self, fill_level: float) -> None

Set the new position of the fill level indicator.

The “fill level” is probably best described by its most prominent use case, which is an indicator for the amount of pre-buffering in a streaming media player. In that use case, the value of the range would indicate the current play position, and the fill level would be the position up to which the file/stream has been downloaded.

This amount of prebuffering can be displayed on the range’s trough and is themeable separately from the trough. To enable fill level display, use Range.set_show_fill_level. The range defaults to not showing the fill level.

Additionally, it’s possible to restrict the range’s slider position to values which are smaller than the fill level. This is controlled by Range.set_restrict_to_fill_level and is by default enabled.

Parameters:

  • fill_level — the new position of the fill level indicator

set_flippable

def set_flippable(self, flippable: bool) -> None

Sets whether the GtkRange respects text direction.

If a range is flippable, it will switch its direction if it is horizontal and its direction is TextDirection.RTL.

See Widget.get_direction.

Parameters:

  • flippableTrue to make the range flippable

set_increments

def set_increments(self, step: float, page: float) -> None

Sets the step and page sizes for the range.

The step size is used when the user clicks the GtkScrollbar arrows or moves a GtkScale via arrow keys. The page size is used for example when moving via Page Up or Page Down keys.

Parameters:

  • step — step size
  • page — page size

set_inverted

def set_inverted(self, setting: bool) -> None

Sets whether to invert the range.

Ranges normally move from lower to higher values as the slider moves from top to bottom or left to right. Inverted ranges have higher values at the top or on the right rather than on the bottom or left.

Parameters:

  • settingTrue to invert the range

set_range

def set_range(self, min: float, max: float) -> None

Sets the allowable values in the GtkRange.

The range value is clamped to be between min and max. (If the range has a non-zero page size, it is clamped between min and max - page-size.)

Parameters:

  • min — minimum range value
  • max — maximum range value

set_restrict_to_fill_level

def set_restrict_to_fill_level(self, restrict_to_fill_level: bool) -> None

Sets whether the slider is restricted to the fill level.

See Range.set_fill_level for a general description of the fill level concept.

Parameters:

  • restrict_to_fill_level — Whether the fill level restricts slider movement.

set_round_digits

def set_round_digits(self, round_digits: int) -> None

Sets the number of digits to round the value to when it changes.

See Range.change-value.

Parameters:

  • round_digits — the precision in digits, or -1

set_show_fill_level

def set_show_fill_level(self, show_fill_level: bool) -> None

Sets whether a graphical fill level is show on the trough.

See Range.set_fill_level for a general description of the fill level concept.

Parameters:

  • show_fill_level — Whether a fill level indicator graphics is shown.

set_slider_size_fixed

def set_slider_size_fixed(self, size_fixed: bool) -> None

Sets whether the range’s slider has a fixed size, or a size that depends on its adjustment’s page size.

This function is useful mainly for GtkRange subclasses.

Parameters:

  • size_fixedTrue to make the slider size constant

set_value

def set_value(self, value: float) -> None

Sets the current value of the range.

If the value is outside the minimum or maximum range values, it will be clamped to fit inside them. The range emits the Range.value-changed signal if the value changes.

Parameters:

  • value — new value of the range

Virtual methods

do_adjust_bounds

def do_adjust_bounds(self, new_value: float) -> None

do_change_value

def do_change_value(self, scroll: ScrollType | int, new_value: float) -> bool

do_get_range_border

def do_get_range_border(self, border_: Border) -> None

do_move_slider

def do_move_slider(self, scroll: ScrollType | int) -> None

do_value_changed

def do_value_changed(self) -> None

Properties

adjustment

adjustment: Adjustment  # read/write

The adjustment that is controlled by the range.

fill_level

fill_level: float  # read/write

The fill level (e.g. prebuffering of a network stream).

inverted

inverted: bool  # read/write

If True, the direction in which the slider moves is inverted.

restrict_to_fill_level

restrict_to_fill_level: bool  # read/write

Controls whether slider movement is restricted to an upper boundary set by the fill level.

round_digits

round_digits: int  # read/write

The number of digits to round the value to when it changes.

See Range.change-value.

show_fill_level

show_fill_level: bool  # read/write

Controls whether fill level indicator graphics are displayed on the trough.

Signals

adjust-bounds

def on_adjust_bounds(self, value: float) -> None: ...

Emitted before clamping a value, to give the application a chance to adjust the bounds.

change-value

def on_change_value(self, scroll: ScrollType, value: float) -> bool: ...

Emitted when a scroll action is performed on a range.

It allows an application to determine the type of scroll event that occurred and the resultant new value. The application can handle the event itself and return True to prevent further processing. Or, by returning False, it can pass the event to other handlers until the default GTK handler is reached.

The value parameter is unrounded. An application that overrides the ::change-value signal is responsible for clamping the value to the desired number of decimal digits; the default GTK handler clamps the value based on Range.round-digits.

move-slider

def on_move_slider(self, step: ScrollType) -> None: ...

Virtual function that moves the slider.

Used for keybindings.

value-changed

def on_value_changed(self) -> None: ...

Emitted when the range value changes.