'GTK +' Tag

  • 错误生涯:Warning: unable to set property `editable' of type `gboolean' from value of type `gchararray'

    May 4, 2009

    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方法来设置对象属性。

Page optimized by WP Minify WordPress Plugin

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org