GtkComboBox standard constructor example

From: Date: Mon, 06 Feb 2006 21:25:38 +0000
Subject: GtkComboBox standard constructor example
Groups: php.gtk.doc 
Request: Send a blank email to php-gtk-doc+get-1826@lists.php.net to get a copy of this message
Just thought somebody might get some use out of the following example of the usage for the standard GtkComboBox constructor. I searched high and low for the usage, but all I found were examples on the GtkComboBox::new_text (); As usual, cleanup and use as required. $data = array (array ('Key1', 'Item1'), array ('Key2', 'Item2'), array ('Key3', 'Item3')); $win1 = new GtkWindow (); $win1->connect_simple ('destroy', 'quit', $win1); $win1->add ($box1 = new GtkVBox (false, 4)); $win1->set_size_request (150, 150); $box1->pack_start ($combo = new GtkComboBox (), false, false); $box1->pack_start ($label = new GtkLabel ('')); $box1->pack_start ($align = new GtkAlignment (.5, .5, .5, .5), false, false); $align->add ($button = GtkButton::new_from_stock ('gtk-close')); $button->connect_simple ('clicked', 'quit', $win1); // Here's the magic :-) $combo->set_model ($model = new GtkListStore (Gtk::TYPE_STRING, Gtk::TYPE_STRING)); $combo->pack_start ($cr = new GtkCellRendererText (), 0); $combo->set_attributes ($cr, 'text', 1); $combo->connect ('changed', 'combo_change', $label, $data); foreach ($data as $i) $model->append ($i); $win1->show_all (); Gtk::main (); function quit ($win) { $win->destroy (); Gtk::main_quit (); } function combo_change ($combo, $label, $data) { $label->set_text ("Key = " . $data[$combo->get_active ()][0] . "\n" . "Value = " . $data[$combo->get_active ()][1]); }

« previous php.gtk.doc (#1826) next »