PHP
  Home arrow PHP arrow Page 2 - Revisited: Building Cross Platform GUI App...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Revisited: Building Cross Platform GUI Apps With PHP-GTK
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2002-11-17

    Table of Contents:
  • Revisited: Building Cross Platform GUI Apps With PHP-GTK
  • What is PHP-GTK?
  • Downloading and installing PHP-GTK
  • Installing PHP-GTK for Linux
  • Building our first PHP-GTK app
  • Registering multiple callback functions
  • Adding GTK widgets to our window
  • Other PHP-GTK widgets
  • A PHP-GTK database app
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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:
    1. GLib: A library of tools that can be used to assist developers when creating applications with GTK+.
    2. 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.

    More PHP Articles
    More By Mitchell Harper


     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek