GTK+ The GIMP Toolkit
|
9.4. Progress BarsProgress bars are used to show the status of an operation. They are pretty easy to use, as you will see with the code below. But first lets start out with the calls to create a new progress bar. There are two ways to create a progress bar, one simple that takes no arguments, and one that takes an Adjustment object as an argument. If the former is used, the progress bar creates its own adjustment object.
The second method has the advantage that we can use the adjustment object to specify our own range parameters for the progress bar. The adjustment of a progress object can be changed dynamically using:
Now that the progress bar has been created we can use it.
The first argument is the progress bar you wish to operate on, and the second argument is the amount "completed", meaning the amount the progress bar has been filled from 0-100%. This is passed to the function as a real number ranging from 0 to 1. GTK v1.2 has added new functionality to the progress bar that enables it to display its value in different ways, and to inform the user of its current value and its range. A progress bar may be set to one of a number of orientations using the function
The orientation argument may take one of the following values to indicate the direction in which the progress bar moves:
When used as a measure of how far a process has progressed, the ProgressBar can be set to display its value in either a continuous or discrete mode. In continuous mode, the progress bar is updated for each value. In discrete mode, the progress bar is updated in a number of discrete blocks. The number of blocks is also configurable. The style of a progress bar can be set using the following function.
The style parameter can take one of two values:
The number of discrete blocks can be set by calling
As well as indicating the amount of progress that has occured, the progress bar may be set to just indicate that there is some activity. This can be useful in situations where progress cannot be measured against a value range. Activity mode is not effected by the bar style that is described above, and overrides it. This mode is either TRUE or FALSE, and is selected by the following function.
The step size of the activity indicator, and the number of blocks are set using the following functions.
When in continuous mode, the progress bar can also display a configurable text string within its trough, using the following function.
The format argument is similiar to one that would be used in a C printf statement. The following directives may be used within the format string:
The displaying of this text string can be toggled using:
The show_text argument is a boolean TRUE/FALSE value. The appearance of the text can be modified further using:
The x_align and y_align arguments take values between 0.0 and 1.0. Their values indicate the position of the text string within the trough. Values of 0.0 for both would place the string in the top left hand corner; values of 0.5 (the default) centres the text, and values of 1.0 places the text in the lower right hand corner. The current text setting of a progress object can be retrieved using the current or a specified adjustment value using the following two functions. The character string returned by these functions should be freed by the application (using the g_free() function). These functions return the formatted string that would be displayed within the trough.
There is yet another way to change the range and value of a progress object using the following function:
This function provides quite a simple interface to the range and value of a progress object. The remaining functions can be used to get and set the current value of a progess object in various types and formats:
These functions are pretty self explanatory. The last function uses the the adjustment of the specified progess object to compute the percentage value of the given range value. Progress Bars are usually used with timeouts or other such functions (see section on Timeouts, I/O and Idle Functions) to give the illusion of multitasking. All will employ the gtk_progress_bar_update function in the same manner. Here is an example of the progress bar, updated using timeouts. This code also shows you how to reset the Progress Bar.
|
|||||||||||||||||||||||||||||||||||||||||