⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sec-progressbars.html

📁 gtk 开发手册和参考文档。 包括gtk glib gdk等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
><LI><P> %v - value</P></LI><LI><P> %l - lower range value</P></LI><LI><P> %u - upper range value</P></LI></UL><P>The displaying of this text string can be toggled using:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_progress_set_show_text( GtkProgress *progress,                                 gint         show_text );</PRE></TD></TR></TABLE><P>The <TTCLASS="LITERAL">show_text</TT> argument is a boolean TRUE/FALSE value. Theappearance of the text can be modified further using:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_progress_set_text_alignment( GtkProgress   *progress,                                      gfloat         x_align,                                      gfloat         y_align );</PRE></TD></TR></TABLE><P>The <TTCLASS="LITERAL">x_align</TT> and <TTCLASS="LITERAL">y_align</TT> arguments take values between 0.0and 1.0. Their values indicate the position of the text string withinthe trough. Values of 0.0 for both would place the string in the topleft hand corner; values of 0.5 (the default) centres the text, andvalues of 1.0 places the text in the lower right hand corner.</P><P>The current text setting of a progress object can be retrieved usingthe current or a specified adjustment value using the following twofunctions. The character string returned by these functions should befreed by the application (using the g_free() function). Thesefunctions return the formatted string that would be displayed withinthe trough.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">gchar *gtk_progress_get_current_text( GtkProgress   *progress );gchar *gtk_progress_get_text_from_value( GtkProgress *progress,                                         gfloat       value );</PRE></TD></TR></TABLE><P>There is yet another way to change the range and value of a progressobject using the following function:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_progress_configure( GtkProgress  *progress,                             gfloat        value,                             gfloat        min,                             gfloat        max );</PRE></TD></TR></TABLE><P>This function provides quite a simple interface to the range and valueof a progress object.</P><P>The remaining functions can be used to get and set the current valueof a progess object in various types and formats:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">void gtk_progress_set_percentage( GtkProgress *progress,                                  gfloat       percentage );void gtk_progress_set_value( GtkProgress *progress,                             gfloat       value );gfloat gtk_progress_get_value( GtkProgress *progress );gfloat gtk_progress_get_current_percentage( GtkProgress *progress );gfloat gtk_progress_get_percentage_from_value( GtkProgress *progress,                                               gfloat       value );</PRE></TD></TR></TABLE><P>These functions are pretty self explanatory. The last function usesthe the adjustment of the specified progess object to compute thepercentage value of the given range value.</P><P>Progress Bars are usually used with timeouts or other such functions(see section on <AHREF="ch-timeouts.html">Timeouts, I/O and Idle Functions</A>) to givethe illusion of multitasking. All will employ thegtk_progress_bar_update function in the same manner.</P><P>Here is an example of the progress bar, updated using timeouts. Thiscode also shows you how to reset the Progress Bar.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">/* example-start progressbar progressbar.c */#include &#60;gtk/gtk.h&#62;typedef struct _ProgressData {    GtkWidget *window;    GtkWidget *pbar;    int timer;} ProgressData;/* Update the value of the progress bar so that we get * some movement */gint progress_timeout( gpointer data ){    gfloat new_val;    GtkAdjustment *adj;    /* Calculate the value of the progress bar using the     * value range set in the adjustment object */    new_val = gtk_progress_get_value( GTK_PROGRESS(data) ) + 1;    adj = GTK_PROGRESS (data)-&#62;adjustment;    if (new_val &#62; adj-&#62;upper)      new_val = adj-&#62;lower;    /* Set the new value */    gtk_progress_set_value (GTK_PROGRESS (data), new_val);    /* As this is a timeout function, return TRUE so that it     * continues to get called */    return(TRUE);} /* Callback that toggles the text display within the progress * bar trough */void toggle_show_text( GtkWidget    *widget,		       ProgressData *pdata ){    gtk_progress_set_show_text (GTK_PROGRESS (pdata-&#62;pbar),                                GTK_TOGGLE_BUTTON (widget)-&#62;active);}/* Callback that toggles the activity mode of the progress * bar */void toggle_activity_mode( GtkWidget    *widget,			   ProgressData *pdata ){    gtk_progress_set_activity_mode (GTK_PROGRESS (pdata-&#62;pbar),                                    GTK_TOGGLE_BUTTON (widget)-&#62;active);}/* Callback that toggles the continuous mode of the progress * bar */void set_continuous_mode( GtkWidget    *widget,			  ProgressData *pdata ){    gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR (pdata-&#62;pbar),                                    GTK_PROGRESS_CONTINUOUS);}/* Callback that toggles the discrete mode of the progress * bar */void set_discrete_mode( GtkWidget    *widget,			ProgressData *pdata ){    gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR (pdata-&#62;pbar),                                    GTK_PROGRESS_DISCRETE);} /* Clean up allocated memory and remove the timer */void destroy_progress( GtkWidget     *widget,		       ProgressData *pdata){    gtk_timeout_remove (pdata-&#62;timer);    pdata-&#62;timer = 0;    pdata-&#62;window = NULL;    g_free(pdata);    gtk_main_quit();}int main( int   argc,          char *argv[]){    ProgressData *pdata;    GtkWidget *align;    GtkWidget *separator;    GtkWidget *table;    GtkAdjustment *adj;    GtkWidget *button;    GtkWidget *check;    GtkWidget *vbox;    gtk_init (&#38;argc, &#38;argv);    /* Allocate memory for the data that is passwd to the callbacks */    pdata = g_malloc( sizeof(ProgressData) );      pdata-&#62;window = gtk_window_new (GTK_WINDOW_TOPLEVEL);    gtk_window_set_policy (GTK_WINDOW (pdata-&#62;window), FALSE, FALSE, TRUE);    gtk_signal_connect (GTK_OBJECT (pdata-&#62;window), "destroy",	                GTK_SIGNAL_FUNC (destroy_progress),                        pdata);    gtk_window_set_title (GTK_WINDOW (pdata-&#62;window), "GtkProgressBar");    gtk_container_set_border_width (GTK_CONTAINER (pdata-&#62;window), 0);    vbox = gtk_vbox_new (FALSE, 5);    gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);    gtk_container_add (GTK_CONTAINER (pdata-&#62;window), vbox);    gtk_widget_show(vbox);      /* Create a centering alignment object */    align = gtk_alignment_new (0.5, 0.5, 0, 0);    gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 5);    gtk_widget_show(align);    /* Create a Adjusment object to hold the range of the     * progress bar */    adj = (GtkAdjustment *) gtk_adjustment_new (0, 1, 150, 0, 0, 0);    /* Create the GtkProgressBar using the adjustment */    pdata-&#62;pbar = gtk_progress_bar_new_with_adjustment (adj);    /* Set the format of the string that can be displayed in the     * trough of the progress bar:     * %p - percentage     * %v - value     * %l - lower range value     * %u - upper range value */    gtk_progress_set_format_string (GTK_PROGRESS (pdata-&#62;pbar),	                            "%v from [%l-%u] (=%p%%)");    gtk_container_add (GTK_CONTAINER (align), pdata-&#62;pbar);    gtk_widget_show(pdata-&#62;pbar);    /* Add a timer callback to update the value of the progress bar */    pdata-&#62;timer = gtk_timeout_add (100, progress_timeout, pdata-&#62;pbar);    separator = gtk_hseparator_new ();    gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);    gtk_widget_show(separator);    /* rows, columns, homogeneous */    table = gtk_table_new (2, 3, FALSE);    gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, TRUE, 0);    gtk_widget_show(table);    /* Add a check button to select displaying of the trough text */    check = gtk_check_button_new_with_label ("Show text");    gtk_table_attach (GTK_TABLE (table), check, 0, 1, 0, 1,                      GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,                      5, 5);    gtk_signal_connect (GTK_OBJECT (check), "clicked",                        GTK_SIGNAL_FUNC (toggle_show_text),                        pdata);    gtk_widget_show(check);    /* Add a check button to toggle activity mode */    check = gtk_check_button_new_with_label ("Activity mode");    gtk_table_attach (GTK_TABLE (table), check, 0, 1, 1, 2,                      GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,                      5, 5);    gtk_signal_connect (GTK_OBJECT (check), "clicked",                        GTK_SIGNAL_FUNC (toggle_activity_mode),                        pdata);    gtk_widget_show(check);    separator = gtk_vseparator_new ();    gtk_table_attach (GTK_TABLE (table), separator, 1, 2, 0, 2,                      GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,                      5, 5);    gtk_widget_show(separator);    /* Add a radio button to select continuous display mode */    button = gtk_radio_button_new_with_label (NULL, "Continuous");    gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1,                      GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,                      5, 5);    gtk_signal_connect (GTK_OBJECT (button), "clicked",                        GTK_SIGNAL_FUNC (set_continuous_mode),                        pdata);    gtk_widget_show (button);    /* Add a radio button to select discrete display mode */    button = gtk_radio_button_new_with_label(               gtk_radio_button_group (GTK_RADIO_BUTTON (button)),               "Discrete");    gtk_table_attach (GTK_TABLE (table), button, 2, 3, 1, 2,                      GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,                      5, 5);    gtk_signal_connect (GTK_OBJECT (button), "clicked",                        GTK_SIGNAL_FUNC (set_discrete_mode),                        pdata);    gtk_widget_show (button);    separator = gtk_hseparator_new ();    gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);    gtk_widget_show(separator);    /* Add a button to exit the program */    button = gtk_button_new_with_label ("close");    gtk_signal_connect_object (GTK_OBJECT (button), "clicked",                               (GtkSignalFunc) gtk_widget_destroy,                               GTK_OBJECT (pdata-&#62;window));    gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);    /* This makes it so the button is the default. */    GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);    /* This grabs this button to be the default button. Simply hitting     * the "Enter" key will cause this button to activate. */    gtk_widget_grab_default (button);    gtk_widget_show(button);    gtk_widget_show (pdata-&#62;window);    gtk_main ();        return(0);}/* example-end */</PRE></TD></TR></TABLE></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="sec-thetooltipsobject.html">&#60;&#60;&#60; Previous</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="gtk-tut.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="sec-dialogs.html">Next &#62;&#62;&#62;</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">The Tooltips Object</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ch-miscwidgets.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Dialogs</TD></TR></TABLE></DIV>        </td>    </tr></table>  </td>  </tr></table></body></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -