Developing GUI with PHP (a simple example)

xiaoxiao2021-03-06  70

Environment: W2K PHP4.3.1 php / gtk0.5.2

A simple notepad (you can only modify the file)

SET_TIME_LIMIT (0); // Set the run time

IF (! Class_exists ("gtk")) // Deconstimate whether there is a GTK module

IF (SUBSTOUPPER (Substr ($ _SERVER ["OS"], 0, 3)) == "WIN")

DL ("php_gtk.dll");

Else

DL ("php_gtk.so");

$ Window = & new gtkwindow (); // Building a window

$ window-> set_uposition (100, 100); // Window appearance position

$ window-> set_usize ((GDK :: Screen_Width () - 200), (GDK :: Screen_HEIGHT () - 150)); // Window Size

$ window-> set_title ("windows"); // Set the window title

$ Window-> Connect_Object ('Destroy', Array ('gtk', 'main_quit')); // Register the event

$ 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; $ hbox-> pack_start ($ scroll, true, true, 0);

$ VBOX-> PACK_START ($ HBOX, TRUE, TRUE, 1);

$ TEXT = & new gtktext ();

$ text-> set_editable;

$ text-> set_word_wrap (true);

$ Scroll-> Add ($ text);

Function showfileselection () // file selection function

{

$ 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-> can_button;

$ CANCEL_BUTTON-> Connect_Object ('Clicked', Array ($ File, 'Destroy');

$ FILE-> show ();

}

$ filepath = null;

Function OpenFile ($ Button, $ f) // Opens the file function

{

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 () / / Save Function

{

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 form

Gtk :: main (); // The most important sentence, essential

?>

转载请注明原文地址:https://www.9cbs.com/read-87820.html

New Post(0)