简体   繁体   English

填充 Glade 组合框“gtk_entry_set_text:断言 `text != NULL' 失败”?

[英]Populating a Glade combobox “gtk_entry_set_text: assertion `text != NULL' failed”?

I am building a “pseudo-intelligent” GUI for a gimp plugin using Glade.我正在使用 Glade 为 gimp 插件构建一个“伪智能”GUI。 The main part of the GUI has two frames and imports the contents using the “reparent” method. GUI 的主要部分有两个框架,并使用“reparent”方法导入内容。 The main objective is to have the contents of the second frame determined by the selections made in the first frame.主要目标是让第二帧的内容由第一帧中的选择决定。 (Eventually, the intention is to import this GUI as the content for the tabbed pages of a "notebook") (最终,目的是将此 GUI 作为“笔记本”选项卡页面的内容导入)

To start with, I made a simple window, consisting of a “RadioButtonBox” and a “ComboBox” which is populated using:首先,我制作了一个简单的窗口,由一个“RadioButtonBox”和一个“ComboBox”组成,使用以下方法填充:

# create the cell renderer
self.cell = gtk.CellRendererText()
#populate the default choice into the Selection  combobox
self.SelectionBox = self.builder.get_object("SelectionBox")
self.SelectionBox.set_model(self.EditCommands)
self.SelectionBox.pack_start(self.cell, True)
self.SelectionBox.add_attribute(self.cell, 'text', 1)
self.SelectionBox.set_active(0)
# End: populate the selection combo box section

This works and I can successfully “import” and “reparent” the simple GUI as the first frame of the larger, more complex GUI without any problems.这有效,我可以成功地“导入”和“重新设置”简单的 GUI 作为更大、更复杂的 GUI 的第一帧,没有任何问题。 However, as the design progressed, it has become more convenient to have the code for the first frame as an integral part of the main GUI, and this is where my problems begin.然而,随着设计的进展,将第一帧的代码作为主 GUI 的一个组成部分变得更加方便,这就是我的问题开始的地方。

I have reproduced the contents of the simple GUI in the first frame of the larger GUI and copy/pasted the code from the simple GUI's “ init ” function.我在较大 GUI 的第一帧中复制了简单 GUI 的内容,并从简单 GUI 的“ init ”函数中复制/粘贴了代码。 In other-words, everything is identical.换句话说,一切都是相同的。

Unfortunately, when I run the code I get the following error:不幸的是,当我运行代码时,出现以下错误:

C:\Documents and Settings\anonymous\Desktop\Glade-tutorial\BatchEditMain\BatchEditLibrary\Tab.py:46: GtkWarning: gtk_entry_set_text: assertion `text != NULL' failed
  self.SelectionBox.set_active(0)

Could someone please explain what the problem is?有人可以解释一下问题是什么吗?

Thanks in advance提前致谢

Irvine尔湾

The GTK Warning is saying that somewhere gtk_entry.set_text() is being called with None instead of some text. GTK 警告说某处gtk_entry.set_text()被调用None而不是一些文本。 This is happening in the call to self.SelectionBox.set_active(0)这发生在调用self.SelectionBox.set_active(0)

This feels a little bit like gravedigging , but i stumbled across the same Problem today and this was the first post google showed...这感觉有点像挖坟,但我今天偶然发现了同样的问题,这是谷歌展示的第一篇文章......

With a little further research i found this Question:通过进一步的研究,我发现了这个问题:

How create a combobox on Python with GTK3? 如何使用 GTK3 在 Python 上创建组合框? The author seems to have the same error.作者似乎也有同样的错误。

What in his and my case seems to do the trick is a simple:在他和我的情况下,似乎可以解决问题的方法很简单:

combobox.set_entry_text_column(0)

Important it has to be in front of set_active(0) !重要的是它必须在set_active(0) So in your case this would be:所以在你的情况下,这将是:

...
self.SelectionBox.add_attribute(self.cell, 'text', 1)
self.SelectionBox.set_entry_text_column(0)
self.SelectionBox.set_active(0)
...

PS: Whatch out if you want to apply attributes like "foreground", they seem to get overwritten by set_entry_text_column(0) if set befor. PS:如果你想应用像“前景”这样的属性,那么如果设置之前,它们似乎会被set_entry_text_column(0)覆盖。 Eg: if items in the model look like:例如:如果模型中的项目看起来像:

["TEXT_YOU_WANT_TO_DISPLAY","TEXT_FOREGROUNDCOLOR_AS_MARKUP_COLOR"]

The change to the foregroundcolor can be applied with the following:可以通过以下方式应用对前景色的更改:

...
self.SelectionBox.add_attribute(self.cell, 'text', 0)
self.SelectionBox.set_entry_text_column(0)
self.SelectionBox.add_attribute(self.cell, 'foreground', 1)
self.SelectionBox.set_active(0)
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM