-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path00053.php
65 lines (46 loc) · 1.42 KB
/
00053.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
62
63
64
<?php
/**
* PHP-GTK Cookbook
*
* https://andor.com.br/php-gtk/cook/open-a-file-chooser-with-gtkfilechooserdialog
*/
Gtk::init();
$window = new GtkWindow();
$window->set_size_request(500, 500);
$window->set_title("PHP-GTK");
// create container
$vbox = new GtkBox(GtkOrientation::VERTICAL);
$vbox->set_border_width(10);
// simple space on container
$vbox->pack_start(new GtkLabel(""), TRUE, TRUE, 0);
// create the label
$label = new GtkLabel("Choose a file:");
$vbox->pack_start($label, FALSE, TRUE, 5);
// button
$button = GtkButton::new_with_label("Open Dialog");
$vbox->pack_start($button, FALSE, TRUE, 5);
$button->connect("clicked", function() use ($window, $label) {
// configure file selection
$dialog = new GtkFileChooserDialog("Choose a file", $window, GtkFileChooserAction::OPEN, ["Cancel", GtkResponseType::CANCEL, "Ok", GtkResponseType::OK]);
$dialog->set_current_folder($default_path);
// run
$result = $dialog->run();
// get selected file
if($result == GtkResponseType::OK) {
$file = $dialog->get_filenames()[0];
$label->set_text("File: " . $file);
}
// destroy
$dialog->destroy();
});
// simple space on container
$vbox->pack_start(new GtkLabel(""), TRUE, TRUE, 0);
//
$window->add($vbox);
// connect to signal that close program
$window->connect("destroy", function() {
Gtk::main_quit();
});
// show all and start
$window->show_all();
Gtk::main();