200 likes | 344 Views
Client-side Applications with PHP. Andrei Zmievski & Frank M. Kromann. Track: PHP Conference Date: Friday, July 27 Time: 3:45pm – 4:30pm Location: Fairbanks C&D. PHP a General Scripting Language. HTML-embeded scripting language Cross platform Rich on functions and extensions
E N D
Client-side Applications with PHP Andrei Zmievski & Frank M. Kromann Track: PHP Conference Date: Friday, July 27 Time: 3:45pm – 4:30pm 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. • GlibProvides useful data types, type convertsions, macros, string utilites etc. • GDKA wrapper for low-level windowing functions. • GTKAn 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 GtkWindow(); • With globals in functions use: • $GLOBALS[”window”] = &new GtkHBox()
Hello World #!/cygdrive/d/php4/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 GtkWindow(); $main_window->connect('destroy', 'destroy'); $main_window->set_policy(TRUE, 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(); ?>
Add a close-button … $main_window->set_usize($window_width, $window_height); $close_button = &new GtkButton("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 GtkWindow(); $main_window->set_position(GTK_WIN_POS_CENTER); $main_window->connect('destroy', 'destroy'); $main_window->set_policy(TRUE, TRUE, FALSE); $main_window->set_title("Gtk+ Hello World"); $main_window->set_usize($window_width, $window_height); function Confirm_Quit($calling_button) { if (MessageBox("Do you realy want to quit ?", "System Message", MB_YES | MB_NO) == MB_YES) destroy(); } $close_button = &new GtkButton("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 • GtkWindow, GtkButton, GtkClist • GtkCursor, GtkCtree, GtkEntry, GtkLabel • GtkPixmap, GtkRadioButton, GtkTooltips
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 • libGlade • …
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/articles/article-php-gtk.html