cvs: php-gtk-doc /manual/zh_cn/tutorials glade.xml
[email protected] ("Fernando Correa da Concei??o") Thu, 04 Jan 2007 02:45:12 -0000
| Newsgroups | php.gtk.doc |
|---|---|
| Message-ID | <cvsfernandoc1167878712@cvsserver> |
fernandoc Thu Jan 4 02:45:12 2007 UTC
Added files:
/php-gtk-doc/manual/zh_cn/tutorials glade.xml
Log:
New translation by mikespook
http://cvs.php.net/viewvc.cgi/php-gtk-doc/manual/zh_cn/tutorials/glade.xml?view=markup&rev=1.1
Index: php-gtk-doc/manual/zh_cn/tutorials/glade.xml
+++ php-gtk-doc/manual/zh_cn/tutorials/glade.xml
<?xml version="1.0" encoding="utf-8" ?>
<!-- EN-Revision: 1.6 Maintainer: mikespook Status: ready -->
<!-- $Revision: 1.1 $ -->
<chapter id="tutorials.helloglade">
<title>Hello Glade!</title>
<sect1>
<title>关于本指南</title>
<para>
本指南将介绍如何在 PHP-Gtk 2 应用中使用 <literal>.glade</literal>
文件的基础知识。
</para>
<para>
Glade2 是用户界面设计器,允许你用鼠标创建 Gtk 2 应用而不需要编写程序。
工作成果保存在 <filename>.glade</filename> 文件中,
并且可以非常简单地加载到你的 PHP-Gtk 2 应用中。
</para>
<simpara>
使用 Glade 创建用户界面可以节约许多时间,特别是在大型项目中可以分工合作:
界面设计人员使用 Glade 设计用户界面(可以不需要了解程序的任何内容)
而你可以专注编写程序而不是关系界面上某部分的易用性。
</simpara>
</sect1>
<sect1 id="tutorials.helloglade.preparation">
<title>准备</title>
<simpara>
我们精练了 Glade 的使用方法,而不是设计繁琐的界面。
这样,用于演示的 <filename>.glade</filename> 会相当简单:窗口上面有一个按钮。
</simpara>
<para>
窗口的名字(id)是 <literal>wndClose</literal>,
同时按钮的名字是 <literal>btnClose</literal>。
</para>
<example>
<title>例子 .glade 文件 - helloglade.glade</title>
<programlisting role="xml">
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
href="&directory.examples;/tutorials/helloglade/helloglade.glade" parse="text">
<xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
</xi:include>
</programlisting>
</example>
</sect1>
<sect1 id="tutorials.helloglade.loading">
<title>加载文件</title>
<para>
首先是需要加载之前的 <filename>.glade</filename> 文件。
<classname>GladeXML</classname> 构造函数接受文件路径作为第一个参数,
所以我们需要做的是:
</para>
<example>
<title>加载 .glade 文件</title>
<programlisting role="php">
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
href="&directory.examples;/tutorials/helloglade/loading.phpw" parse="text">
<xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
</xi:include>
</programlisting>
</example>
<para>
当运行这个脚本时,你会发现屏幕上显示出来有一个按钮的窗口,
但是除了关闭窗口不可以做其他任何事情。
甚至窗口销毁了以后脚本仍然运行 —— 很明显缺少信号处理的连接。
</para>
<sect2 id="tutorials.helloglade.connecting">
<title>手工连接信号处理</title>
<para>
下一步,只需要像我们已经知道的那样连接信号处理:针对元件对象调用
<function class="GtkObject">connect</function> 或
<function class="GtkObject">connect_simple</function>。获取对象只要使用
<function class="GladeXML">get_widget</function> 并作为参数传递元件名称(id)。
然后像往常一样的方式:
</para>
<example>
<title>获取并连接信号处理</title>
<programlisting role="php">
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
href="&directory.examples;/tutorials/helloglade/connecting_by_hand.phpw" parse="text">
<xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
</xi:include>
</programlisting>
</example>
</sect2>
<sect2 id="tutorials.helloglade.autoconnect">
<title>使用 Glade 连接信号处理</title>
<para>
你可能已经注意到 <filename>.glade</filename> 文件中的 <signal> 标签——
它使得在文件中直接定义信号处理成为了可能。我们需要做的就是通过调用
<function class="GladeXML">signal_autoconnect</function> 告诉 Glade 建立连接。
</para>
<para>
你可以定义普通的函数名作为处理方式,当事件发生时调用。
或者使用两个冒号分隔的类和静态方法,如
<literal>Classname::methodName</literal>。
</para>
<example>
<title>使用 signal_autoconnect</title>
<programlisting role="php">
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
href="&directory.examples;/tutorials/helloglade/autoconnect.phpw" parse="text">
<xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
</xi:include>
</programlisting>
</example>
</sect2>
<sect2 id="tutorials.helloglade.autoconnect_instance">
<title>连接到对象方法</title>
<para>
仅仅连接到普通函数或静态方法不能满足真正的好程序员的需要。避免混乱的代码,
我们需要能够将信号连接到对象的方法上。
</para>
<para>
使用这个是非常简单的:仅仅需要将使用那个对象作为第一个参数的
<function class="GladeXML">signal_autoconnect_instance</function> 替换
<function class="GladeXML">signal_autoconnect</function> 即可:
</para>
<example>
<title>使用 signal_autoconnect_instance</title>
<programlisting role="php">
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
href="&directory.examples;/tutorials/helloglade/autoconnect_instance.phpw" parse="text">
<xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
</xi:include>
</programlisting>
</example>
</sect2>
</sect1>
<sect1 id="tutorials.helloglade.partial">
<title>加载 .glade 文件的一部分</title>
<para>
在大项目中,你可能有许多窗口定义在 <filename>.glade</filename> 文件中,
并且在加载 <filename>.glade</filename> 时全部被加载。这会使得
a) 你的程序启动变得缓慢。b) 立即显示所有的窗口,如果你没有在 Glade 中设置隐藏。
此外,你可能希望 <function class="GladeXML">signal_autoconnect_instance</function>
连接 <filename>.glade</filename> 文件的一部分到一个对象,然后连接其他的部分到另外的对象。
</para>
<para>
解决这个问题的方法是 <classname>GladeXML</classname> 构造函数的第二个参数:
仅仅传递将要作为根元件的元件 id ,那么只有这部分的
<filename>.glade</filename> 文件会被加载。
</para>
<example>
<title>部分加载 .glade 文件</title>
<programlisting role="php">
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
href="&directory.examples;/tutorials/helloglade/partially.phpw" parse="text">
<xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
</xi:include>
</programlisting>
</example>
</sect1>
</chapter>