📄 z101.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html> <head> <title> A Dialog Example </title> <meta name="GENERATOR" content= "Modular DocBook HTML Stylesheet Version 1.45"> <link rel="HOME" title="GTK+ / Gnome Application Development" href="ggad.html"> <link rel="UP" title="User Communication: Dialogs" href= "cha-dialogs.html"> <link rel="PREVIOUS" title="Modal Dialogs" href= "sec-modaldialogs.html"> <link rel="NEXT" title="Special Dialog Types" href= "cha-dialogs-special.html"> </head> <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink= "#840084" alink="#0000FF"> <div class="NAVHEADER"> <table width="100%" border="0" bgcolor="#ffffff" cellpadding= "1" cellspacing="0"> <tr> <th colspan="4" align="center"> <font color="#000000" size="2">GTK+ / Gnome Application Development</font> </th> </tr> <tr> <td width="25%" bgcolor="#ffffff" align="left"> <a href="sec-modaldialogs.html"><font color="#0000ff" size="2"><b><<< Previous</b></font></a> </td> <td width="25%" colspan="2" bgcolor="#ffffff" align= "center"> <font color="#0000ff" size="2"><b><a href="ggad.html"> <font color="#0000ff" size="2"><b> Home</b></font></a></b></font> </td> <td width="25%" bgcolor="#ffffff" align="right"> <a href="cha-dialogs-special.html"><font color= "#0000ff" size="2"><b>Next >>></b></font></a> </td> </tr> </table> </div> <div class="SECT1"> <h1 class="SECT1"> <a name="Z101">A Dialog Example</a> </h1> <p> Here's a piece of code from the Gnome plot and chart component, Guppi. This is used for an "Open file" dialog. Future versions of Gnome will have a <tt class="CLASSNAME"> GnomeFileSelection</tt> widget, which would be more appropriate for this particular task than a custom dialog; but the example is nonetheless instructive. </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> GtkWidget * dialog; dialog = gnome_dialog_new(_("Guppi: Open"), GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL); gnome_dialog_set_close(GNOME_DIALOG(dialog), TRUE); gnome_dialog_close_hides(GNOME_DIALOG(dialog), TRUE); guppi_setup_dialog(dialog); GtkWidget* fileentry = gnome_file_entry_new("guppi:guppi_loadsave_history", _("Guppi: Browse Files For Open")); gnome_dialog_editable_enters(GNOME_DIALOG(dialog), GTK_EDITABLE(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(fileentry)))); gnome_dialog_set_default(GNOME_DIALOG(dialog), GNOME_OK); gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox), fileentry, TRUE, TRUE, GNOME_PAD); gtk_widget_show_all(dialog); int reply = gnome_dialog_run(GNOME_DIALOG(dialog)); if (reply == GNOME_OK) { gchar* s = gnome_file_entry_get_full_path(GNOME_FILE_ENTRY(fileentry), TRUE); /* Application-specific details of actually * loading the file omitted. */ } gtk_widget_destroy(dialog); </pre> </td> </tr> </table> <p> <tt class="FUNCTION">gnome_dialog_set_close()</tt> is called, so this dialog will close if any of its buttons are clicked. However, closing the dialog only calls <tt class= "FUNCTION">gtk_widget_hide()</tt>, rather than destroying it; <tt class="FUNCTION">gnome_dialog_close_hides()</tt> configures this behavior. <tt class="FUNCTION"> guppi_setup_dialog()</tt> is a wrapper function that calls <tt class="FUNCTION">gnome_dialog_set_parent()</tt> to set the main application window as the dialog's parent. </p> <p> Since the purpose of the dialog is to get a filename, it will be convenient to have the Enter key press the "OK" button; thus the "OK" button should be the default. However, the text entry box would normally steal the Enter key press; <tt class="FUNCTION"> gnome_dialog_editable_enters()</tt> fixes the problem. <tt class="FUNCTION">gnome_dialog_run()</tt> waits for the user to take some action; if "OK" is clicked, we fetch the contents of the text entry and load the file. Note that the dialog is <i class="EMPHASIS">not</i> destroyed after <tt class="FUNCTION">gnome_dialog_run()</tt> returns, because we called <tt class="FUNCTION"> gnome_dialog_close_hides()</tt>. However, the dialog is <i class="EMPHASIS">closed</i> after <tt class="FUNCTION"> gnome_dialog_run()</tt> returns, because the code ensures that all user actions will close it (using <tt class= "FUNCTION">gnome_dialog_set_close()</tt> and relying on the default behavior for the window manager's close button). Finally, <tt class="FUNCTION">gtk_widget_destroy()</tt> is necessary, since the dialog was not destroyed when it was closed. </p> </div> <div class="NAVFOOTER"> <br> <br> <table width="100%" border="0" bgcolor="#ffffff" cellpadding= "1" cellspacing="0"> <tr> <td width="25%" bgcolor="#ffffff" align="left"> <a href="sec-modaldialogs.html"><font color="#0000ff" size="2"><b><<< Previous</b></font></a> </td> <td width="25%" colspan="2" bgcolor="#ffffff" align= "center"> <font color="#0000ff" size="2"><b><a href="ggad.html"> <font color="#0000ff" size="2"><b> Home</b></font></a></b></font> </td> <td width="25%" bgcolor="#ffffff" align="right"> <a href="cha-dialogs-special.html"><font color= "#0000ff" size="2"><b>Next >>></b></font></a> </td> </tr> <tr> <td colspan="2" align="left"> <font color="#000000" size="2"><b>Modal Dialogs</b></font> </td> <td colspan="2" align="right"> <font color="#000000" size="2"><b>Special Dialog Types</b></font> </td> </tr> </table> </div> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -