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.
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
. Hopefully that all worked smoothly for you.



April 23rd, 2008 at 3:32 pm
Notice I made an error in my window
… That password text box isn’t needed. Doh!
April 25th, 2008 at 10:12 pm
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.
April 26th, 2008 at 2:19 am
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
April 27th, 2008 at 8:08 am
its a nice post to know about the PHP and GTK2 .if they to think are intregated into one it will be dynamic.
April 27th, 2008 at 4:36 pm
I like PHP language more then java script.
April 28th, 2008 at 2:10 pm
thanx for the info. great to learn little bit about PHP and GTK2.
May 1st, 2008 at 3:13 am
Thanks for the information!
May 6th, 2008 at 2:06 pm
Great nice & tips than x each point is appreciated
May 7th, 2008 at 5:24 pm
Tried it and it works like a charm. Thanx!!
May 18th, 2008 at 3:54 am
I have been playing with this all day trying to figure what is it..
May 21st, 2008 at 2:01 am
I never thought in this way.Thanks for sharing.
May 21st, 2008 at 2:01 am
Thanks a lot for this cool post.I like this one.
May 24th, 2008 at 12:31 pm
im not successful.
it not be. =)