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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| <?php $window = new GtkWindow(); $window->set_size_request(480, 160); $window->connect_simple('destroy', array('Gtk','main_quit')); $window->add($vbox = new GtkVBox());
// display title
$title = new GtkLabel("Retain control of Popup Dialogs"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $title->set_size_request(-1, 40); $title->set_justify(Gtk::JUSTIFY_CENTER); $alignment = new GtkAlignment(0.5, 0, 0, 0); $alignment->add($title); $vbox->pack_start($alignment, 0, 0); $vbox->pack_start(new GtkLabel(), 0, 0);
// setup button
$hbox = new gtkHBox(); $vbox->pack_start($hbox, 0);
$hbox->pack_start(new GtkLabel( " Press the Edit button to display the edit dialog: "), 0); $button = new Gtkbutton(" Edit "); $button->connect('clicked', 'on_edit_button'); $hbox->pack_start($button, 0);
$label_font = new GtkLabel(); $label_path = new GtkLabel(); $vbox->pack_start($label_font); $vbox->pack_start($label_path);
$window->show_all(); Gtk::main();
function on_edit_button($button) { global $label_font, $label_path; $prompt = new Prompt(); // note 1
$font = $prompt->entry_font->get_text(); // note 4
$path = $prompt->entry_path->get_text(); // note 5
$label_font->set_text("font: $font"); // note 6
$label_path->set_text("path: $path"); // note 6
}
// wrapper for class GetFont
function get_font() { // note 1
$getfont_dialog = new GetFont(); // note 2
$font_name = $getfont_dialog->main(); return $font_name; }
class GetFont{ // note 1
function GetFont() { $dialog = new GtkFontSelectionDialog('Select Font'); $this->dialog = $dialog; $dialog->show_all(); }
function main() { $this->dialog->run(); $fontname = $this->dialog->get_font_name(); $this->dialog->destroy(); return $fontname; } }
class Prompt{
var $entry; // the user input
function Prompt() { $dialog = new GtkDialog('Prompt', null, Gtk::DIALOG_MODAL); $top_area = $dialog->vbox;
$hbox = new GtkHBox(); $top_area->pack_start($hbox, 0, 0); $hbox->pack_start(new GtkLabel('Font: '), 0); $this->entry_font = new GtkEntry(); $hbox->pack_start($this->entry_font, 0, 0); $hbox->pack_start(new GtkLabel(' '), 0, 0); $hbox->pack_start($font_button = new GtkButton('Select Font'), 0, 0); $font_button->connect('clicked', array($this, 'on_button_font'));
$hbox2 = new GtkHBox(); $top_area->pack_start($hbox2, 0, 0); $hbox2->pack_start(new GtkLabel('Path: '), 0); $this->entry_path = new GtkEntry();
|