Developing the GUI with PHP (a simple example)

Source: Internet
Author: User
Tags array exit functions gtk return window
Environment: w2k+php4.3.1+php/gtk0.5.2
A simple Notepad (you can only open files for modification)
<?php
Set_time_limit (0); Set run time

if (!class_exists ("GTK"))//Determine if there is a GTK module
if (Strtoupper substr ($_server["OS", 0, 3)) = = "WIN")
DL ("Php_gtk.dll");
Else
DL ("php_gtk.so");

$window = &new Gtkwindow (); Build a Window
$window->set_uposition (100, 100); Where the window appears
$window->set_usize ((Gdk::screen_width () -200), (Gdk::screen_height ()-150)); Window size
$window->set_title ("WINDOWS"); Set window title
$window->connect_object (' Destroy ', Array (' GTK ', ' main_quit ')); Registering the window's events

$vbox = &new Gtkvbox ();
$hbox = &new Gtkhbox ();
$window->add ($vbox);


$menuBar = &new Gtkmenubar (); Create a Menu
$vbox->pack_start ($menuBar, False, False, 0);

$file = &new Gtkmenuitem ("file");
$menuBar->append ($file);

$fileMenu = &new Gtkmenu ();
$open = &new Gtkmenuitem ("open");
$save = &new Gtkmenuitem ("Save");
$line = &new Gtkmenuitem ();
$line->set_sensitive (TRUE);
$exit = &new Gtkmenuitem ("exit");
$fileMenu->append ($open);
$open->connect_object (' Activate ', ' showfileselection ');
$fileMenu->append ($save);
$save->connect_object (' Activate ', ' savefile ');
$fileMenu->append ($line);
$fileMenu->append ($exit);
$exit->connect_object (' Activate ', Array (' GTK ', ' main_quit '));

$file->set_submenu ($fileMenu);

$scroll = &new Gtkscrolledwindow ();
$scroll->set_border_width (8);
$scroll->set_policy (gtk_policy_automatic, gtk_policy_automatic);
$hbox->pack_start ($scroll, True, true, 0);
$vbox->pack_start ($hbox, True, true, 1);

$text = &new Gtktext ();
$text->set_editable (TRUE);
$text->set_word_wrap (TRUE);
$scroll->add ($text);

function showfileselection ()//File selection functions
{
$file = &new gtkfileselection ("File Selection");
$ok _button = $file->ok_button;
$ok _button->connect (' clicked ', ' OpenFile ', $file);
$ok _button->connect_object (' clicked ', Array ($file, ' destroy '));
$cancel _button = $file->cancel_button;
$cancel _button->connect_object (' clicked ', Array ($file, ' destroy '));
$file->show ();
}

$filePath = null;
function OpenFile ($button, $f)//Open file functions
{
GLOBAL $text, $save, $filePath;
$filePath = $f->get_filename ();
if (Is_file ($filePath))
{
$fp = fopen ($filePath, ' R ');
while (!feof ($FP))
$str. = Fgets ($fp, 1024);
$text->insert (null, NULL, NULL, $STR);
Fclose ($FP);
return $filePath;
}
}

function SaveFile ()//Saving file functions
{
GLOBAL $filePath, $text;
if (Is_file ($filePath))
{
$str = $text->get_chars (0,-1);
$fp = fopen ($filePath, ' w ');
Fwrite ($fp, $STR);
Fclose ($FP);
}
Return
}

$window->show_all (); Display all controls in the body of a window
Gtk::main (); The most important one, not less.
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.