Next: , Previous: GtkLabel, Up: Top


12 GtkProgressBar

A widget which indicates progress visually

12.1 Overview

The <gtk-progress-bar> is typically used to display the progress of a long running operation. It provides a visual clue that processing is underway. The <gtk-progress-bar> 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-progress-bar> 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-progress-bar-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-progress-bar> 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-progress-bar-pulse perodically to update the progress bar.

There is quite a bit of flexibility provided to control the appearance of the <gtk-progress-bar>. 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.

The <gtk-progress-bar>/<gtk-progress> API in GTK 1.2 was bloated, needlessly complex and hard to use properly. Therefore <gtk-progress> has been deprecated completely and the <gtk-progress-bar> API has been reduced to the following 10 functions: gtk-progress-bar-new, gtk-progress-bar-pulse, gtk-progress-bar-set-text, gtk-progress-bar-set-fraction, gtk-progress-bar-set-pulse-step, gtk-progress-bar-set-orientation, gtk-progress-bar-get-text, gtk-progress-bar-get-fraction, gtk-progress-bar-get-pulse-step, gtk-progress-bar-get-orientation. These have been grouped at the beginning of this section, followed by a large chunk of deprecated 1.2 compatibility functions.

12.2 Usage

— Class: <gtk-progress-bar>

Derives from <gtk-progress>.

This class defines the following slots:

fraction
The fraction of total work that has been completed
pulse-step
The fraction of total progress to move the bouncing block when pulsed
orientation
Orientation and growth direction of the progress bar
text
Text to be displayed in the progress bar
ellipsize
The preferred place to ellipsize the string, if the progress bar does not have enough room to display the entire string, if at all.
adjustment
The GtkAdjustment connected to the progress bar (Deprecated)
bar-style
Specifies the visual style of the bar in percentage mode (Deprecated)
activity-step
The increment used for each iteration in activity mode (Deprecated)
activity-blocks
The number of blocks which can fit in the progress bar area in activity mode (Deprecated)
discrete-blocks
The number of discrete blocks in a progress bar (when shown in the discrete style)
— Function: gtk-progress-bar-new ⇒  (ret <gtk-widget>)

Creates a new <gtk-progress-bar>.

ret
a <gtk-progress-bar>.
— Function: gtk-progress-bar-pulse (self <gtk-progress-bar>)
— Method: pulse

Indicates that some progress is made, but you don't know how much. Causes the progress bar to enter "activity mode," where a block bounces back and forth. Each call to gtk-progress-bar-pulse causes the block to move by a little bit (the amount of movement per pulse is determined by gtk-progress-bar-set-pulse-step).

pbar
a <gtk-progress-bar>
— Function: gtk-progress-bar-set-text (self <gtk-progress-bar>) (text mchars)
— Method: set-text

Causes the given text to appear superimposed on the progress bar.

pbar
a <gtk-progress-bar>
text
a UTF-8 string, or ‘#f
— Function: gtk-progress-bar-set-fraction (self <gtk-progress-bar>) (fraction double)
— Method: set-fraction

Causes the progress bar to "fill in" the given fraction of the bar. The fraction should be between 0.0 and 1.0, inclusive.

pbar
a <gtk-progress-bar>
fraction
fraction of the task that's been completed
— Function: gtk-progress-bar-set-pulse-step (self <gtk-progress-bar>) (fraction double)
— Method: set-pulse-step

Sets the fraction of total progress bar length to move the bouncing block for each call to gtk-progress-bar-pulse.

pbar
a <gtk-progress-bar>
fraction
fraction between 0.0 and 1.0
— Function: gtk-progress-bar-set-orientation (self <gtk-progress-bar>) (orientation <gtk-progress-bar-orientation>)
— Method: set-orientation

Causes the progress bar to switch to a different orientation (left-to-right, right-to-left, top-to-bottom, or bottom-to-top).

pbar
a <gtk-progress-bar>
orientation
orientation of the progress bar
— Function: gtk-progress-bar-set-ellipsize (self <gtk-progress-bar>) (mode <pango-ellipsize-mode>)
— Method: set-ellipsize

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

pbar
a <gtk-progress-bar>
mode
a <pango-ellipsize-mode>

Since 2.6

— Function: gtk-progress-bar-get-text (self <gtk-progress-bar>) ⇒  (ret mchars)
— Method: get-text

Retrieves the text displayed superimposed on the progress bar, if any, otherwise ‘#f’. The return value is a reference to the text, not a copy of it, so will become invalid if you change the text in the progress bar.

pbar
a <gtk-progress-bar>
ret
text, or ‘#f’; this string is owned by the widget and should not be modified or freed.
— Function: gtk-progress-bar-get-fraction (self <gtk-progress-bar>) ⇒  (ret double)
— Method: get-fraction

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

pbar
a <gtk-progress-bar>
ret
a fraction from 0.0 to 1.0
— Function: gtk-progress-bar-get-pulse-step (self <gtk-progress-bar>) ⇒  (ret double)
— Method: get-pulse-step

Retrieves the pulse step set with gtk-progress-bar-set-pulse-step

pbar
a <gtk-progress-bar>
ret
a fraction from 0.0 to 1.0
— Function: gtk-progress-bar-get-ellipsize (self <gtk-progress-bar>) ⇒  (ret <pango-ellipsize-mode>)
— Method: get-ellipsize

Returns the ellipsizing position of the progressbar. See gtk-progress-bar-set-ellipsize.

pbar
a <gtk-progress-bar>
ret
<pango-ellipsize-mode>

Since 2.6