Gtk.ProgressBar


Gtk.ProgressBar — A widget which indicates progress visually

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.ProgressBar

Functions:

Description:

The Gtk.ProgressBar is typically used to display the progress of a long running operation. It provides a visual clue that processing is underway.

The Gtk.ProgressBar can be used in two different modes: percentage mode and activity mode.

When an application can determine how much work needs to take place (e.g. read a fixed number of bytes from a file) and can monitor its progress, it can use the Gtk.ProgressBar in percentage mode and the user sees a growing bar indicating the percentage of the work that has been completed. In this mode, the application is required to call Gtk.ProgressBar::set_fraction() periodically to update the progress bar.

When an application has no accurate way of knowing the amount of work to do, it can use the Gtk.ProgressBar in activity mode, which shows activity by a block moving back and forth within the progress area. In this mode, the application is required to call Gtk.ProgressBar::pulse() periodically to update the progress bar.

There is quite a bit of flexibility provided to control the appearance of the Gtk.ProgressBar. Functions are provided to control the orientation of the bar, optional text can be displayed along with the bar, and the step size used in activity mode can be set.


Function Details:

new()

new () -> Gtk.Widget

Creates a new Gtk.ProgressBar.

  • Returns: a Gtk.ProgressBar.

pulse()

pulse (self)

Indicates that some progress has been made, but you don’t know how much.Causes the progress bar to enter “activity mode,” where a blockbounces back and forth. Each call to Gtk.ProgressBar:pulse()causes the block to move by a little bit (the amount of movementper pulse is determined by Gtk.ProgressBar:set_pulse_step()).


set_fraction()

set_fraction (self, fraction:float)

Causes the progress bar to “fill in” the given fractionof the bar. The fraction should be between 0.0 and 1.0,inclusive.


get_fraction()

get_fraction (self) -> float

Returns the current fraction of the task that’s been completed.

  • Returns: a fraction from 0.0 to 1.0

set_inverted()

set_inverted (self, inverted:bool)

Progress bars normally grow from top to bottom or left to right.Inverted progress bars grow in the opposite direction.


get_inverted()

get_inverted (self) -> bool

Gets the value set by Gtk.ProgressBar:set_inverted().

  • Returns: True if the progress bar is inverted

set_show_text()

set_show_text (self, show_text:bool)

Sets whether the progress bar will show text next to the bar.The shown text is either the value of the “text”property or, if that is None, the “fraction” value,as a percentage. To make a progress bar that is styled and sized suitably for containingtext (even if the actual text is blank), set “show-text” toTrue and “text” to the empty string (not None).

  • Since: 3.0

get_show_text()

get_show_text (self) -> bool

Gets the value of the “show-text” property.See Gtk.ProgressBar:set_show_text().

  • Returns: True if text is shown in the progress bar

  • Since: 3.0


set_text()

set_text (self, text:str=None)

Causes the given text to appear next to the progress bar. If text is None and “show-text” is True, the currentvalue of “fraction” will be displayed as a percentage. If text is non-None and “show-text” is True, the textwill be displayed. In this case, it will not display the progresspercentage. If text is the empty string, the progress bar will stillbe styled and sized suitably for containing text, as long as“show-text” is True.


get_text()

get_text (self) -> str

Retrieves the text that is displayed with the progress bar,if any, otherwise None. The return value is a referenceto the text, not a copy of it, so will become invalidif you change the text in the progress bar.

  • Returns: text, or None; this string is owned by the widgetand should not be modified or freed.

set_ellipsize()

set_ellipsize (self, mode:Pango.EllipsizeMode)

Sets the mode used to ellipsize (add an ellipsis: "...") thetext if there is not enough space to render the entire string.

  • Since: 2.6

get_ellipsize()

get_ellipsize (self) -> Pango.EllipsizeMode

Returns the ellipsizing position of the progress bar.See Gtk.ProgressBar:set_ellipsize().

  • Returns: PangoEllipsizeMode

  • Since: 2.6


set_pulse_step()

set_pulse_step (self, fraction:float)

Sets the fraction of total progress bar length to move thebouncing block for each call to Gtk.ProgressBar:pulse().


get_pulse_step()

get_pulse_step (self) -> float

Retrieves the pulse step set with Gtk.ProgressBar:set_pulse_step().

  • Returns: a fraction from 0.0 to 1.0

Example:

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

class ProgressBar(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.connect("destroy", Gtk.main_quit)

        self.progressbar = Gtk.ProgressBar()
        self.progressbar.set_show_text(True)
        self.add(self.progressbar)

        GObject.timeout_add(500, self.update_progressbar)

    def update_progressbar(self):
        fraction = self.progressbar.get_fraction() + 0.1

        if fraction <= 1.0:
            self.progressbar.set_fraction(fraction)
        else:
            self.progressbar.set_fraction(0.0)

        return True

window = ProgressBar()
window.show_all()

Gtk.main()

results matching ""

    No results matching ""