PHP GTK 2

Last time I said I would be writing a Java application. My idea was take some of these php scripts and group them into something that is easier to use for beginners that runs on the desktop.

However… I got to thinking. I said PHP is a powerful language, and is the only language you really need to write some truly powerful applications. So I’m going to write a PHP application that runs not from a web server or the command line but starts up a proper window.

OK, so lets get to this. You need:

Glade (to design the window)
GTK+ windows runtimes (unless you run Linux)
PHP 5 with php_gtk2 extension
My PHP GTK scripts (extract them into the same directory as the php 5 install and then double click start.bat)

You got all those? OK fire up glade and create a window that is to your liking. Like mine below. It will save as something.glade which will be some XML for creating the window.

PHP GTK2 App

Now this is the PHP to create a window… I call it glade_win.php

<?php

// load php gtk2 in
if (!extension_loaded(’php_gtk’)) {
if (strtoupper(substr(PHP_OS, 0, 3)) === ‘WIN’) {
dl(’php_gtk2.dll’);
} else {
dl(’php_gtk2.so’);
}
}

// load the window from our glade .xml file
$glade =& new GladeXML( dirname( __FILE__) . “/wndMain.glade”);

// make sure the window closes when we click close
$glade->get_widget(’wndMain’)->connect_simple(’destroy’, array(’Gtk’, ‘main_quit’));

// execute the gtk main function
gtk::main();

?>

This couldn’t be any more simple. The first bit is necessary to load the DLL in because when it runs on my Linux install it destroys my web server if it has php_gtk2 turned on by default.

The next part creates an object that loads in the XML. We then connect the close button i.e. the cross at the top right hand corner to a quit routine, and then gtk::main(); runs the necessary code to view the window.

My window XML is in my scripts zip. It should give an idea of where I am going with this :D . Hopefully that all worked smoothly for you.

13 Responses to “PHP GTK 2”

  1. Harry Says:

    Notice I made an error in my window :D … That password text box isn’t needed. Doh!

  2. Jorge Says:

    Great subject. I am glad i found your blog. Would you mind sometime maybe adding an
    article to my website so that others may read this too? I think that my visitors would really enjoy the stuff i found here. Thanks and I will visit often.

  3. Smaxor Says:

    GTK is a fun toy to play with for sure. Haven’t found a really good use for it yet as most stuff is made into RIA apps if I need an interface. Which I prefer not to have as interface = manual interaction :D

  4. gratis gewinn spiele Says:

    its a nice post to know about the PHP and GTK2 .if they to think are intregated into one it will be dynamic.

  5. festplatte retten Says:

    I like PHP language more then java script.

  6. kredi karti Says:

    thanx for the info. great to learn little bit about PHP and GTK2.

  7. Barcode Says:

    Thanks for the information!

  8. Air Jordan Says:

    Great nice & tips than x each point is appreciated

  9. Houston payday loans Says:

    Tried it and it works like a charm. Thanx!!

  10. seo Says:

    I have been playing with this all day trying to figure what is it..

  11. Coupons Says:

    I never thought in this way.Thanks for sharing.

  12. Promotional Codes Says:

    Thanks a lot for this cool post.I like this one.

  13. adminme Says:

    im not successful.
    it not be. =)

Leave a Reply