Op dinsdag 03-03-2009 om 17:07 uur [tijdzone +0100], schreef Johannes
Bauer:

[..]

> Is there no easier way than manually creating the combobox at runtime?
> Can I somehow convince Glade to create a combobox in the variant you
> presented?

Perhaps what confuses you is the fact that there is no real difference
between creating the widget at runtime or getting it from the gladefile.
In the above example, where Walter wrote:

    combo = gtk.ComboBox()

You could also have:

    gladefile = "test.glade"
    widget_tree = gtk.glade.XML(gladefile)
    combo = widget_tree.get_widget("combobox1")

Same thing, really. The result is a combo object of class gtk.ComboBox.
Then you start filling its list.

I am also just starting out with Python and PyGTK, and I agree that many
aspects of PyGTK are just confusing. Especially everything about
TreeViews seems just way too complicated to me. However, to make sure I
understood everything else in your question and in Walter's reply I just
made this little test program. Perhaps it will give you some ideas.

The gladefile I used here contains nothing but a window with a single
combobox in it.


""" test.py """

import pygtk
import gtk
import gtk.glade

combobox_items = [
    "qwerty",
    "asdfgh",
    "zxcvbn",
]

class Test(object):

    def __init__(self):

        self.gladefile = "test.glade"
        self.widget_tree = gtk.glade.XML(self.gladefile)
        self.widget_tree.signal_autoconnect(self)
        
        self.combobox1 = self.widget_tree.get_widget("combobox1")
        self.liststore = gtk.ListStore(str)
        self.combobox1.set_model(self.liststore)
        
        cellrenderer = gtk.CellRendererText()
        self.combobox1.pack_start(cellrenderer)
        self.combobox1.add_attribute(cellrenderer, 'text', 0)
        
    def run(self):
        
        for item in combobox_items:
            self.liststore.append([item])
        
        gtk.main()


if (__name__ == "__main__"):
    
    t = Test()
    t.run()



-- 
Olav Lavell <olav...@xs4all.nl>

_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to