Revisited: Building Cross Platform GUI Apps With PHP-GTK - What is PHP-GTK?
(Page 2 of 10 )
Personally, I would call PHP-GTK an excellent set of classes that can be used to build applications containing buttons, windows, toolbars, menus, scroll bars, database access, lists and more. The team that developed PHP-GTK defines it as a PHP extension that allows us to easily write cross-platform GUI based applications.
Funnily enough, PHP-GTK was written to prove that PHP could actually be used to build stuff other than web pages, and let me tell you that they've succeeded.
No doubt you're familiar with the PHP acronym, but what does GTK mean? GTK stands for GIMP tool kit, and it's basically just a set of widgets that we can use to create applications. A widget is the equivalent of a control (such as a button, list box, frame or radio button) in "Linux speak".
GIMP is an acronym for GNU Image Manipulation Program, and is a fully featured graphics editing program that runs on Linux. It has many (if not all) of the features of popular Windows programs such as Photoshop and Paintshop. It's the graphics editor of choice for most Linux users.
GTK is actually part of a set of libraries that was written in C called GTK+. GTK+ was built up over time and is now a main part of Gnome, which is a Linux GUI desktop environment. GTK+ is based on an object-oriented nature and also includes two other libraries:
- GLib: A library of tools that can be used to assist developers when creating applications with GTK+.
- GDK: Similar to GDI for Win32, GDK standard for GIMP drawing kit and wraps a set of lower level drawing functions into classes that make developing applications with GTK+ easier. If you're thinking along the lines of MFC for C++ then you're making a fair comparison: MFC wraps several controls and hides the calls to the underlying Windows API's from the developer. GDK does the same thing for GTK+.
Although GTK is used in many other applications and projects, in terms of PHP-GTK, it's an advanced set of classes which can be referenced to create widgets which we can then manipulate programmatically. PHP-GTK's programming style is similar to event driven programming languages such as Visual Basic and C++ in that it fires off signals. These signals can be captured and specific functions (called callback functions) can be defined to handle them.
I know that we haven't even looked at PHP-GTK yet, but consider the following PHP code:
$button = &new GtkButton("Click me");
$button->connect("clicked", "buttonClicked");In the code above I've instantiated a new GtkButton class. I've then called its connect function passing in two parameters: the name of the signal to capture (clicked) as well as the name of a call-back function to execute when this signal is caught (buttonClicked). This tells PHP-GTK that when the button emits a "clicked" signal, that the buttonClicked function should be called.
So if we added a buttonClicked function like this:
function buttonClicked()
{
echo "You clicked the button";
}Then "You clicked the button" would be echoed to the screen when the button is clicked on. That brings me to another point: PHP-GTK apps are run by calling them up with the normal PHP interpreter. The console window in which you called the PHP-GTK GUI app sits in the background and the app sits on top. While the app is running you can still output to the console window using echo, print, etc.
In my opinion this is excellent, because it means that you can set a debug flag and treat the console window as a debug window, outputting debugging statements when you're building your PHP GTK GUI app. When you're ready to distribute the app, simply set the debug flag to false or remove the echo commands.
Well hopefully now you have a bit of an understanding of what PHP-GTK is. The next step is to actually download and install PHP-GTK, so let's do that now.
Next: Downloading and installing PHP-GTK >>
More PHP Articles
More By Mitchell Harper