On Mon, 29 Nov 2004 09:15:06 -0200 Adriano Monteiro
<[EMAIL PROTECTED]> wrote:
> I have a problem about combobox + glade...
>
> I don't know how to insert values, in a combobox generated by glade,
> in my code. This is the code I'm using:
>
> import pygtk
> import gtk
> import gtk.glade
> import gobject
>
> janela = gtk.glade.XML ("/home/adriano/teste/teste.glade", "window1")
>
> lista = gtk.ListStore ( gobject.TYPE_STRING )
>
> lista.append ( [ "testing1" ] )
> lista.append ( [ "testing2" ] )
> lista.append ( [ "testing3" ] )
> lista.append ( [ "testing4" ] )
>
> combo = janela.get_widget ("comboboxentry1")
> combo.set_model ( lista )
>
> gtk.main ()
>
> The glade file has only one widget: a comboboxentry with name:
> comboboxentry1
>
> The fields in the comboboxentry is showed, but I can't see their
> values and it raises an error when I click in a field.
>
> What I'm doing wrong?
You need to add:
combo.set_text_column(0)
That will tell your combo box to use the 1st (and only) column of your
listbox.
Here's the convenience function I use regularly to set ComboBoxes based
on strings. (setup_typeahead and setup_completion are my own functions
to automatically allow you to select an item by typing it in a ComboBox
and to setup a gtk.EntryCompletion widget for all ComboBoxEntry's --
they're irrelevant to your problem :)
def set_model_from_list (cb, list):
"""Setup a ComboBox or ComboBoxEntry based on a list of strings."""
model = gtk.ListStore(str)
for l in list:
model.append([l])
cb.set_model(model)
if type(cb) == gtk.ComboBoxEntry:
cb.set_text_column(0)
# setup_completion(cb)
elif type(cb) == gtk.ComboBox:
cell = gtk.CellRendererText()
cb.pack_start(cell, True)
cb.add_attribute(cell, 'text',0)
# setup_typeahead(cb, 0)
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/