-
Notifications
You must be signed in to change notification settings - Fork 1
/
00019.php
61 lines (44 loc) · 1.34 KB
/
00019.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* PHP-GTK Cookbook
*
* https://andor.com.br/php-gtk/cook/how-to-use-gtkcombobox
*/
Gtk::init();
$window = new \GtkWindow();
$window->set_size_request(500, 500);
// create a box
$vbox = new \GtkBox(GtkOrientation::VERTICAL);
// create the label and add to the box
$label = new \GtkLabel("User");
$vbox->pack_start($label, FALSE, TRUE, 0);
// create model
$model = new GtkListStore(GObject::TYPE_INT, GObject::TYPE_STRING);
// add some values
$model->append([1, "scorninpc"]);
$model->append([2, "admin"]);
$model->append([3, "bruno"]);
// create the GtkComboBox
$combo = GtkComboBox::new_with_model($model);
// add column
$renderer = new GtkCellRendererText();
$combo->pack_start($renderer, TRUE);
$combo->add_attribute($renderer, "text", 1);
// $combo->set_id_column(1);
$vbox->pack_start($combo, FALSE, TRUE, 0);
// connect to change signal
$combo->connect("changed", function($widget) {
// get model and selected iter
$model = $widget->get_model();
$iter = $widget->get_active_iter();
// get values of model
$iduser = $model->get_value($iter, 0);
$user = $model->get_value($iter, 1);
var_dump("User " . $user . " with id " . $iduser);
});
// add a label only to complete the window area
$vbox->pack_start(new GtkLabel(""), TRUE, TRUE, 0);
// add box to window
$window->add($vbox);
$window->show_all();
Gtk::main();