<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>apt-blog.net   无证程序员的PT桑 &#187; GTK +</title>
	<atom:link href="http://apt-blog.net/category/tech/programming/gtk/feed" rel="self" type="application/rss+xml" />
	<link>http://apt-blog.net</link>
	<description>潜逃中。</description>
	<lastBuildDate>Fri, 18 May 2012 11:25:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>错误生涯：Warning: unable to set property `editable&#039; of type `gboolean&#039; from value of type `gchararray&#039;</title>
		<link>http://apt-blog.net/error_of_gchararray</link>
		<comments>http://apt-blog.net/error_of_gchararray#comments</comments>
		<pubDate>Mon, 04 May 2009 06:04:00 +0000</pubDate>
		<dc:creator>PT</dc:creator>
				<category><![CDATA[GTK +]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Pygtk]]></category>
		<category><![CDATA[错误生涯]]></category>
		<guid isPermaLink="false">http://apt-blog.net/archives/356.html</guid>
		<description><![CDATA[Warning: unable to set property `editable' of type `gboolean' from value of type `gchararray' 做GTK编程的时候，使用TreeView控件时出现这个警告，也就是无法使单元格变为“editable”，原因出在这里： column = gtk.TreeViewColumn(columName[columnNum], renderer, editable=True) 原理解TreeViewColumn的构造函数接受的参数里面可以接受设置Cellrenderer的属性，就直接给editable设True，于是就得到以上警告。 换用add_attribute、set_attributes，均是如此。 Google上搜到同样错误警告，但是他的原因是设错值类型，我明明设了True啊…… 自己观察pygtk-demo的代码和手册，突然发现在构造函数里面给出的属性设置值不应该是直接的值，而是对应Model里面的相应column的值！看手册的描述： Zero or more attribute=column pairs may be added to specify from which tree model column to retrieve the attribute value. 呃，果然是看手册时候大意了，这么多年来还是让英语介词搞的晕头转向。如果在构造函数里面设True这个值，就会被解析为1，去对应Model里面第二栏的类型，是字符串的gchararray，当然对不上了。 解决办法是renderer.set_property("editable", True)，调用继承自GObject的set_property方法来设置对象属性。]]></description>
			<content:encoded><![CDATA[<blockquote><p>Warning: unable to set property `editable' of type `gboolean' from value of type `gchararray'</p></blockquote>
<p>做GTK编程的时候，使用TreeView控件时出现这个警告，也就是无法使单元格变为“editable”，原因出在这里：</p>
<p>column = gtk.TreeViewColumn(columName[columnNum], renderer, editable=True)</p>
<p>原理解TreeViewColumn的构造函数接受的参数里面可以接受设置Cellrenderer的属性，就直接给editable设True，于是就得到以上警告。</p>
<p>换用add_attribute、set_attributes，均是如此。</p>
<p>Google上搜到<a target="_blank" href="http://errorjournal.blogspot.com/2008/11/unable-to-set-property-editable-of-type.html">同样错误警告</a>，但是他的原因是设错值类型，我明明设了True啊……</p>
<p>自己观察pygtk-demo的代码和手册，突然发现在构造函数里面给出的属性设置值不应该是直接的值，而是对应Model里面的相应column的值！看手册的描述：<br />
<blockquote>Zero or more attribute=column pairs may be added to specify from which tree model column to retrieve the attribute value.</p></blockquote>
<p>呃，果然是看手册时候大意了，这么多年来还是让英语介词搞的晕头转向。如果在构造函数里面设True这个值，就会被解析为1，去对应Model里面第二栏的类型，是字符串的gchararray，当然对不上了。</p>
<p>解决办法是renderer.set_property("editable", True)，调用继承自GObject的set_property方法来设置对象属性。</p>
]]></content:encoded>
			<wfw:commentRss>http://apt-blog.net/error_of_gchararray/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Create a exe file with icon in Mingw gcc</title>
		<link>http://apt-blog.net/create-a-exe-file-with-icon-in-mingw-gcc</link>
		<comments>http://apt-blog.net/create-a-exe-file-with-icon-in-mingw-gcc#comments</comments>
		<pubDate>Mon, 12 Jan 2009 07:34:56 +0000</pubDate>
		<dc:creator>PT</dc:creator>
				<category><![CDATA[GTK +]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">http://apt-blog.net/archives/10.htm</guid>
		<description><![CDATA[1. get a icon file name "logo.ico"2. create an file name "logo.rc", contain a line: 1 ICON "icon.ico" 3. run : (windres was include in Mingw) windres logo.rc logo.o 4. link the "logo.o" file together with other object files to the final exe file.]]></description>
			<content:encoded><![CDATA[<p>1. get a icon file name "logo.ico"<br />2. create an file name "logo.rc", contain a line:<br />
<blockquote>1 ICON "icon.ico"</p></blockquote>
<p>3. run : (windres was include in Mingw)<br />
<blockquote>windres logo.rc logo.o</p></blockquote>
<p>4. link the "logo.o" file together with other object files to the final exe file.</p>
]]></content:encoded>
			<wfw:commentRss>http://apt-blog.net/create-a-exe-file-with-icon-in-mingw-gcc/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>编程笔记：Editable Treeview Cell</title>
		<link>http://apt-blog.net/note-editable-treeview-cell</link>
		<comments>http://apt-blog.net/note-editable-treeview-cell#comments</comments>
		<pubDate>Mon, 12 Jan 2009 07:34:48 +0000</pubDate>
		<dc:creator>PT</dc:creator>
				<category><![CDATA[GTK +]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">http://apt-blog.net/archives/9.htm</guid>
		<description><![CDATA[I found that programming gtk+ plays a lot of tricks. I implemented "editable treeview cells" today in my program, after spending quite a while looking up for examples on Google. The most I wanted to say is that, the Gtk manual was detailed enough, but it never tells you how to do, which makes me [...]]]></description>
			<content:encoded><![CDATA[<p>I found that programming gtk+ plays a lot of tricks. I implemented "editable treeview cells" today in my program, after spending quite a while looking up for examples on Google. The most I wanted to say is that, the Gtk manual was detailed enough, but it never tells you how to do, which makes me so desperate sometimes......</p>
<p>The solution was written in a tutorial, <a href="http://scentric.net/tutorial/sec-editable-cells.html">http://scentric.net/tutorial/sec-editable-cells.html</a></p>
<p>there seems quite several GTK tutorials, but most of their contents were duplicated, though I always learn the tricks from them... ^_^</p>
<p>Note:<br />
<blockquote>renderer = gtk_cell_renderer_text_new();<br />...<br />g_object_set_data(G_OBJECT(renderer), "my_column_num", GUINT_TO_POINTER(COLUMN_NAME));</p>
<p>...</p>
<p>renderer = gtk_cell_renderer_text_new();<br />...<br />g_object_set_data(G_OBJECT(renderer), "my_column_num", GUINT_TO_POINTER(COLUMN_YEAR_OF_BIRTH));</p>
<p>...</p></blockquote>
<p><span style="color: rgb(255, 0, 0);">the "renderer" must be create several times in this trick, for a object couldn't carry the same property in different value twice, itn's it?</span></p>
]]></content:encoded>
			<wfw:commentRss>http://apt-blog.net/note-editable-treeview-cell/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>编程笔记：GtkBuilder和popup menu</title>
		<link>http://apt-blog.net/notes-gtkbuilder-and-popup-menu</link>
		<comments>http://apt-blog.net/notes-gtkbuilder-and-popup-menu#comments</comments>
		<pubDate>Mon, 12 Jan 2009 07:34:41 +0000</pubDate>
		<dc:creator>PT</dc:creator>
				<category><![CDATA[GTK +]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">http://apt-blog.net/archives/8.htm</guid>
		<description><![CDATA[今天又奋战gtk的文档，看着别人写的旧版example代码，用GtkBuilder的方法重写，实现了一个自己想要的TreeView List。最后想在TreeView中加入一个右键菜单，却想不到小小的popup menu就给我设了两大难关。 首先找来找去没有见到有right-click的signal，Google了一下，从Maillist里面的解答找到头绪，由GtkWidget的button_press_event来实现。GTK+ Reference Manual里面一点都没提到这个信号，原来这个button指鼠标的button，键盘的键叫做key…… http://mail.gnome.org/archives/gtk-list/2002-August/msg00119.html button_press_event emits when any mouse button pressed, when handling with this signal, use a callback prototype in this way: gboolean callback (GtkWidget *widget, GdkEventButton *event, gpointer data); and you can determine which button was press with event-&#62;button (values 1,2,3...3 stands for the right button, 1 for left and [...]]]></description>
			<content:encoded><![CDATA[<p>今天又奋战gtk的文档，看着别人写的旧版example代码，用GtkBuilder的方法重写，实现了一个自己想要的TreeView List。最后想在TreeView中加入一个右键菜单，却想不到小小的popup menu就给我设了两大难关。</p>
<p>首先找来找去没有见到有right-click的signal，Google了一下，从Maillist里面的解答找到头绪，由GtkWidget的button_press_event来实现。GTK+ Reference Manual里面一点都没提到这个信号，原来这个button指鼠标的button，键盘的键叫做key……</p>
<p><a href="http://mail.gnome.org/archives/gtk-list/2002-August/msg00119.html">http://mail.gnome.org/archives/gtk-list/2002-August/msg00119.html</a></p>
<p>button_press_event emits when any mouse button pressed, when handling with this signal, use a callback prototype in this way:</p>
<blockquote><p>gboolean callback (GtkWidget *widget,<br />   GdkEventButton *event,<br />   gpointer data);</p></blockquote>
<p>and you can determine which button was press with <span style="font-style: italic; color: rgb(0, 153, 0);">event-&gt;button</span> (values 1,2,3...3 stands for the right button, 1 for left and 2 for middle), and if you want give this signal back to the widget, just return FALSE.</p>
<p>另外一个问题是popup menu, 在glade3里面添加了一个popup menu, 照搬老方法，初始化程序的时候<br />
<blockquote>tree-&gt;menu = GTK_WIDGET ( gtk_builder_get_object (builder,  "menu1") );</p></blockquote>
<p>弹出窗口：<br />
<blockquote>gtk_menu_popup (GTK_MENU(user_data-&gt;menu), NULL, NULL, NULL, NULL, event-&gt;button, event-&gt;time);</p></blockquote>
<p>郁闷的事情来了，程序运行的时候提示：<br />
<blockquote>(tree:28254): GLib-GObject-WARNING **: invalid unclassed pointer in cast to `GtkMenu'</p>
<p>(tree:28254): Gtk-CRITICAL **: gtk_menu_popup: assertion `GTK_IS_MENU (menu)' failed</p></blockquote>
<p>在Reference里面看了半天，注意到GtkBuilder Description的一段话：<br />
<blockquote>A GtkBuilder holds a reference to all objects that it has constructed and drops these references when it is finalized. <span style="font-weight: bold; color: rgb(255, 0, 0);">This finalization can cause the destruction of non-widget objects or widgets which are not contained in a toplevel window. </span>For toplevel windows constructed by a builder, it is the responsibility of the user to call gtk_widget_destroy() to get rid of them and all the widgets they contain. </p></blockquote>
<p>在Glade3里面看到，popup menu不属于toplevel的window，看来小menu在g_object_unref (G_OBJECT (builder));的时候被收回去了……可是怎么解决呢？总不能不收了builder吧，builder占的内存可不小的，很容易造成内存泄漏……</p>
<p>It's obvious that the menu allocation was released after initialing the application, I have to solve this problem.</p>
<p>In the Reference Manual, I found a function.<br />
<h3></h3>
<blockquote><h3>g_object_ref ()</h3>
<pre class="programlisting">gpointer g_object_ref (gpointer object);</pre>
<p> Increases the reference count of <em class="parameter"><code>object</code></em>.</p>
<p>  The <span style="color: rgb(255, 0, 0); font-style: italic; font-weight: bold;">reference count</span> really mean something, worth to read about it carefully. I just add one more statement after getting the menu widget:</p>
<p>这个reference count大有来头。在gtk_builder_get_object (builder,  "menu1")后，加了一句:<br />
<blockquote style="color: rgb(255, 0, 0);">g_object_ref ((gpointer)tree-&gt;menu);</p></blockquote>
<p>Yes，the whole world goes the right way now!!!!</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://apt-blog.net/notes-gtkbuilder-and-popup-menu/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

