pyGTK TreeView 中的条件 CellRenderCombo

发布于 2024-08-30 01:47:21 字数 596 浏览 1 评论 0原文

我有一个两列 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱倦旧时光 2024-09-06 01:47:21

首先,您需要从模型绑定第二个渲染器的 model 属性,例如:

gtk.TreeViewColumn ('...', gtk.CellRendererCombo (), text = N, model = M)

其中 M 是存储模型的列号(可能是 gtk.ListStore< /代码>)。或者使用任何其他方法来绑定模型列的属性。

然后连接到第一个渲染器的 changed 信号。在回调中,您需要相应地更改用于第二个渲染器组合的模型(即 M 列中的值)。我敢打赌,您可以在不同的行中使用相同的模型,即一个用于数字,一个用于字母,而无需创建更多模型,但我不确定。换句话说,回调可能看起来与此类似(store 是主要的 gtk.ListStoreX 是具有第一个值的列组合):

def combo1_changed (combo, path, iter):
    main_iter = store.get_iter (path)
    selected  = store.get_value (main_iter, X)
    if selected == 'Alphabet':
        store.set_value (main_iter, M, alphabet_list_store)
    elif selected == 'Numbers':
        store.set_value (main_iter, M, number_list_store)
    ...

First, you need to bind model property of the second renderer from the model, like:

gtk.TreeViewColumn ('...', gtk.CellRendererCombo (), text = N, model = M)

where M is the column number which stores models (likely gtk.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 column M) 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 main gtk.ListStore, X is the column with the value of the first combo):

def combo1_changed (combo, path, iter):
    main_iter = store.get_iter (path)
    selected  = store.get_value (main_iter, X)
    if selected == 'Alphabet':
        store.set_value (main_iter, M, alphabet_list_store)
    elif selected == 'Numbers':
        store.set_value (main_iter, M, number_list_store)
    ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文