# Scale (Python)

Marta Maria Casetti
mmcasetti@gmail.com 2012
Un widget de desprazamento para seleccionar un valor dun rango

# Escala

Desprazar as escalas!

# Código usado para xerar este exemplo

# Métodos útiles para o widget Scale

For an explanation of signals and callback functions, see this page. An example is the `"value-changed"` signal, emitted when the value of the scale changes.

A Gtk.Adjustment is needed to construct the Gtk.Scale. This is the representation of a value with a lower and upper bound, together with step and page increments, and a page size, and it is constructed as `Gtk.Adjustment(value, lower, upper, step_increment, page_increment, page_size)` where the fields are of type `float`; `step_increment` is the increment/decrement that is obtained by using the cursor keys, `page_increment` the one that is obtained clicking on the scale itself. Note that `page_size` is not used in this case, it should be set to `0`.

`get_value()` retrieves the current value of the scale; `set_value(value)` sets it (if the `value`, of type `float`, is outside the minimum or maximum range, it will be clamped to fit inside them). These are methods of the class Gtk.Range.

Use `set_draw_value(False)` to avoid displaying the current value as a string next to the slider.

To highlight the part of the scale between the origin and the current value:

self.h_scale.set_restrict_to_fill_level(False) self.h_scale.set_fill_level(self.h_scale.get_value()) self.h_scale.set_show_fill_level(True)

in the callback function of the "value-changed" signal, so to have the new filling every time the value is changed. These are methods of the class Gtk.Range.

`add_mark(value, position, markup)` adds a mark at the `value` (`float` or `int` if that is the precision of the scale), in `position` (`Gtk.PositionType.LEFT, Gtk.PositionType.RIGHT, Gtk.PositionType.TOP, Gtk.PositionType.BOTTOM`) with text `Null` or `markup` in the Pango Markup Language. To clear marks, `clear_marks()`.

`set_digits(digits)` sets the precision of the scale at `digits` digits.

# API References

Neste exemplo empregaremos o seguinte:

GtkScale

GtkAdjustment

Enumeracións estándar