Gtk.LevelBar¶
Example¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1), Gtk.Orientable (2)
- Structs:
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Emitted when an offset specified on the bar changes value. |
Fields¶
- Inherited:
Class Details¶
- class Gtk.LevelBar(**kwargs)¶
- Bases:
- Abstract:
No
GtkLevelBar
is a widget that can be used as a level indicator.Typical use cases are displaying the strength of a password, or showing the charge level of a battery.
An example
Gtk.LevelBar
Use [method`Gtk`.LevelBar.set_value] to set the current value, and [method`Gtk`.LevelBar.add_offset_value] to set the value offsets at which the bar will be considered in a different state. GTK will add a few offsets by default on the level bar:
Gtk.LEVEL_BAR_OFFSET_LOW
,Gtk.LEVEL_BAR_OFFSET_HIGH
andGtk.LEVEL_BAR_OFFSET_FULL
, with values 0.25, 0.75 and 1.0 respectively.Note that it is your responsibility to update preexisting offsets when changing the minimum or maximum value. GTK will simply clamp them to the new range.
- Adding a custom offset on the bar
```c static
Gtk.Widget
* create_level_bar (void) {Gtk.Widget
*widget;Gtk.LevelBar
*bar;widget =
Gtk.LevelBar.new
(); bar = GTK_LEVEL_BAR (widget);// This changes the value of the default low offset
Gtk.LevelBar.add_offset_value
(bar,Gtk.LEVEL_BAR_OFFSET_LOW
, 0.10);// This adds a new offset to the bar; the application will // be able to change its color CSS like this: // // levelbar block.my-offset { // background-color: magenta; // border-style: solid; // border-color: black; // border-width: 1px; // }
Gtk.LevelBar.add_offset_value
(bar, “my-offset”, 0.60);return widget; } ```
The default interval of values is between zero and one, but it’s possible to modify the interval using [method`Gtk`.LevelBar.set_min_value] and [method`Gtk`.LevelBar.set_max_value]. The value will be always drawn in proportion to the admissible interval, i.e. a value of 15 with a specified interval between 10 and 20 is equivalent to a value of 0.5 with an interval between 0 and 1. When
Gtk.LevelBarMode.DISCRETE
is used, the bar level is rendered as a finite number of separated blocks instead of a single one. The number of blocks that will be rendered is equal to the number of units specified by the admissible interval.For instance, to build a bar rendered with five blocks, it’s sufficient to set the minimum value to 0 and the maximum value to 5 after changing the indicator mode to discrete.
The
GtkLevelBar
implementation of theGtkBuildable
interface supports a custom<offsets>
element, which can contain any number of<offset>
elements, each of which must have “name” and “value” attributes.- CSS nodes
`` levelbar[.discrete] ╰── trough
├── block.filled.level-name ┊ ├── block.empty ┊
GtkLevelBar
has a main CSS node with name levelbar and one of the style classes .discrete or .continuous and a subnode with name trough. Below the trough node are a number of nodes with name block and style class .filled or .empty. In continuous mode, there is exactly one node of each, in discrete mode, the number of filled and unfilled nodes corresponds to blocks that are drawn. The block.filled nodes also get a style class .level-name corresponding to the level for the current value.In horizontal orientation, the nodes are always arranged from left to right, regardless of text direction.
- Accessibility
GtkLevelBar
uses theGtk.AccessibleRole.METER
role.- classmethod new_for_interval(min_value, max_value)[source]¶
- Parameters:
- Returns:
a
GtkLevelBar
- Return type:
Creates a new
GtkLevelBar
for the specified interval.
- add_offset_value(name, value)[source]¶
-
Adds a new offset marker on self at the position specified by value.
When the bar value is in the interval topped by value (or between value and [property`Gtk`.LevelBar:max-value] in case the offset is the last one on the bar) a style class named
level-
name will be applied when rendering the level bar fill.If another offset marker named name exists, its value will be replaced by value.
- get_max_value()[source]¶
- Returns:
a positive value
- Return type:
Returns the
max-value
of theGtkLevelBar
.
- get_min_value()[source]¶
- Returns:
a positive value
- Return type:
Returns the
min-value
of theGtkLevelBar
.
- get_offset_value(name)[source]¶
- Parameters:
- Returns:
True
if the specified offset is found- value:
location where to store the value
- Return type:
Fetches the value specified for the offset marker name in self.
- get_value()[source]¶
- Returns:
a value in the interval between [property`Gtk`.LevelBar:min-value] and [property`Gtk`.LevelBar:max-value]
- Return type:
Returns the
value
of theGtkLevelBar
.
- remove_offset_value(name)[source]¶
-
Removes an offset marker from a
GtkLevelBar
.The marker must have been previously added with [method`Gtk`.LevelBar.add_offset_value].
- set_max_value(value)[source]¶
- Parameters:
value (
float
) – a positive value
Sets the
max-value
of theGtkLevelBar
.You probably want to update preexisting level offsets after calling this function.
- set_min_value(value)[source]¶
- Parameters:
value (
float
) – a positive value
Sets the
min-value
of theGtkLevelBar
.You probably want to update preexisting level offsets after calling this function.
- set_mode(mode)[source]¶
- Parameters:
mode (
Gtk.LevelBarMode
) – aGtkLevelBarMode
Sets the
mode
of theGtkLevelBar
.
Signal Details¶
- Gtk.LevelBar.signals.offset_changed(level_bar, name)¶
- Signal Name:
offset-changed
- Flags:
- Parameters:
level_bar (
Gtk.LevelBar
) – The object which received the signalname (
str
) – the name of the offset that changed value
Emitted when an offset specified on the bar changes value.
This typically is the result of a [method`Gtk`.LevelBar.add_offset_value] call.
The signal supports detailed connections; you can connect to the detailed signal “changed::x” in order to only receive callbacks when the value of offset “x” changes.
Property Details¶
- Gtk.LevelBar.props.inverted¶
- Name:
inverted
- Type:
- Default Value:
- Flags:
Whether the
GtkLeveBar
is inverted.Level bars normally grow from top to bottom or left to right. Inverted level bars grow in the opposite direction.
- Gtk.LevelBar.props.max_value¶
- Name:
max-value
- Type:
- Default Value:
1.0
- Flags:
Determines the maximum value of the interval that can be displayed by the bar.
- Gtk.LevelBar.props.min_value¶
- Name:
min-value
- Type:
- Default Value:
0.0
- Flags:
Determines the minimum value of the interval that can be displayed by the bar.
- Gtk.LevelBar.props.mode¶
- Name:
mode
- Type:
- Default Value:
- Flags:
Determines the way
GtkLevelBar
interprets the value properties to draw the level fill area.Specifically, when the value is
Gtk.LevelBarMode.CONTINUOUS
,GtkLevelBar
will draw a single block representing the current value in that area; when the value isGtk.LevelBarMode.DISCRETE
, the widget will draw a succession of separate blocks filling the draw area, with the number of blocks being equal to the units separating the integral roundings of [property`Gtk`.LevelBar:min-value] and [property`Gtk`.LevelBar:max-value].
- Gtk.LevelBar.props.value¶
- Name:
value
- Type:
- Default Value:
0.0
- Flags:
Determines the currently filled value of the level bar.