GtkProgressBar
[Display Widgets]


Detailed Description

GtkProgressBar is a widget which indicates progress visually.

gtkprogressbar.png

Fig.6 GtkProgressBar

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

Code Example

 GtkWidget *progress_bar;

 progress_bar = gtk_progress_bar_new ();
 gtk_container_add (GTK_CONTAINER (window), progress_bar);
 gtk_widget_show (progress_bar);

 switch (gtk_progress_bar_get_orientation (GTK_PROGRESS_BAR (progress_bar)
 {
 case GTK_PROGRESS_LEFT_TO_RIGHT:
    gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (progress_bar), 
                                    GTK_PROGRESS_RIGHT_TO_LEFT);
    break;

 case GTK_PROGRESS_RIGHT_TO_LEFT:
    gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (progress_bar), 
                                        GTK_PROGRESS_LEFT_TO_RIGHT);
    break;

 default:
 }


Data Structures

struct  _GtkProgress
 GtkProgress stucture. More...
struct  _GtkProgressClass
 GtkProgress class stucture. More...
struct  _GtkProgressBar
 GtkProgressBar instance stucture. More...
struct  _GtkProgressBarClass
 GtkProgressBar instance Class structure. More...

Enumerations

enum  GtkProgressBarStyle
 GtkProgressBar mode. More...
enum  GtkProgressBarOrientation
 GtkProgressBar direction. More...

Functions

GType gtk_progress_bar_get_type (void) G_GNUC_CONST
 This Fuction returns GType.
GtkWidgetgtk_progress_bar_new (void)
 Creates a new GtkProgressBar.
void gtk_progress_bar_pulse (GtkProgressBar *pbar)
 GtkProgress/GtkProgressBar had serious problems in GTK 1.2.
void gtk_progress_bar_set_text (GtkProgressBar *pbar, const gchar *text)
 Causes the given text to appear superimposed on the progress bar.
void gtk_progress_bar_set_fraction (GtkProgressBar *pbar, gdouble fraction)
 Causes the progress bar to "fill in" the given fraction of the bar.
void gtk_progress_bar_set_pulse_step (GtkProgressBar *pbar, gdouble fraction)
 Sets the fraction of total progress bar length to move the bouncing block for each call to gtk_progress_bar_pulse().
void gtk_progress_bar_set_orientation (GtkProgressBar *pbar, GtkProgressBarOrientation orientation)
 Causes the progress bar to switch to a different orientation (left-to-right, right-to-left, top-to-bottom, or bottom-to-top).
G_CONST_RETURN gchar * gtk_progress_bar_get_text (GtkProgressBar *pbar)
 Retrieves the text displayed superimposed on the progress bar, if any, otherwise NULL.
gdouble gtk_progress_bar_get_fraction (GtkProgressBar *pbar)
 Returns the current fraction of the task that's been completed.
gdouble gtk_progress_bar_get_pulse_step (GtkProgressBar *pbar)
 Retrieves the pulse step set with gtk_progress_bar_set_pulse_step().
GtkProgressBarOrientation gtk_progress_bar_get_orientation (GtkProgressBar *pbar)
 Retrieves the current progress bar orientation.
void gtk_progress_bar_set_ellipsize (GtkProgressBar *pbar, PangoEllipsizeMode mode)
 Sets the mode used to ellipsize (add an ellipsis: "...") the text if there is not enough space to render the entire string.
PangoEllipsizeMode gtk_progress_bar_get_ellipsize (GtkProgressBar *pbar)
 Returns the ellipsizing position of the progressbar.

Enumeration Type Documentation

GtkProgressBar direction.

GtkProgressBar mode.


Function Documentation

PangoEllipsizeMode gtk_progress_bar_get_ellipsize ( GtkProgressBar pbar  ) 

Returns the ellipsizing position of the progressbar.

See gtk_progress_bar_set_ellipsize().

Parameters:
pbar [in] a GtkProgressBar
Returns:
PangoEllipsizeMode

gdouble gtk_progress_bar_get_fraction ( GtkProgressBar pbar  ) 

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

Parameters:
pbar [in] a GtkProgressBar
Returns:
a fraction from 0.0 to 1.0

GtkProgressBarOrientation gtk_progress_bar_get_orientation ( GtkProgressBar pbar  ) 

Retrieves the current progress bar orientation.

Parameters:
pbar [in] a GtkProgressBar
Returns:
orientation of the progress bar

gdouble gtk_progress_bar_get_pulse_step ( GtkProgressBar pbar  ) 

Retrieves the pulse step set with gtk_progress_bar_set_pulse_step().

Parameters:
pbar [in] a GtkProgressBar
Returns:
a fraction from 0.0 to 1.0

G_CONST_RETURN gchar* gtk_progress_bar_get_text ( GtkProgressBar pbar  ) 

Retrieves the text displayed superimposed on the progress bar, if any, otherwise NULL.

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.

Parameters:
pbar [in] a GtkProgressBar
Returns:
reference to the text, not a copy of it.
Remarks:
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.

GType gtk_progress_bar_get_type ( void   ) 

This Fuction returns GType.

Returns:
GType Type

GtkWidget* gtk_progress_bar_new ( void   ) 

Creates a new GtkProgressBar.

Returns:
a new GtkProgressBar

void gtk_progress_bar_pulse ( GtkProgressBar pbar  ) 

GtkProgress/GtkProgressBar had serious problems in GTK 1.2.

  • Only 3 or 4 functions are really needed for 95% of progress interfaces; GtkProgress[Bar] had about 25 functions, and didn't even include these 3 or 4.
  • In activity mode, the API involves setting the adjustment to any random value, just to have the side effect of calling the progress bar update function - the adjustment is totally ignored in activity mode
  • You set the activity step as a pixel value, which means to set the activity step you basically need to connect to size_allocate
  • There are ctree_set_expander_style()-functions, to randomly change look-and-feel for no good reason
  • The split between GtkProgress and GtkProgressBar makes no sense to me whatsoever.

This was a big wart on GTK and made people waste lots of time, both learning and using the interface.

So, I have added what I feel is the correct API, and marked all the rest deprecated. However, the changes are 100% backward-compatible and should break no existing code.

The following 9 functions are the new programming interface. 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()).

Parameters:
pbar [in] a GtkProgressBar
Returns:
void

void gtk_progress_bar_set_ellipsize ( GtkProgressBar pbar,
PangoEllipsizeMode  mode 
)

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

Parameters:
pbar [in] a GtkProgressBar
mode [in] a PangoEllipsizeMode
Returns:
void

void gtk_progress_bar_set_fraction ( GtkProgressBar pbar,
gdouble  fraction 
)

Causes the progress bar to "fill in" the given fraction of the bar.

Parameters:
pbar [in] a GtkProgressBar
fraction [in] fraction of the task that's been completed. fraction should be between 0.0 and 1.0, inclusive.
Returns:
void

void gtk_progress_bar_set_orientation ( GtkProgressBar pbar,
GtkProgressBarOrientation  orientation 
)

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

Parameters:
pbar [in] a GtkProgressBar
orientation [in] orientation of the progress bar
Returns:
void

void gtk_progress_bar_set_pulse_step ( GtkProgressBar pbar,
gdouble  fraction 
)

Sets the fraction of total progress bar length to move the bouncing block for each call to gtk_progress_bar_pulse().

Parameters:
pbar [in] a GtkProgressBar
fraction [in] fraction between 0.0 and 1.0
Returns:
void

void gtk_progress_bar_set_text ( GtkProgressBar pbar,
const gchar *  text 
)

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

Parameters:
pbar [in] a GtkProgressBar
text [in] a UTF-8 string, or NULL
Returns:
void


Generated on Mon Mar 31 01:01:00 2008 by  doxygen 1.5.4