
f057ea6c99b412bb61b1ae3688ebc04b.ppt
- Количество слайдов: 20
Client-side Applications with PHP Andrei Zmievski & Frank M. Kromann Track: PHP Conference Date: Friday, July 27 Time: 3: 45 pm – 4: 30 pm Location: Fairbanks C&D
PHP a General Scripting Language • • HTML-embeded scripting language Cross platform Rich on functions and extensions Also used for shell scripts
Adding a GUI to PHP • With a GUI it is possible to write client side applications and tools. • PHP becomes event driven.
What is GTK • GTK+ A multi platform toolkit for creating graphical user interfaces. • Glib Provides useful data types, type convertsions, macros, string utilites etc. • GDK A wrapper for low-level windowing functions. • GTK An advanced widget set.
Automated code generation • The source code for the php-gtk extension is generated from a set of definition files. • 600 constant definitions • 95 Objects • 970 Methods
Web applications • Request driven • Procedural execution • Tight integration with the web server
Event driven applications • • Setup main window Create functions Connect functions to events Start the main loop
Loading the extension • PHP-GTK is not a built-in extension php // this file is used to make sure the gtk-extension is loaded. if (!extension_loaded("gtk")) { if (strtoupper(substr(PHP_OS, 0, 3) == "WIN")) dl("php_gtk. dll"); else dl("php_gtk. so"); } ? >
Creating Gtk objects • The syntax for creating an object is: – $window = &new Gtk. Window(); • With globals in functions use: – $GLOBALS[”window”] = &new Gtk. HBox()
Hello World #!/cygdrive/d/php 4/php_win php require "gtk. inc"; $window_width = 500; $window_height = 200; $window_xpos = (Gdk: : screen_width() - $window_width) / 2; $window_ypos = (Gdk: : screen_height() - $window_height) / 2; $main_window = &new Gtk. Window(); $main_window->connect('destroy', 'destroy'); $main_window->set_policy(TRUE, FALSE); $main_window->set_title("Gtk+ Hello World"); $main_window->set_uposition($window_xpos, $window_ypos); $main_window->set_usize($window_width, $window_height); $main_window->show_all(); Gtk: : main(); ? >
connect('clicked', 'destroy'); $close_button->show();" src="https://present5.com/presentation/f057ea6c99b412bb61b1ae3688ebc04b/image-11.jpg" alt="Add a close-button … $main_window->set_usize($window_width, $window_height); $close_button = &new Gtk. Button("Close"); $close_button->connect('clicked', 'destroy'); $close_button->show();" />
Add a close-button … $main_window->set_usize($window_width, $window_height); $close_button = &new Gtk. Button("Close"); $close_button->connect('clicked', 'destroy'); $close_button->show(); $main_window->add($close_button); $main_window->show_all(); …
Connecting Signals • Signals are used to connect user actions and system events with php-functions. • Examples: – ’clicked’ signals on buttons. – ’destroy’ signals on windows.
Callback function • Names are case-insensitive • Names are passed as strings (lowercase) • The object emitting the signal is the first parameter, can be changed with the connect_object() method. • Additional parameters can be added
Popup Messagebox() $main_window = &new Gtk. Window(); $main_window->set_position(GTK_WIN_POS_CENTER); $main_window->connect('destroy', 'destroy'); $main_window->set_policy(TRUE, FALSE); $main_window->set_title("Gtk+ Hello World"); $main_window->set_usize($window_width, $window_height); function Confirm_Quit($calling_button) { if (Message. Box("Do you realy want to quit ? ", "System Message", MB_YES | MB_NO) == MB_YES) destroy(); } $close_button = &new Gtk. Button("Close"); $close_button->connect('clicked', 'confirm_quit'); $close_button->show(); $main_window->add($close_button); $main_window->show_all(); Gtk: : main();
The gtk. php sample • Shows basic and advanced features • How to use Gtk objects – Gtk. Window, Gtk. Button, Gtk. Clist – Gtk. Cursor, Gtk. Ctree, Gtk. Entry, Gtk. Label – Gtk. Pixmap, Gtk. Radio. Button, Gtk. Tooltips
Database Manager • • Manage local or remote DBMS View status of databases Start and stop databases Demo
DB Query Tool • • • A simple SQL tool Executing SQL Statements Exporting data Cross platform Support for mulitple databases Demo
Related technologies • lib. Glade • …
Future Development • Adding support for aditional functions • Compiling php-gtk as a built-in ext. • Documentation
More Information • http: //gtk. php. net • http: //www. gtk. org • http: //josefine. ben. tuwien. ac. at/~mfischer/ar ticles/article-php-gtk. html