访问 gtk.TreeIter 里面的 render() 函数的 gtk.CellRenderer -- pygtk
我正在尝试编写以下代码:两列。一个包含 itemId,另一个包含 typeId。我只想在 typeId 等于特定值时渲染 itemId。
class IDRenderer(gtk.CellRendererText):
def __init__(self):
gtk.CellRendererText.__init__(self)
def do_render(self,window, widget, background_area, cell_area, expose_area, flags):
if ----} Condition to ask for value of the typeId - Cell {-----:
gtk.CellRendererText.do_render(self, window, widget, background_area, cell_area,
expose_area, flags)
gobject.type_register(IDRenderer)
我不知道如何获取当前呈现的行的迭代器,我需要它来确定 typeId 的值。这可能吗?
I am trying to code the following: Two Columns. One contains a itemId, the other one contains a typeId. I want to render the itemId only when the typeId equals a specific value.
class IDRenderer(gtk.CellRendererText):
def __init__(self):
gtk.CellRendererText.__init__(self)
def do_render(self,window, widget, background_area, cell_area, expose_area, flags):
if ----} Condition to ask for value of the typeId - Cell {-----:
gtk.CellRendererText.do_render(self, window, widget, background_area, cell_area,
expose_area, flags)
gobject.type_register(IDRenderer)
I don't know how to get the iter of the currently rendered row which i need to determine the value of the typeId. Is this even possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我现在发现了,感谢 gimpIRC 上 #pygtk 上的一个好人:
您可以通过将所谓的单元格数据函数绑定到相应的 gtk.TreeViewColumn 来做到这一点,如本示例中所做的那样,
我省略了一些与渲染完整树视图相关的代码,但我认为它展示了我想做的事情以及如何做。
仅当第二个模型列 (1) 中的值等于 3 时,该列才会呈现模型第一列 (0) 中的值。
我希望这可以对某人有所帮助。
I now found out, thanks to a nice guy on #pygtk on gimpIRC:
You can do that, with binding so called cell data functions to the corresponding gtk.TreeViewColumn as done here in this example
I ommited some code relevant to render a complete treeview, but i think it shows what i wanted to do and how to do it.
The column renderes the value in the first column (0) of the model only if the value in the second modelcolumn (1) equals 3
I hope this could help someone some time.
据我所知这是不可能的。您需要使用自定义渲染器的属性,这些属性将由调用渲染函数的代码自动设置。 (与
CellRendererText
的text
属性类似 - 渲染代码不会从树模型获取文本,但树模型设置text
在调用渲染代码之前渲染器的属性。)It's not possible as far as I know. You need to use properties of the custom renderer which will be set automatically by the code calling the rendering function. (Like the
text
property ofCellRendererText
-- the rendering code doesn't get the text from the tree model, but the tree model sets thetext
property of the renderer before calling the rendering code.)