PHP-GTK Introduction and its Application _php tutorial

Source: Internet
Author: User
Tags gtk
1. PHP-GTK Introduction 1.1 PHP-GTK php-gtk is an extension module for PHP that allows programmers to write programs that are executed on a client-side, independent GUI. This module does not allow GTK + programs to be viewed on the browser, it was developed to write a standalone GUI program at the outset. 1.2 GTK GTK was originally developed for GIMP, a GUI for image processing software. GTK + is a suite tool for GIMP. GTK + has evolved from here until now it has become the center of GNOME (Gnome is a desktop environment). GTK + has also been extended to BeOS and Win32, making it the best choice for PHP extension modules, maintaining PHP's ability to cross-platform and use PHP to develop Windows interface programs for platforms such as Linux,beos,windows. 2. PHP-GTK Concept 2.1 Preface The next step is to teach you something a little more conceptual. Because the concept of this chapter is very important, so even if you do not understand, it is necessary to slowly understand it, or else after that. Also, the next content is not recommended for readers without programming experience, because there are many ideas that can easily be confused. Also, the next part of the English language I will use in English, so that everyone in the reading of foreign documents will not be overwhelmed, refueling it!! If you have any questions about this chapter, please consult your own PHP-GTK manual:http://gtk.php.net/manual/en/2.2 widget (s) widget is a basic functions and forms in a GUI program. The most commonly used widgets are: Label, button, window, frame, and text box. All widgets come from an abstract basic class─gtkwidget. Each widget is a Class A widget has a lifetime of about five periods: 1. Establishment (Creation): Declares an object (declaring an object) 2. Placement (Placement): add it to a container (adding it to a container) 3. Signal connection (Signal Connection): Receive signal and perform action (the action it'll perform) 4. Display: Whether it is visible (whether it is viewable or not) 5. Delete (destruction): Close Program (closing of a programs) 2.3 Container (s) Container YesA widget that can contain other widgets. Most of the widgets are container, for example: Gtkwindow, gtktable, and Gtkbox. In addition to this, container is no different than the other widgets and can be placed in other container. And all the container come from a class─gtkcontainer, which itself comes from the Gtkwidget class. So container is also one of the widgets. 2.4 Signal (s) when the programmer does an action in the program, the program needs to have an action to respond to the user's actions. The signals enables the program to know that the user has done the action and can trigger the appropriate response. For example, when the user presses a button (Gtkbutton) that opens a new window, the program recognizes the request and opens a new window. The matter can be done by signal. When the button is pressed, the widget emits a signal, and then the signal triggers the callbacks, creating a new Window (Gtkwindow). 2.5 Callback (s) Callback is the function that is awakened by the signal when signal is sent out. Callback performs a function to return a value or to do an action. Callback is signal's handler Funciton. It can be a preset handler of the signal or a function defined by the programmer. To create a callback, you must connect the function to signal. 2.6 Signal Inheritance (inheritance) and methods, signals can be inherited by objects. A widget can send out any of its parent widgets and its own unique signal. 2.7 Connecting signals you must specify a callback function for PHP-GTK to respond to signal when signal is sent out. Connecting a signal to a function can be achieved using the Connect () object method. As follows: Connect ("Destroy", "shutdown"); Create a Gtkbutton, button text for "Press Me" $button = &new Gtkbutton ("Press Me"); $button->connect ("clicked", "you_clicked"); Put Gtkbutton into the Gtkwindow of container $window->add ($button); Displays the $window and all of its child widgets $window->show_all (); Enter the main loop of the program (that is, the program starts) Gtk::main ();?> executes it, a window appears with a button that says "Press me" and a you_clicked function is executed by pressing the button. In this program, the "destroy" signal of the $window object is sent when the user presses the "X" in the upper-right corner of the window, while the "clicked" signal of the $button object is sent when the user presses the button. The last line of the Gtk::main () is necessary to execute, so as to tell the computer to start executing the program, since there is a beginning to execute, then there must be a stop it? Yes, you can stop the program with Gtk::main_quit (). After reading the above example, some readers may wonder, "What if I want to do a widget that's outside of the signal widget?", at this point, we're going to use another method, a connect_object (), It can call methods across objects or pass other objects as three numbers of function. The cross-object call method is as follows: $window->connect_object ("Destroy", Array ("GTK", "Main_quit")) So, the "destroy" of the $window object When the signal is sent out, it evokes the gtk::main_quit () method, and the program will eventually refer to execution. At the end of the introduction to the connection method, mention the way that the custom increase of connect () and Connect_object () is passed to the callback function. See Example: Connect ("Clicked", "Who_are_you", $parameter); $button 2 = &new Gtkbutton ("Test Two"); Connect the "clicked" signal to the Kill_the_button1 function with three additional $button1 $button 2->connect_object ("clicked", "Kill_the_button1", $ button1); function Who_are_you ($widget, $parameter) {echo $parameter;} function Kill_the_button ($button) {$button->destroy () ; ?> Note that the two function,who_are_you have two three, right? What's the first thing to do? Why does it automatically appear?? Because, each signal callback function will be due to signal different and some of the default will be passed to the callback function of the three, and basically all signal will be passed at least callback Function a three-number-a object that produces the signal. So Who_are_you's first three numbers are $button1, and the second one is $parameter, the new Superman. That Kill_the_button function is not the same Luo ~ because Connect_object () function will call the original signal callback function preset three numbers, so Kill_the_button is only attached to connect_ The last $button1 of object, so that Kill_the_button can call $button1 method or get its properties, here called the Destroy method of $button1, $button1 will be destroyed. The 2.8 event (s) event is one of the signal, but its purpose and functionality are very powerful. As far as signal, signal this kind of thing is built on the widget, so, for example Gtkwindow does not have "clicked" signal, then in the case of no event signal, Gtkwindow is the impossible to send out clicked such signal. What if we use the event signal? Event signal is allowed to be added to any WIdget, so even if the widget does not emit the "clicked" signal function, you can also use Add_events () to add a response to the event signal after it has been pressed. The event signal contains a lot of information, such as when you use the "key-press-event" event signal, but also record what button you pressed, the usual event signal callback The function format will have two three numbers, the first one is still sent out signal widget, and the second is $event, the $event is a class, the properties and methods will be sent over the event signal the kind of different. In terms of the $event class returned by "Key-press-event", there is a property in Keyval which is the content of which key the user presses. These are often useful information for a programmer. So the importance of the event can not be ignored, even if the beginning will be a little confused, but also slowly into the line. This section is also very important. 3. Install PHP-GTK 3.1 Install under Windows system first to download from http://gtk.php.net/download.php ... HP-GTK's Windows Binary Archive (version 0.5.1 When this article is written). Then take a look at the contents of php-gtk 0.5.1 binary file: php4→php and php-gtk binary files winnt→ preset php.ini files winntsystem32→gtk binaries used by ex Tension test→ Several test files readme.txt→ installation instructions start the installation: 1. Copy the contents of the PHP4 to your PHP installation directory (example c:php). 2. Copy the contents of the Winnt to your Winnt folder. On Windows NT or Windows2000 is C:winnt, on Window95, 98, XP is c:windows. If the folder already has php.ini, then do not do this action. 3. Copy the contents of the Winntsystem32 to your Winntsystem32 folder. On Windows NT or Windows2000 is C:winntsystem32, on Window95, 98, XP is C:windowssystem32. 4. Copy the contents of test to the place where you want to execute your script (this step is not necessary). How to execute the PHP-GTK program: The PHP-GTK program can be launched under "Start"-"Execution" (or create a shortcut), such as: C:phpphp-q c:phptestgtk.php # # means not to send out the HTTP Header, but always use this window, Until you close the program. C:phpphp-q-C php.ini c:gtk.php # # IBID., but performs the specified php.ini settings. c:phpphp c:phptestgtk.php # # indicates that the HTTP Header will be printed, but always use this window until the program is closed C:phpphp_win c:phptestgtk.php # # means not to use Windows, execute a separate execution program, He uses the PHP-Q mode, but it stops execution whenever output of any character, such as an error message, is produced. 3.2 Users who install Debian under UNIX systems can download php-gtk binary files from the http://www.debian.org. The system requirements must have been installed in the following package:php 4.1.0 or later versions, which have to be compiled into the CGI binary (command-line) version, including all headers files and devlement scripts. PHP-GTK supports GTK + v1.2 and requires the installation of 1.2.6 + versions of GTK +. GTK + v2.0 is not yet supported and must wait until it is developed and

http://www.bkjia.com/PHPjc/531984.html www.bkjia.com true http://www.bkjia.com/PHPjc/531984.html techarticle 1. PHP-GTK Introduction 1.1 PHP-GTK php-gtk is an extension module for PHP that allows programmers to write programs that are executed on a client-side, independent GUI. This module is not allowed to display on the browser ...

  • 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.