Please respond to the list.

The combobox only shows up when you click on the cell to edit it. If you are expecting to see an arrow icon in each cell that is a combo box you won't, I think that would get pretty messy and am glad it is not there.

John Wood wrote:
Thank you for your response.

I got the code working almost the way I wanted. The only thing is that
I the actual widget is not visible. Is this the expected behavior? I
was under the impression that I would have a gtk.ComboBox in each of
the cells in the TreeViewColumn.

I include the current version of the sample program to show the "quirk".

#!/usr/bin/env python
import sys

try:
   import pygtk
   pygtk.require("2.6")
except:
   pass

try:
   import gtk, gobject
except:
   sys.exit(1)

class CellRendererExample:
   """ Main class of the application. """

   items = ("item 1",
            "item 2",
            "item 3",
            "item 4",
            "item 5")

   def __init__(self):
       # Create window and connect its destroy signal.
       window = gtk.Window()
       window.connect("destroy", gtk.main_quit)

       # Create and add a treeview widget to the window.
       self.treeview = gtk.TreeView()
       window.add(self.treeview)

       # Create a text column
       column0 = gtk.TreeViewColumn("Text",
                                     gtk.CellRendererText(),
                                     text=0)

       # Create a combobox column
       lsmodel = gtk.ListStore(str)

       for item in self.items:
           lsmodel.append([item])

       cellcombo = gtk.CellRendererCombo()

       cellcombo.set_property("text-column", 0)
       cellcombo.set_property("editable", True)
       cellcombo.set_property("has-entry", False)
       cellcombo.set_property("model", lsmodel)

       cellcombo.connect("edited", self.cellcombo_edited)

       column1 = gtk.TreeViewColumn("Combobox", cellcombo, text=1)

       self.treeview.append_column(column0)
       self.treeview.append_column(column1)

       # Create liststore.
       liststore = gtk.ListStore(str, str)

       # Append a couple of rows.
       liststore.append(["Some text", "Click here to select an item."])
       liststore.append(["More text", "Click here to select an item."])
       liststore.append(["More text", "Click here to select an item."])
       liststore.append(["More text", "Click here to select an item."])
       liststore.append(["More text", "Click here to select an item."])

       # Set model.
       self.treeview.set_model(liststore)

       window.show_all()

   def cellcombo_edited(self, cellrenderertext, path, new_text):
       treeviewmodel = self.treeview.get_model()
       iter = treeviewmodel.get_iter(path)
       treeviewmodel.set_value(iter, 1, new_text)

   def main(self):
       gtk.main()

if __name__ == "__main__":
   cre = CellRendererExample()
   cre.main()

2006/11/6, Kim Novak <[EMAIL PROTECTED]>:
The CellRendererCombo needs to be editable. The drop-down will only
appear when you click on the cell.

cellcombo.set_property("editable", True)

John Wood wrote:
> Hello,
>
> I'm having a hard time using a gtk.CellRendererCombo in my treeview
> widget. The problem is that the combobox widget won't show. I've read
> the pygtk reference a number times and the I get no errors executing
> my code. I've created a small sample program which illustrates my
> problem.
>
> Any help is much appreciated, if someone can point me to a pygtk
> program that uses gtk.CellRendererCombo that would be great.
>
> John
>
> #!/usr/bin/env python
> import sys
>
> try:
>    import pygtk
>    pygtk.require("2.6")
> except:
>    pass
>
> try:
>    import gtk
> except:
>    sys.exit(1)
>
> class CellRendererExample:
>    """ Main class of the application. """
>
>    def __init__(self):
>        # Create window and connect its destroy signal.
>        window = gtk.Window()
>        window.connect("destroy", gtk.main_quit)
>
>        # Create and add a treeview widget to the window.
>        self.treeview = gtk.TreeView()
>        window.add(self.treeview)
>
>        # Create a text column
>        column0 = gtk.TreeViewColumn("Text",
>                                    gtk.CellRendererText(),
>                                    text=0)
>
>        # Create a combobox column
>        cellcombo = gtk.CellRendererCombo()
>
>        model = gtk.ListStore(str)
>
>        for k in range(1,10):
>            model.append(["item_%d" % k])
>
>        cellcombo.set_property("model", model)
>
>        column1 = gtk.TreeViewColumn("Combobox", cellcombo)
>
>        column1.add_attribute(cellcombo, "text-column", 1)
>
>        self.treeview.append_column(column0)
>        self.treeview.append_column(column1)
>
>        # Create liststore.
>        liststore = gtk.ListStore(str, int)
>
>        # Append a couple of rows.
>        liststore.append(["Some text", 0])
>        liststore.append(["More text", 1])
>
>        # Set model.
>        self.treeview.set_model(liststore)
>
>        window.show_all()
>
>    def main(self):
>        gtk.main()
>
> if __name__ == "__main__":
>    cre = CellRendererExample()
>    cre.main()
> _______________________________________________
> pygtk mailing list   [email protected]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to