Example #1
0
 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;
 }
/** Initiates a standard combobox-entry. */
function cbe_init(GtkComboBoxEntry $cbe)
{
    $cr = new GtkCellRendererText();
    $cr->set_property("xalign", 0);
    $cr->set_property("yalign", 0);
    $cbe->set_model(new GtkListStore(_TYPE_STRING));
    $cbe->pack_start($cr);
    $cbe->set_attributes($cr, "text", 0);
    $cbe->connect("changed", "cbe_event", $cbe);
}
Example #3
0
$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)
 /**
  * Seta o valor selecionado no combobox
  * 
  * @name set_selected_value($value)
  * @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, 0)) {
             // Seleciona o combo
             //parent::set_active($index);
             parent::set_active_iter($iter);
             return $index;
         }
         // Incrementa o index
         $index++;
     }
     // Retorna falso
     return FALSE;
 }