📄 sec-progressbars.html
字号:
<HTML><HEAD><TITLE>Progress Bars</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.49"><LINKREL="HOME"TITLE="GTK+ 1.2 Tutorial"HREF="gtk-tut.html"><LINKREL="UP"TITLE="Miscellaneous Widgets"HREF="ch-miscwidgets.html"><LINKREL="PREVIOUS"TITLE="The Tooltips Object"HREF="sec-thetooltipsobject.html"><LINKREL="NEXT"TITLE="Dialogs"HREF="sec-dialogs.html"></HEAD></head><body bgcolor="#FFFFFF" marginheight=0 marginwidth=0 width="100%"><table cellspacing=6 border=0 cellpadding=0 width="100%"> <tr> <td bgcolor="#FFFFFF" valign=top nowrap> <centeR><A HREF="/"><img src="/images/gtk-logo-rgb.gif" width=107 height=140 border=0></A> <font face="helvetica,lucidia" color="#000000"><BR><BR><b>GTK+<BR>The GIMP Toolkit</b></center><BR><table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>General</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/">Introduction</A><BR><A HREF="/screenshots/">Screenshots</A><br><A HREF="/download/">Download</A><br><A HREF="/mailinglists.html">Mailing Lists</A><BR><A HREF="/bindings.html">Language Bindings</A><BR><A HREF="http://gtk.themes.org/">Themes</A><BR><A HREF="/bugs.html">Bug Tracker</A><BR></td></tr></table></td></tr></table><BR> <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Documentation</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="/faq/">FAQ</A><br><A HREF="/tutorial/">Tutorial</A><BR><A HREF="/api/">API Reference</A><br><A HREF="/books.html">Published Books</A><BR></td></tr></table></td></tr></table><BR> <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B>Projects</B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.pango.org/">Pango</A><BR><A HREF="http://sources.redhat.com/inti/">Inti</A><BR><A HREF="http://www.gnome.org/">GNOME</A><BR><A HREF="http://user.sgic.fi/~tml/gimp/win32/">GTK+ for Win32</A><br><A HREF="http://people.redhat.com/sopwith/gtkfb/">GtkFB (Framebuffer)</A><br><A HREF="http://www.directfb.org/gtk.xml">GTK+ on DirectFB</A><BR><A HREF="/beos/">GTK+ for BeOS</A></td></tr></table></td></tr></table><BR> <table width=100% cellspacing=0 cellpadding=2 border=0><tr><td bgcolor="#000000"><table width=100% cellspacing=0 cellpadding=4 border=0><tr><td bgcolor="#AAAAEE" nowrap><B><B>Applications</B></B></td></tr><tr><td bgcolor="#FFFFFF" nowrap><A HREF="http://www.gimp.org/">GIMP</A><BR><A HREF="http://www.abiword.org/">Abiword</A><BR><A HREF="http://www.lysator.liu.se/~alla/dia/dia.html">Dia</A><BR><A HREF="http://glade.pn.org/">Glade</A><BR><A HREF="http://www.gnucash.org/">GnuCash</A><BR><A HREF="http://www.gnome.org/projects/gnumeric/">Gnumeric</A><BR><BR><A HREF="http://www.gnome.org/applist/">GNOME Software Map</A><br></td></tr></table></td></tr></table><BR> </td> <td bgcolor="#ffffff" valign=top width="99%"><font face="lucida,helvetica"><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GTK+ 1.2 Tutorial</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="sec-thetooltipsobject.html"><<< Previous</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 9. Miscellaneous Widgets</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="sec-dialogs.html">Next >>></A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="SEC-PROGRESSBARS">9.4. Progress Bars</A></H1><P>Progress bars are used to show the status of an operation. They arepretty easy to use, as you will see with the code below. But firstlets start out with the calls to create a new progress bar.</P><P>There are two ways to create a progress bar, one simple that takesno arguments, and one that takes an Adjustment object as anargument. If the former is used, the progress bar creates its ownadjustment object.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">GtkWidget *gtk_progress_bar_new( void );GtkWidget *gtk_progress_bar_new_with_adjustment( GtkAdjustment *adjustment );</PRE></TD></TR></TABLE><P>The second method has the advantage that we can use the adjustmentobject to specify our own range parameters for the progress bar.</P><P>The adjustment of a progress object can be changed dynamically using:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_progress_set_adjustment( GtkProgress *progress, GtkAdjustment *adjustment );</PRE></TD></TR></TABLE><P>Now that the progress bar has been created we can use it.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_progress_bar_update( GtkProgressBar *pbar, gfloat percentage );</PRE></TD></TR></TABLE><P>The first argument is the progress bar you wish to operate on, and thesecond argument is the amount "completed", meaning the amount theprogress bar has been filled from 0-100%. This is passed to thefunction as a real number ranging from 0 to 1.</P><P>GTK v1.2 has added new functionality to the progress bar that enablesit to display its value in different ways, and to inform the user ofits current value and its range.</P><P>A progress bar may be set to one of a number of orientations using thefunction</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_progress_bar_set_orientation( GtkProgressBar *pbar, GtkProgressBarOrientation orientation );</PRE></TD></TR></TABLE><P>The <TTCLASS="LITERAL">orientation</TT> argument may take one of the followingvalues to indicate the direction in which the progress bar moves:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING"> GTK_PROGRESS_LEFT_TO_RIGHT GTK_PROGRESS_RIGHT_TO_LEFT GTK_PROGRESS_BOTTOM_TO_TOP GTK_PROGRESS_TOP_TO_BOTTOM</PRE></TD></TR></TABLE><P>When used as a measure of how far a process has progressed, theProgressBar can be set to display its value in either a continuousor discrete mode. In continuous mode, the progress bar is updated foreach value. In discrete mode, the progress bar is updated in a numberof discrete blocks. The number of blocks is also configurable.</P><P>The style of a progress bar can be set using the following function.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_progress_bar_set_bar_style( GtkProgressBar *pbar, GtkProgressBarStyle style );</PRE></TD></TR></TABLE><P>The <TTCLASS="LITERAL">style</TT> parameter can take one of two values:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING"> GTK_PROGRESS_CONTINUOUS GTK_PROGRESS_DISCRETE</PRE></TD></TR></TABLE><P>The number of discrete blocks can be set by calling</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_progress_bar_set_discrete_blocks( GtkProgressBar *pbar, guint blocks );</PRE></TD></TR></TABLE><P>As well as indicating the amount of progress that has occured, theprogress bar may be set to just indicate that there is someactivity. This can be useful in situations where progress cannot bemeasured against a value range. Activity mode is not effected by thebar style that is described above, and overrides it. This mode iseither TRUE or FALSE, and is selected by the following function.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_progress_set_activity_mode( GtkProgress *progress, guint activity_mode );</PRE></TD></TR></TABLE><P>The step size of the activity indicator, and the number of blocks areset using the following functions.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_progress_bar_set_activity_step( GtkProgressBar *pbar, guint step );void gtk_progress_bar_set_activity_blocks( GtkProgressBar *pbar, guint blocks );</PRE></TD></TR></TABLE><P>When in continuous mode, the progress bar can also display aconfigurable text string within its trough, using the followingfunction.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_progress_set_format_string( GtkProgress *progress, gchar *format);</PRE></TD></TR></TABLE><P>The <TTCLASS="LITERAL">format</TT> argument is similiar to one that would be used in a C<TTCLASS="LITERAL">printf</TT> statement. The following directives may be used within theformat string:</P><P></P><UL><LI><P> %p - percentage</P></LI
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -