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

📄 gtkbuilder.html

📁 最新gtk中文资料集
💻 HTML
📖 第 1 页 / 共 4 页
字号:
the builder look for translated strings using <code class="function">dgettext()</code> in thedomain specified. This can also be done by calling<a class="link" href="GtkBuilder.html#gtk-builder-set-translation-domain"><code class="function">gtk_builder_set_translation_domain()</code></a> on the builder.Objects are described by &lt;object&gt; elements, which cancontain &lt;property&gt; elements to set properties, &lt;signal&gt;elements which connect signals to handlers, and &lt;child&gt;elements, which describe child objects (most often widgetsinside a container, but also e.g. actions in an action group,or columns in a tree model). A &lt;child&gt; element containsan &lt;object&gt; element which describes the child object.</p><p>Typically, the specific kind of object represented by an&lt;object&gt; element is specified by the "class" attribute.If the type has not been loaded yet, GTK+ tries to find the<code class="function"><code class="function">_get_type()</code></code> from the class name by applying heuristics. This works in most cases, but if necessary, it ispossible to specify the name of the <code class="function"><code class="function">_get_type()</code></code> explictly with the "type-func" attribute. As a special case, GtkBuilder allows to use an object that has been constructedby a <a class="link" href="GtkUIManager.html" title="GtkUIManager"><span class="type">GtkUIManager</span></a> in another part of the UI definition byspecifying the id of the <a class="link" href="GtkUIManager.html" title="GtkUIManager"><span class="type">GtkUIManager</span></a> in the "constructor"attribute and the name of the object in the "id" attribute.</p><p>Objects must be given a name with the "id" attribute, which allows the application to retrieve them from the builder with <a class="link" href="GtkBuilder.html#gtk-builder-get-object"><code class="function">gtk_builder_get_object()</code></a>. An id is also necessary to use the object as property value in other parts of the UI definition.</p><p>Setting properties of objects is pretty straightforward withthe &lt;property&gt; element: the "name" attribute specifiesthe name of the property, and the content of the element specifies the value. If the "translatable" attribute is set to a true value, GTK+ uses <code class="function">gettext()</code> (or <code class="function">dgettext()</code> ifthe builder has a translation domain set) to find a translation for the value. This happens before the value is parsed, soit can be used for properties of any type, but it is probablymost useful for string properties. It is also possible tospecify a context to disambiguate short strings, and commentswhich may help the translators.</p><p>GtkBuilder can parse textual representations for the mostcommon property types: characters, strings, integers, floating-pointnumbers, booleans (strings like "TRUE", "t", "yes", "y", "1" areinterpreted as <ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, strings like "FALSE, "f", "no", "n", "0" areinterpreted as <ahref="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a>), enumerations (can be specified by their name, nick or integer value), flags (can be specified by their name, nick, integer value, optionally combined with "|", e.g. "GTK_VISIBLE|GTK_REALIZED")  and colors (in a format understood by <ahref="/usr/share/gtk-doc/html/gdk/gdk-Colormaps-and-Colors.html#gdk-color-parse"><code class="function">gdk_color_parse()</code></a>). Objects can be referred to by their name. Pixbufs can be specified as a filename of an image file to load.In general, GtkBuilder allows forward references to objects &#8212; an object doesn't have to constructed before it can be referred to.The exception to this rule is that an object has to be constructedbefore it can be used as the value of a construct-only property. </p><p>Signal handlers are set up with the &lt;signal&gt; element.The "name" attribute specifies the name of the signal, and the"handler" attribute specifies the function to connect to the signal.By default, GTK+ tries to find the handler using <ahref="/usr/share/gtk-doc/html/glib/glib-Dynamic-Loading-of-Modules.html#g-module-symbol"><code class="function">g_module_symbol()</code></a>,but this can be changed by passing a custom <a class="link" href="GtkBuilder.html#GtkBuilderConnectFunc"><span class="type">GtkBuilderConnectFunc</span></a>to <a class="link" href="GtkBuilder.html#gtk-builder-connect-signals-full"><code class="function">gtk_builder_connect_signals_full()</code></a>. The remaining attributes,"after", "swapped" and "object", have the same meaning as the corresponding parameters of the <ahref="/usr/share/gtk-doc/html/gobject/gobject-Signals.html#g-signal-connect-object"><code class="function">g_signal_connect_object()</code></a> or<ahref="/usr/share/gtk-doc/html/gobject/gobject-Signals.html#g-signal-connect-data"><code class="function">g_signal_connect_data()</code></a> functions. A "last_modification_time" attributeis also allowed, but it does not have a meaning to the builder.</p><p>Sometimes it is necessary to refer to widgets which have implicitlybeen constructed by GTK+ as part of a composite widget, to set properties on them or to add further children (e.g. the <em class="parameter"><code>vbox</code></em> of a <a class="link" href="GtkDialog.html" title="GtkDialog"><span class="type">GtkDialog</span></a>). This can be achieved by setting the "internal-child"propery of the &lt;child&gt; element to a true value. Note thatGtkBuilder still requires an &lt;object&gt; element for the internalchild, even if it has already been constructed.</p><p>A number of widgets have different places where a child can be added (e.g. tabs vs. page content in notebooks). This can be reflectedin a UI definition by specifying the "type" attribute on a &lt;child&gt;The possible values for the "type" attribute are described in the sections describing the widget-specific portions of UI definitions.</p><div class="example"><a name="id4456774"></a><p class="title"><b>Example&#160;51.&#160;A GtkBuilder UI Definition</b></p><div class="example-contents"><pre class="programlisting">&lt;interface&gt;  &lt;object class="GtkDialog" id="dialog1"&gt;    &lt;child internal-child="vbox"&gt;      &lt;object class="GtkVBox" id="vbox1"&gt;        &lt;property name="border-width"&gt;10&lt;/property&gt;        &lt;child internal-child="action_area"&gt;          &lt;object class="GtkHButtonBox" id="hbuttonbox1"&gt;            &lt;property name="border-width"&gt;20&lt;/property&gt;            &lt;child&gt;              &lt;object class="GtkButton" id="ok_button"&gt;                &lt;property name="label"&gt;gtk-ok&lt;/property&gt;                &lt;property name="use-stock"&gt;TRUE&lt;/property&gt;                &lt;signal name="clicked" handler="ok_button_clicked"/&gt;              &lt;/object&gt;            &lt;/child&gt;          &lt;/object&gt;        &lt;/child&gt;      &lt;/object&gt;    &lt;/child&gt;  &lt;/object&gt;&lt;/interface&gt;</pre></div></div><br class="example-break"><p>Beyond this general structure, several object classes definetheir own XML DTD fragments for filling in the ANY placeholdersin the DTD above. Note that a custom element in a &lt;child&gt;element gets parsed by the custom tag handler of the parentobject, while a custom element in an &lt;object&gt; elementgets parsed by the custom tag handler of the object. </p><p>These XML fragments are explained in the documentation of therespective objects, see <a class="link" href="GtkWidget.html#GtkWidget-BUILDER-UI" title="GtkWidget as GtkBuildable">GtkWidget</a>,<a class="link" href="GtkContainer.html#GtkContainer-BUILDER-UI" title="GtkContainer as GtkBuildable">GtkContainer</a>,<a class="link" href="GtkDialog.html#GtkDialog-BUILDER-UI" title="GtkDialog as GtkBuildable">GtkDialog</a>,<a class="link" href="GtkCellLayout.html#GtkCellLayout-BUILDER-UI" title="GtkCellLayouts as GtkBuildable">GtkCellLayout</a>,<a class="link" href="GtkColorSelectionDialog.html#GtkColorSelectionDialog-BUILDER-UI" title="GtkColorSelectionDialog as GtkBuildable">GtkColorSelectionDialog</a>,<a class="link" href="GtkFontSelectionDialog.html#GtkFontSelectionDialog-BUILDER-UI" title="GtkFontSelectionDialog as GtkBuildable">GtkFontSelectionDialog</a>,<a class="link" href="GtkComboBoxEntry.html#GtkComboBoxEntry-BUILDER-UI" title="GtkComboBoxEntry as GtkBuildable">GtkComboBoxEntry</a>,<a class="link" href="GtkExpander.html#GtkExpander-BUILDER-UI" title="GtkExpander as GtkBuildable">GtkExpander</a>,<a class="link" href="GtkFrame.html#GtkFrame-BUILDER-UI" title="GtkFrame as GtkBuildable">GtkFrame</a>,<a class="link" href="GtkListStore.html#GtkListStore-BUILDER-UI" title="GtkListStore as GtkBuildable">GtkListStore</a>,<a class="link" href="GtkTreeStore.html#GtkTreeStore-BUILDER-UI" title="GtkTreeStore as GtkBuildable">GtkTreeStore</a>,<a class="link" href="GtkNotebook.html#GtkNotebook-BUILDER-UI" title="GtkNotebook as GtkBuildable">GtkNotebook</a>,<a class="link" href="GtkSizeGroup.html#GtkSizeGroup-BUILDER-UI" title="GtkSizeGroup as GtkBuildable">GtkSizeGroup</a>,<a class="link" href="GtkTreeView.html#GtkTreeView-BUILDER-UI" title="GtkTreeView as GtkBuildable">GtkTreeView</a>,<a class="link" href="GtkUIManager.html#GtkUIManager-BUILDER-UI" title="GtkUIManager as GtkBuildable">GtkUIManager</a>,<a class="link" href="GtkActionGroup.html#GtkActionGroup-BUILDER-UI" title="GtkActionGroup as GtkBuildable">GtkActionGroup</a>.</p></div></div><div class="refsect1" lang="en"><a name="id4456947"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id4456957"></a><h3><a name="GtkBuilder-struct"></a>GtkBuilder</h3><a class="indexterm" name="id4456970"></a><pre class="programlisting">typedef struct _GtkBuilder GtkBuilder;</pre><p></p></div><hr><div class="refsect2" lang="en"><a name="id4456985"></a><h3><a name="GtkBuilderConnectFunc"></a>GtkBuilderConnectFunc ()</h3><a class="indexterm" name="id4457001"></a><pre class="programlisting">void                (*GtkBuilderConnectFunc)            (<a class="link" href="GtkBuilder.html" title="GtkBuilder">GtkBuilder</a> *builder,                                                         <ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject">GObject</a> *object,                                                         const <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar">gchar</a> *signal_name,                                                         const <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar">gchar</a> *handler_name,                                                         <ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject">GObject</a> *connect_object,                                                         <ahref="/usr/share/gtk-doc/html/gobject/gobject-Signals.html#GConnectFlags">GConnectFlags</a> flags,                                                         <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gpointer">gpointer</a> user_data);</pre><p>This is the signature of a function used to connect signals.  It is usedby the <a class="link" href="GtkBuilder.html#gtk-builder-connect-signals"><code class="function">gtk_builder_connect_signals()</code></a> and <a class="link" href="GtkBuilder.html#gtk-builder-connect-signals-full"><code class="function">gtk_builder_connect_signals_full()</code></a>methods.  It is mainly intended for interpreted language bindings, butcould be useful where the programmer wants more control over the signalconnection process.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>builder</code></em>&#160;:</span></p></td><td> a <a class="link" href="GtkBuilder.html" title="GtkBuilder"><span class="type">GtkBuilder</span></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>object</code></em>&#160;:</span></p></td><td> object to connect a signal to</td></tr><tr><td><p><span class="term"><em class="parameter"><code>signal_name</code></em>&#160;:</span></p></td><td> name of the signal</td></tr><tr><td><p><span class="term"><em class="parameter"><code>handler_name</code></em>&#160;:</span></p></td><td> name of the handler</td></tr><tr><td><p><span class="term"><em class="parameter"><code>connect_object</code></em>&#160;:</span></p></td><td> a <ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject"><span class="type">GObject</span></a>, if non-<ahref="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a>, use <ahref="/usr/share/gtk-doc/html/gobject/gobject-Signals.html#g-signal-connect-object"><code class="function">g_signal_connect_object()</code></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>flags</code></em>&#160;:</span></p></td><td> <ahref="/usr/share/gtk-doc/html/gobject/gobject-Signals.html#GConnectFlags"><span class="type">GConnectFlags</span></a> to use</td></tr><tr><td><p><span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></p></td><td> user data</td></tr></tbody></table></div><p class="since">Since  2.12</p></div><hr><div class="refsect2" lang="en"><a name="id4457260"></a><h3><a name="GtkBuilderError"></a>enum GtkBuilderError</h3><a class="indexterm" name="id4457273"></a><pre class="programlisting">typedef enum{  GTK_BUILDER_ERROR_INVALID_TYPE_FUNCTION,  GTK_BUILDER_ERROR_UNHANDLED_TAG,  GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,  GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,  GTK_BUILDER_ERROR_INVALID_TAG,  GTK_BUILDER_ERROR_MISSING_PROPERTY_VALUE,  GTK_BUILDER_ERROR_INVALID_VALUE} GtkBuilderError;</pre><p></p></div><hr><div class="refsect2" lang="en"><a name="id4457292"></a><h3><a name="gtk-builder-new"></a>gtk_builder_new ()</h3><a class="indexterm" name="id4457308"></a><pre class="programlisting"><a class="link" href="GtkBuilder.html" title="GtkBuilder">GtkBuilder</a>*         gtk_builder_new                     (void);</pre><p>Creates a new builder object.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td> a new <a class="link" href="GtkBuilder.html" title="GtkBuilder"><span class="type">GtkBuilder</span></a> object</td></tr></tbody></table></div><p class="since">Since  2.12</p></div><hr><div class="refsect2" lang="en"><a name="id4457363"></a><h3><a name="gtk-builder-add-from-file"></a>gtk_builder_add_from_file ()</h3><a class="indexterm" name="id4457379"></a><pre class="programlisting"><ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#guint">guint</a>               gtk_builder_add_from_file           (<a class="link" href="GtkBuilder.html" title="GtkBuilder">GtkBuilder</a> *builder,                                                         const <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar">gchar</a> *filename,                                                         <ahref="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError">GError</a> **error);</pre>

⌨️ 快捷键说明

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