Up
index

source: ComboBoxEntry


import gtk

NAME="ComboBoxEntry"

class t_combo_entry(gtk.Window):
	def __init__(self):
		gtk.Window.__init__(self)

		self.set_title("ComboBox")
		self.set_geometry_hints(min_width=200)
		self.connect("destroy", gtk.main_quit)

		self.list = gtk.ListStore(int, str)
		iter = self.list.append( (0, "toto",) )
		self.list.set(iter)
		iter = self.list.append( (1, "toto2",) )
		self.list.set(iter)

		self.combo = gtk.ComboBoxEntry()
		cell = gtk.CellRendererText()
		self.combo.pack_start(cell, True)
		self.combo.add_attribute(cell, 'text', 1)

		self.combo.set_model(self.list)
		self.combo.connect("changed", self.on_combobox_changed)
		
		self.combo.show()
		self.add(self.combo)
		
	def on_combobox_changed(self, widget):
		print "combobox changed"
		iter = widget.get_active_iter()
		model = widget.get_model()

		if iter is not None:
			data_id = model.get_value(iter, 0)
			data_str = model.get_value(iter, 1)
			print "item selected:", data_id, data_str
			child = widget.get_child()
			child.set_text(data_str)

		else:
			print "no item selected"
			 
t = t_combo_entry()
t.show()
gtk.main()

$Id: page.wml,v 1.5 2007-01-04 15:52:08 dakol Exp $

Valid XHTML 1.0! Valid CSS!