function __create_box() { $vbox = new GtkVBox(false, 5); $vbox->set_border_width(5); $combo = GtkComboBox::new_text(); $data = array('PHP-Gtk2', 'is', 'really', 'cool'); foreach ($data as $string) { $combo->append_text($string); } $combo->set_active(2); $button = new GtkButton('Check this'); $vbox->pack_start($combo, false, true); $vbox->pack_start($button, false, true); $button->connect('clicked', array($this, 'onClickedButton'), $combo); //GtkComboBoxEntry $vbox->pack_start(new GtkHSeparator(), false, true); $comboentry = GtkComboBoxEntry::new_text(); $data2 = array('You', 'can', 'edit', 'this', 'box'); foreach ($data2 as $string) { $comboentry->append_text($string); } $comboentry->get_child()->set_text('That\'s an own text for the entry'); $vbox->pack_start($comboentry, false, true); $button2 = new GtkButton('Check that'); $vbox->pack_start($button2, false, true); $button2->connect('clicked', array($this, 'onClickedButton'), $comboentry); return $vbox; }
$window = new GtkWindow(); $window->connect_simple('destroy', array('Gtk', 'main_quit')); $window->set_size_request(400, 150); $window->add($vbox = new GtkVBox()); // display title $title = new GtkLabel("Setup and read value from ComboBoxEntry"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $title->set_size_request(-1, 60); $vbox->pack_start($title, 0, 0); // the selection $list = array('item 1', 'item 2', 'item 3', 'item 4'); $vbox->pack_start($hbox = new GtkHBox(), 0, 0); $hbox->pack_start(new GtkLabel('Select: '), 0, 0); // Create a new comboboxentry and populates it $combobox = GtkComboBoxEntry::new_text(); foreach ($list as $choice) { $combobox->append_text($choice); } $combobox->get_child()->set_text(''); // note 1 $hbox->pack_start($combobox); // Set up the submit butotn $hbox->pack_start($button = new GtkLabel(' '), 0, 0); $hbox->pack_start($button = new GtkButton('Submit'), 0, 0); $button->set_size_request(60, 24); // Set up the event handler to respond to button click $button->connect('clicked', "on_button", $combobox); //note 2 // The callback function that is called when user clicks the submit button function on_button($button, $combobox)