pyGTK TreeView 中的条件 CellRenderCombo
我有一个两列 TreeView 附加到 ListStore。两列都是 CellRenderCombo 组合框。
当用户在第一个框中选择一个条目时,我需要在第二个框中动态加载一组选项。
例如,我想要的行为是:
On row 0, the user selects "Alphabet" in the first column box.
The second column box is populated with the letters "A-Z".
On row 1, the user selects "Numbers" in the first column box.
The second column box is populated with the numbers "0-9".
On row 2, the user selects "Alphabet" in the first column box.
The second column box is populated with the letters "A-Z".
etc.
有谁知道如何做到这一点,或者看到任何具有我可以分析的类似行为的开源 pygtk 或 gtk 项目吗?
I have a two column TreeView attached to a ListStore. Both columns are CellRenderCombo combo boxes.
When the user selects an entry in the first box, I need to dynamically load a set of options in the second.
For example, the behavior I want is:
On row 0, the user selects "Alphabet" in the first column box.
The second column box is populated with the letters "A-Z".
On row 1, the user selects "Numbers" in the first column box.
The second column box is populated with the numbers "0-9".
On row 2, the user selects "Alphabet" in the first column box.
The second column box is populated with the letters "A-Z".
etc.
Does anyone know how to do this, or seen any open source pygtk or gtk projects that have similar behavior which I can analyze?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要从模型绑定第二个渲染器的
model
属性,例如:其中
M
是存储模型的列号(可能是gtk.ListStore< /代码>)。或者使用任何其他方法来绑定模型列的属性。
然后连接到第一个渲染器的
changed
信号。在回调中,您需要相应地更改用于第二个渲染器组合的模型(即M
列中的值)。我敢打赌,您可以在不同的行中使用相同的模型,即一个用于数字,一个用于字母,而无需创建更多模型,但我不确定。换句话说,回调可能看起来与此类似(store
是主要的gtk.ListStore
,X
是具有第一个值的列组合):First, you need to bind
model
property of the second renderer from the model, like:where
M
is the column number which stores models (likelygtk.ListStore
). Or use any other method of binding properties from model columns.Then connect to the first renderer's
changed
signal. In the callback you need to change the model used for the second renderer's combo (i.e. value in columnM
) accordingly. I'd bet you can use the same models in different rows, i.e. one for numbers, one for letters, without creating more, but I'm not sure. In other words, callback could look similar to this (store
is the maingtk.ListStore
,X
is the column with the value of the first combo):