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

📄 gtk_tut-9.html

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 HTML
📖 第 1 页 / 共 5 页
字号:
...tooltips = gtk_tooltips_new ();button = gtk_button_new_with_label ("button 1");...gtk_tooltips_set_tip (tooltips, button, "This is button 1", NULL);</PRE></CODE></BLOCKQUOTE><P>There are other calls that can be used with tooltips. I will just listthem with a brief description of what they do.<P><BLOCKQUOTE><CODE><PRE>void gtk_tooltips_enable( GtkTooltips *tooltips );</PRE></CODE></BLOCKQUOTE><P>Enable a disabled set of tooltips.<P><BLOCKQUOTE><CODE><PRE>void gtk_tooltips_disable( GtkTooltips *tooltips );</PRE></CODE></BLOCKQUOTE><P>Disable an enabled set of tooltips.<P><BLOCKQUOTE><CODE><PRE>void gtk_tooltips_set_delay( GtkTooltips *tooltips,                             gint         delay );</PRE></CODE></BLOCKQUOTE><P>Sets how many milliseconds you have to hold your pointer over thewidget before the tooltip will pop up. The default is 500milliseconds (half a second).<P><BLOCKQUOTE><CODE><PRE>void gtk_tooltips_set_colors( GtkTooltips *tooltips,                              GdkColor    *background,                              GdkColor    *foreground );</PRE></CODE></BLOCKQUOTE><P>Set the foreground and background color of the tooltips.<P>And that's all the functions associated with tooltips. More thanyou'll ever want to know :-)<P><H2><A NAME="sec_ProgressBar"></A> <A NAME="ss9.4">9.4 Progress Bars </A></H2><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>There are two ways to create a progress bar, one simple that takesno arguments, and one that takes a GtkAdjustment object as anargument. If the former is used, the progress bar creates its ownadjustment object.<P><BLOCKQUOTE><CODE><PRE>GtkWidget *gtk_progress_bar_new( void );GtkWidget *gtk_progress_bar_new_with_adjustment( GtkAdjustment *adjustment );</PRE></CODE></BLOCKQUOTE><P>The second method has the advantage that we can use the adjustmentobject to specify our own range parameters for the progress bar.<P>The adjustment of a progress object can be changed dynamically using:<P><BLOCKQUOTE><CODE><PRE>void gtk_progress_set_adjustment( GtkProgress   *progress,                                  GtkAdjustment *adjustment );</PRE></CODE></BLOCKQUOTE><P>Now that the progress bar has been created we can use it.<P><BLOCKQUOTE><CODE><PRE>void gtk_progress_bar_update( GtkProgressBar *pbar,                              gfloat          percentage );</PRE></CODE></BLOCKQUOTE><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>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>A progress bar may be set to one of a number of orientations using thefunction<P><BLOCKQUOTE><CODE><PRE>void gtk_progress_bar_set_orientation( GtkProgressBar *pbar,                                       GtkProgressBarOrientation orientation );</PRE></CODE></BLOCKQUOTE><P>Where the <CODE>orientation</CODE> argument may take one of the followingvalues to indicate the direction in which the progress bar moves:<P><UL><LI> GTK_PROGRESS_LEFT_TO_RIGHT</LI><LI> GTK_PROGRESS_RIGHT_TO_LEFT</LI><LI> GTK_PROGRESS_BOTTOM_TO_TOP</LI><LI> GTK_PROGRESS_TOP_TO_BOTTOM</LI></UL><P>When used as a measure of how far a process has progressed, theGtkProgressBar 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>The style of a progress bar can be set using the following function.<P><BLOCKQUOTE><CODE><PRE>void gtk_progress_bar_set_bar_style( GtkProgressBar      *pbar,                                     GtkProgressBarStyle  style );</PRE></CODE></BLOCKQUOTE><P>The <CODE>style</CODE> parameter can take one of two values:<P><UL><LI>GTK_PROGRESS_CONTINUOUS</LI><LI>GTK_PROGRESS_DISCRETE</LI></UL><P>The number of discrete blocks can be set by calling<P><BLOCKQUOTE><CODE><PRE>void gtk_progress_bar_set_discrete_blocks( GtkProgressBar *pbar,                                           guint           blocks );</PRE></CODE></BLOCKQUOTE><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 isselected by the following function.<P><BLOCKQUOTE><CODE><PRE>void gtk_progress_set_activity_mode( GtkProgress *progress,                                     guint        activity_mode );</PRE></CODE></BLOCKQUOTE><P>The step size of the activity indicator, and the number of blocks areset using the following functions.<P><BLOCKQUOTE><CODE><PRE>void gtk_progress_bar_set_activity_step( GtkProgressBar *pbar,                                         guint           step );void gtk_progress_bar_set_activity_blocks( GtkProgressBar *pbar,                                           guint           blocks );</PRE></CODE></BLOCKQUOTE><P>When in continuous mode, the progress bar can also display aconfigurable text string within its trough, using the followingfunction.<P><BLOCKQUOTE><CODE><PRE>void gtk_progress_set_format_string( GtkProgress *progress,                                     gchar       *format);</PRE></CODE></BLOCKQUOTE><P>The <CODE>format</CODE> argument is similiar to one that would be used in a C<CODE>printf</CODE> statement. The following directives may be used within theformat string:<P><UL><LI> %p - percentage</LI><LI> %v - value</LI><LI> %l - lower range value</LI><LI> %u - upper range value</LI></UL><P>The displaying of this text string can be toggled using:<P><BLOCKQUOTE><CODE><PRE>void gtk_progress_set_show_text( GtkProgress *progress,                                 gint         show_text );</PRE></CODE></BLOCKQUOTE><P>The <CODE>show_text</CODE> argument is a boolean TRUE/FALSE value. Theappearance of the text can be modified further using:<P><BLOCKQUOTE><CODE><PRE>void gtk_progress_set_text_alignment( GtkProgress   *progress,                                      gfloat         x_align,                                      gfloat         y_align );</PRE></CODE></BLOCKQUOTE><P>The <CODE>x_align</CODE> and <CODE>y_align</CODE> arguments take a value between 0.0and 1.0. Their value indicates 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>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><BLOCKQUOTE><CODE><PRE>gchar *gtk_progress_get_current_text( GtkProgress   *progress );gchar *gtk_progress_get_text_from_value( GtkProgress *progress,                                         gfloat       value );</PRE></CODE></BLOCKQUOTE><P>There is yet another way to change the range and value of a progressobject using the following function:<P><BLOCKQUOTE><CODE><PRE>void gtk_progress_configure( GtkProgress  *progress,                             gfloat        value,                             gfloat        min,                             gfloat        max );</PRE></CODE></BLOCKQUOTE><P>This function provides quite a simple interface to the range and valueof a progress object.<P>The remaining functions can be used to get and set the current valueof a progess object in various types and formats:<P><BLOCKQUOTE><CODE><PRE>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></CODE></BLOCKQUOTE><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>Progress Bars are usually used with timeouts or other such functions(see section on <A HREF="gtk_tut-17.html#sec_timeouts">Timeouts, I/O and Idle Functions</A>) to give the illusion of multitasking. All will employ thegtk_progress_bar_update function in the same manner.<P>Here is an example of the progress bar, updated using timeouts. Thiscode also shows you how to reset the Progress Bar.<P><BLOCKQUOTE><CODE><PRE>/* example-start progressbar progressbar.c */#include &lt;gtk/gtk.h>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)->adjustment;    if (new_val > adj->upper)      new_val = adj->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->pbar),                                GTK_TOGGLE_BUTTON (widget)->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->pbar),                                    GTK_TOGGLE_BUTTON (widget)->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->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->pbar),                                    GTK_PROGRESS_DISCRETE);} /* Clean up allocated memory and remove the timer */void destroy_progress( GtkWidget     *widget,                       ProgressData *pdata){    gtk_timeout_remove (pdata->timer);    pdata->timer = 0;    pdata->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 (&amp;argc, &amp;argv);    /* Allocate memory for the data that is passwd to the callbacks */    pdata = g_malloc( sizeof(ProgressData) );      pdata->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);    gtk_window_set_policy (GTK_WINDOW (pdata->window), FALSE, FALSE, TRUE);    gtk_signal_connect (GTK_OBJECT (pdata->window), "destroy",                        GTK_SIGNAL_FUNC (destroy_progress),                        pdata);    gtk_window_set_title (GTK_WINDOW (pdata->window), "GtkProgressBar");    gtk_container_set_border_width (GTK_CONTAINER (pdata->window), 0);

⌨️ 快捷键说明

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