Home  >  Article  >  Backend Development  >  Developing GUI with PHP_PHP Tutorial

Developing GUI with PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 16:08:25771browse

Environment: W2k+php4.3.1+php/gtk0.5.2
A simple notepad (only files can be opened for modification)
set_time_limit (0);                                                                                                                             Running time

if (!class_exists ("gtk")) // Determine whether 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 ();
$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 window title
$window->connect_object ('destroy', array ('gtk', 'main_quit' )); // Register window events

$vbox = &new GtkVBox (); >

$menuBar = &new GtkMenuBar ();                                                                                                                                                                                                                                                                             > ("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'); $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 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->cancel_button;
$cancel_button->connect_object ('clicked', array ($file, ' destroy'));
$file->show ();
}

$filePath = null;
function openFile ($button, $f) // Function to open a file
{
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);
                                                                                                                                           who’ who who’ who’ who’ who’ who who’ who who’ who who who who’s who who’s’ssigning to,
{
GLOBAL $filePath, $text;
if (is_file ($filePath))
{
$str = $text->get_chars (0, -1);
         $fp = fopen ($filePath, 'w');
    return;
}

$window->show_all ();             // 显示窗体内的所有控件
gtk::main ();                      // 最重要的一句,不可少的
?>

 

附:php/gtk配置

Practical PHP/GTK (reposted)

Diao Yan published on 2002-2-19 15:25 PHP Programming←Return to the page

In the past, PHP was considered to only be used to write server-side programs CGI programs, if PHP can develop GUI (graphical user interface) programs under Windows, do you believe it? Recently, the PHP development team successfully developed PHP bundled with GTK+, so that GUI programs under Windows can be developed.

1. Establish a PHP/GTK operating environment:
In fact, there is no difference between GUI programs and ordinary PHPCGI programs. It is just that PHP/GTK programs generate GUI interfaces from GTK classes. They are also open The source code relies on PHP to parse and create windows. If you have already established a PHP debugging environment, it is relatively simple to install the PHP/GTK environment:
1. Download php_gtk.dll (this dll file is used to parse the GTK code in the PHP source program), and unzip it after downloading Go to the PHP extension directory;
2. Download other PHP/GTK dll files (6 in total), and unzip them into the system32 directory of Windows;
3. Open php.ini, Add the statement "extension=php_gtk.dll" at the bottom of the "Windows Extensions" section of the extension settings. It is recommended to back up php.ini first to avoid failure to modify and invalidate the established PHP running environment;
PHP is now established/ GTK's operating environment. Of course, you can skip the second step and add "dl('php_gtk.dll')" to the first line of each PHP/GTK program source code to dynamically load GTK support.
If you have not set up a PHP running environment, then the installation is simpler:
1. Download the entire PHP/GTK bundled support package, and then unzip them to the PHP4 directory of the c drive;
2 , Copy the dll file under the winnt directory to the system32 directory of Windows, and copy the php.ini file to the Windows directory;
After establishing the operation of PHP/GTK, you can use PHP in command line mode to run it A PHP/GTK program: Enter "c:php4php -q gtkprogrampath" during operation, where "c:php4php" is changed to the path of PHP.EXE, and "gtkprogrampath" is the path of the PHP/GTK program. For example: "c:php4php -q c:php4sampleshello.php" will run the sample "hello world" program included in the PHP/GTK runtime package.

2. Compile PHP/GTK program:
If you make a PHP/GTK application, you also need the other party’s computer to set up a PHP operating environment and use the PHP command line mode to parse it before it can be executed. , that would be too complicated. So how can you compile a PHP/GTK program? After some searching, the author discovered the software PHPCompiler.
PHPCompiler is developed by www.deskcode.com (http://www.deskcode.com/phpcompiler). It can compile PHP into an EXE executable file. It has built-in PHP support. If you want to compile a PHP/GTK program , the operating environment of PHP/GTK must be established (refer to the previous steps). The steps to compile a PHP/GTK program are as follows:
1. Open PHPCompiler (as shown in the picture), select the PHP program source code you want to compile in "Script to", and select the successfully compiled EXE file in "Destination" Path;
2. Click the "Compile" button, and a dialog box will pop up asking for the compilation mode to be used (if it is a PHP/GTK program, select no, if it is a simple PHPCGI program, select yes);
3. Then A dialog box will pop up asking whether to copy the php4ts.dll file to the directory of the compiled EXE file. Select yes.
After the above steps, a PHP/GTK program has been successfully compiled, but there are still several things to pay attention to when compiling a PHP/GTK program:
1. If the compiled executable file needs to be executed, The PC must have several dll files required for the GTK operating environment (the ones downloaded earlier). If you need to make an application, you can copy several dll files to the system32 directory during installation (but like this The program is no longer "green software" ^_^).
2. PHPCompiler itself has very good support for PHP, but some people have tried to use some functions that require extended support, such as "gzopen", etc., which worked fine before compilation, but cannot be used after compilation. In fact, the compiled executable file is equivalent to only the default PHP support (not even GTK support), so if any function that requires extended support is applied in the program, the dll file that supports the function must be dynamically loaded. , such as "dl('php_gtk.dll')", so that no errors will occur after the compilation is completed.
3. When running a compiled executable file, a DOS window will pop up first and then close automatically. Because each GUI window is "drawn" by GTK, there must be that window.
4. Perhaps PHP could not be said to be a true OOP (object-oriented programming) language before, but with PHP/GTK, any window is "drawn" by GTK objects. Without strong OOP skills, it is difficult to Write GUI programs.

3. PHP/GTK resources:
1. http://gtk.php.net: the official website of PHP/GTK; although it is said to be an official website, it is indeed very simple. There is a FAQ and mailing list, almost nothing useful can be found.
2. http://www.phpgtk.com: A PHP/GTK website with a good interface and the latest version information.
3. http://developer.gnome.org/doc/API/gtk/gtkobjects.html: A comprehensive/manual website for PHP/GTK functions and classes, which contains a wealth of PHP/GTK information.
4. http://www.phpuk.org/gtk/: The unofficial version of GTK manual website, simple and easy to understand.

If you think E-texts are ugly, you can also go to zphp.com to download the latest PHP/GTK operating environment and support package.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314812.htmlTechArticleEnvironment: W2k+php4.3.1+php/gtk0.5.2 A simple notepad (can only open files for Modify) ?php set_time_limit (0);//Set the running time if (!class_exists ("gtk"))// Determine whether...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn