tags:

views:

34

answers:

1

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?

A: 

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)
    ...
doublep
Close, needed to connect cursor_changed, and the handler changed the content based on the column everytime someone selected a row.
Präriewolf