Gtk.LevelBar


Gtk.LevelBar — A bar that can used as a level indicator

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.LevelBar

Functions:


Signals:

  • “offset-changed” (self, name, user_data)

Description:

The Gtk.LevelBar is a bar 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.

Use Gtk.LevelBar::set_value() to set the current value, and Gtk.LevelBar::add_offset_value() to set the value offsets at which the bar will be considered in a different state. GTK will add two offsets by default on the level bar: #GTK_LEVEL_BAR_OFFSET_LOW and #GTK_LEVEL_BAR_OFFSET_HIGH, with values 0.25 and 0.75 respectively.

The default interval of values is between zero and one, but it’s possible to modify the interval using Gtk.LevelBar::set_min_value() and 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_LEVEL_BAR_MODE_DISCRETE is used, the bar level is rendered as a finite and 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.


Function Details:

new()

new () -> Gtk.Widget

Creates a new Gtk.LevelBar.

  • Returns: a Gtk.LevelBar.

  • Since: 3.6


new_for_interval()

new_for_interval (min_value:float, max_value:float) -> Gtk.Widget

Utility constructor that creates a new Gtk.LevelBar for the specifiedinterval.

  • Returns: a Gtk.LevelBar

  • Since: 3.6


set_mode()

set_mode (self, mode:Gtk.LevelBarMode)

Sets the value of the “mode” property.

  • Since: 3.6

get_mode()

get_mode (self) -> Gtk.LevelBarMode

Returns the value of the “mode” property.

  • Returns: a Gtk.LevelBarMode

  • Since: 3.6


set_value()

set_value (self, value:float)

Sets the value of the “value” property.

  • Since: 3.6

get_value()

get_value (self) -> float

Returns the value of the “value” property.

  • Returns: a value in the interval between“min-value” and “max-value”

  • Since: 3.6


set_min_value()

set_min_value (self, value:float)

Sets the value of the “min-value” property.

  • Since: 3.6

get_min_value()

get_min_value (self) -> float

Returns the value of the “min-value” property.

  • Returns: a positive value

  • Since: 3.6


set_max_value()

set_max_value (self, value:float)

Sets the value of the “max-value” property.

  • Since: 3.6

get_max_value()

get_max_value (self) -> float

Returns the value of the “max-value” property.

  • Returns: a positive value

  • Since: 3.6


set_inverted()

set_inverted (self, inverted:bool)

Sets the value of the “inverted” property.

  • Since: 3.8

get_inverted()

get_inverted (self) -> bool

Return the value of the “inverted” property.

  • Returns: True if the level bar is inverted

  • Since: 3.8


add_offset_value()

add_offset_value (self, name:str, value:float)

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 valueand “max-value” in case the offset is the last one on the bar)a style class named level-``name will be appliedwhen rendering the level bar fill.If another offset marker named name exists, its value will bereplaced by value.

  • Since: 3.6

remove_offset_value()

remove_offset_value (self, name:str=None)

Removes an offset marker previously added withGtk.LevelBar:add_offset_value().

  • Since: 3.6

get_offset_value()

get_offset_value (self, name:str=None) -> bool, value:float

Fetches the value specified for the offset marker name in self,returning True in case an offset named name was found.

  • Returns: True if the specified offset is found

  • Since: 3.6


Example:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import random

class LevelBar(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_default_size(150, -1)
        self.connect("destroy", Gtk.main_quit)

        levelbar = Gtk.LevelBar()
        levelbar.set_min_value(0)
        levelbar.set_max_value(10)
        levelbar.set_value(random.randint(0, 10))
        self.add(levelbar)

window = LevelBar()
window.show_all()

Gtk.main()

results matching ""

    No results matching ""