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; }
/** * Class Constructor * @param $name widget's name */ public function __construct($name) { parent::__construct($name); $this->widget = GtkComboBox::new_text(); parent::add($this->widget); // create the combo model $this->model = new GtkListStore(GObject::TYPE_STRING, GObject::TYPE_STRING); $this->widget->set_model($this->model); $this->setSize(200); }
public function __construct() { parent::__construct(); parent::set_title('Incluir'); parent::connect_simple('destroy', array('Gtk', 'main_quit')); parent::set_default_size(400, 240); parent::set_border_width(10); parent::set_position(GTK::WIN_POS_CENTER); $vbox = new GtkVBox(); $this->labels['id'] = new GtkLabel('Código:'); $this->campos['id'] = new GtkEntry(); $this->campos['id']->set_size_request(80, -1); $this->labels['nome'] = new GtkLabel('Nome: '); $this->campos['nome'] = new GtkEntry(); $this->campos['nome']->set_size_request(240, -1); $this->labels['endereco'] = new GtkLabel('Endereço: '); $this->campos['endereco'] = new GtkEntry(); $this->campos['endereco']->set_size_request(240, -1); $this->labels['telefone'] = new GtkLabel('Telefone: '); $this->campos['telefone'] = new GtkEntry(); $this->campos['telefone']->set_size_request(140, -1); $this->labels['id_cidade'] = new GtkLabel('Cidade: '); $this->campos['id_cidade'] = GtkComboBox::new_text(); $this->campos['id_cidade']->set_size_request(240, -1); $this->campos['id_cidade']->insert_text(0, 'Porto Alegre'); $this->campos['id_cidade']->insert_text(1, 'São Paulo'); $this->campos['id_cidade']->insert_text(2, 'Rio de Janeiro'); $this->campos['id_cidade']->insert_text(3, 'Belo Horizonte'); foreach ($this->campos as $chave => $objeto) { $hbox = new GtkHBox(); $hbox->pack_start($this->labels[$chave], false, false); $hbox->pack_start($this->campos[$chave], false, false); $this->labels[$chave]->set_size_request(100, -1); $this->labels[$chave]->set_alignment(1, 0.5); // xAlign, yalign (0.5, 1) $vbox->pack_start($hbox, false, false); } $vbox->pack_start(new GtkHSeparator(), true, true); // cria uma caixa de botões $buttonbox = new GtkHButtonBox(); $buttonbox->set_layout(Gtk::BUTTONBOX_START); // cria um botão de salvar $botao = GtkButton::new_from_stock(Gtk::STOCK_SAVE); // conecta o botão ao método onSaveClick() $botao->connect_simple('clicked', array($this, 'onSaveClick')); $buttonbox->pack_start($botao, false, false); // cria um botão de fechar a aplicação $botao = GtkButton::new_from_stock(Gtk::STOCK_CLOSE); $botao->connect_simple('clicked', array('Gtk', 'main_quit')); $buttonbox->pack_start($botao, false, false); $vbox->pack_start($buttonbox, false, false); parent::add($vbox); // exibe a janela parent::show_all(); }
/** * Class Constructor * @param $name widget's name */ public function __construct($name) { parent::__construct(); $this->widget = GtkComboBox::new_text(); // create the combo model $this->model = new GtkListStore(GObject::TYPE_STRING, GObject::TYPE_STRING); $this->widget->set_model($this->model); $this->widget->set_size_request(200, -1); $this->wname = $name; parent::add($this->widget); $this->validations = array(); }
function create_option_menu($options) { // $option_menu = new GtkComboBox(); // $model = new GtkListStore(Gtk::TYPE_STRING); // $option_menu->set_model($model); $option_menu = GtkComboBox::new_text(); foreach ($options as $option) { // $iter = $model->append(); // $model->set($iter, 0, $option); $option_menu->append_text($option); } $option_menu->set_active(0); return $option_menu; }
function createComboBox($basewidget, $basefunction, $strConstants) { $combo = GtkComboBox::new_text(); $type = substr($strConstants, 0, strpos($strConstants, '::')); $name = substr($strConstants, strpos($strConstants, '::') + 2); $r = new ReflectionClass($type); $arConstants = $r->getConstants(); foreach ($arConstants as $id => $value) { if (substr($id, 0, strlen($name)) == $name) { $combo->insert_text($value, $type . '::' . $id); } } $function = 'get_' . $basefunction; $combo->set_active($basewidget->{$function}()); $combo->connect('changed', array($this, 'set_combobox'), $basewidget, 'set_' . $basefunction); return $combo; }
/** * Class Constructor * @param $name widget's name * @param $text widget's name */ public function __construct($name, $text_name) { parent::__construct($name); $this->widget = new GtkHBox(); parent::add($this->widget); $this->text_name = $text_name; // create the combo model $this->model = new GtkListStore(GObject::TYPE_STRING, GObject::TYPE_STRING); $this->entry = new GtkEntry(); $this->entry->set_size_request(50, 25); $this->entry->set_sensitive(FALSE); $this->combo = GtkComboBox::new_text(); $this->combo->set_model($this->model); $this->combo->set_size_request(200, -1); $this->combo->connect_simple('changed', array($this, 'onComboChange')); $this->widget->pack_start($this->entry); $this->widget->pack_start($this->combo); }
$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 process GtkComboBox"); $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 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
<?php // FIXED by Christian on 2006-03-06 $cmb = new GtkComboBox(); $mod = new GtkListStore(Gtk::TYPE_STRING); $cmb->set_model($mod); $mod->append(array("one")); $mod->append(array("two")); $mod->append(array("three")); $cmb->set_active(1); //that should return an iter, not require one var_dump($cmb->get_active_iter());
/** * Seta o valor selecionado no combobox * * @name set_selected_value($value) * @param string $value Valor que será selecionado * @return int */ public function set_selected_value($value) { $index = 0; // Percorre os valores foreach ($this->__widgets['model'] as $row) { // Busca o iter $iter = $row->iter; // Verifica se o valor é igual o iter if ($value == $this->__widgets['model']->get_value($iter, 1)) { // Seleciona o combo //parent::set_active($index); parent::set_active_iter($iter); return $index; } // Incrementa o index $index++; } // Retorna falso return FALSE; }
$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 GtkComboBox with label-value pair"); $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); $vbox->pack_start($hbox = new GtkHBox(), 0, 0); $hbox->pack_start(new GtkLabel('Select: '), 0, 0); // the month label-value pair $month_options = array('Januaary' => '01', 'February' => '02', 'March' => '03', 'April' => '04', 'May' => '05', 'June' => '06', 'July' => '07', 'August' => '08', 'September' => '09', 'October' => '10', 'November' => '11', 'December' => '12'); // Create a combobox $combobox = GtkComboBox::new_text(); // note 2 // populates the options foreach ($month_options as $label => $value) { $combobox->append_text($label); // note 3 } // 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); // 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); }