[pygtk] Trouble getting a ListStore with dynamic column number.

Neil Dugan pygtk at butterflystitches.com.au
Fri Feb 1 09:37:37 WST 2008


Stephen George wrote:
> Neil Dugan wrote:
> 
>> Hi,
>>
>> I am trying to create a dialog with a gtk.TreeView() with a 
>> gtk.ListStore() model.  I don't know until run time how many columns 
>> will be needed.  I have managed to create the TreeView but I haven't 
>> worked out how to populate it.
>>
>> Any help appreciated.
>>
>> Regards Neil.
> 
> Hi Neil,
> 
> I think your problem steams from the line
> 
> dialog._model = gtk.ListStore(object)
> 
> Which I think should be more like
> 
> dialog._model = gtk.ListStore(str,str,str)
> 
> However this does not give you the dynamic nature you desire.
> 
> I don't know the limits of column expansion/contraction you require for 
> your problem, .. but I see in your code you want to limit it to 20
> (are they always strings?, or all columns the same type?)
> 
> I would create a listStore with 20 str as arguments.
> 
> I would then create the treeview with as many columns needed for the 
> problem at hand
> 
> Attached you will see a modified prog that works for me, I limited the 
> columns to 7, each time you press the dialog button, a list is 
> dynamically generated with a random number of columns.
> Assumptions:
> the list is always strings.
> length of list correlates to number of colomns to view.
> 
> Don't know if this has been helpful?
> 
> Steve
> 
> 

Hi Steve,

Thanks, that does do what I want.  :)

After posting I found out that, that line was the trouble, but I 
couldn't find a decent way of handling the problem.  I didn't realise 
you could specify more types when creating the gtk.ListStore than you 
had intentions of using.

I think it would be handy to be able to use a list or truple to 
specify the types as well.

Regards Neil.


More information about the pygtk mailing list