/** * @name __construct() * @return GtkComboBox */ public function __construct() { // Cria o model $this->__widgets['model'] = new GtkListStore(Gobject::TYPE_STRING, Gobject::TYPE_PHP_VALUE); // Cria o combo parent::__construct($this->__widgets['model']); // Cria o render $this->__widgets['render'] = new GtkCellRendererText(); parent::set_model($this->__widgets['model']); parent::pack_start($this->__widgets['render']); parent::set_attributes($this->__widgets['render'], "text", 0); }
$hbox->pack_start(new GtkLabel('Select: '), 0, 0); // Create a combobox $combobox = new GtkComboBox(); // Create a model if (defined("GObject::TYPE_STRING")) { $model = new GtkListStore(GObject::TYPE_STRING); } else { $model = new GtkListStore(Gtk::TYPE_STRING); } // Set up the combobox $combobox->set_model($model); // note 1 $cellRenderer = new GtkCellRendererText(); // note 2 $combobox->pack_start($cellRenderer); $combobox->set_attributes($cellRenderer, 'text', 0); // note 3 // Stuff the choices in the model foreach ($list as $choice) { $model->append(array($choice)); } // Set up a hbox to contain the combobox as well as the Submit button $hbox->pack_start($combobox, 0, 0); $hbox->pack_start(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 4 // The callback function that is called when user clicks the submit button function on_button($button, $combobox)
/** * Used for settings up a GtkComboBox() without writing tons of code. * @param GtkComboBox $cb The GtkComboBox() which should be initialized. */ function combobox_init(GtkComboBox $cb){ $cellRenderer = new GtkCellRendererText(); $cb->set_model(new GtkListStore(_TYPE_STRING)); $cb->pack_start($cellRenderer); $cb->set_attributes($cellRenderer, "text", 0); }