03-01-2008, 05:40 PM
|
#1 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
PHP-GTK2 (finally) Released
Well, the PHP-Gtk team proved me wrong by finally releasing PHP-Gtk2. And to think I'd assumed that the project was dead
PHP-Gtk2 brings lots of improvments over the previous version, including much better window drawing / handling on Windows.
Some useful links for anyone interested:
PHP-Gtk Website
PHP-Gtk2 Documentation
PHP-Gtk2 Downloads
I've also knocked up a little demo app for anyone interested in PHP-Gtk - code and screenshots below:
Code:
PHP Code:
<?php
// ===============================================================
// PHP-GTK2 Demo Application
// Accepts input from a text box then shows a popup message
// ---------------------------------------------------------------
// Written by Alan Wagstaff
// Donated to the Public Domain
// ===============================================================
// Check if GTK2 is loaded
if( !class_exists('gtk'))
{
die('Please load the php-gtk2 module in your php.ini' . "\r\n");
}
/**
* Main Window
* Displays a label, input box and button
*/
class windowMain extends GtkWindow
{
/**
* Text input
*
* @var object
*/
var $txtName = null;
/**
* Constructor - sets up the main window
*/
function __construct()
{
parent::__construct();
// Create the window
$this->connect_simple('destroy', array('gtk', 'main_quit'));
// Set the window properties
$this->set_title('TalkPHP PHP-GTK2 Demo');
$this->set_position(Gtk::WIN_POS_CENTER);
$this->set_border_width(8);
// Add the label, input box and go button
$this->add($this->createInput());
// Display the window
$this->show_all();
}
/**
* Creates the label, input box and button elements
*/
function createInput()
{
// Create a panel that will hold our other elements
$panel = new GtkVBox(false, 8);
// Create the input box
$this->txtName = new GtkEntry();
// Create the label
$labelNamePrompt = new GtkLabel('Please Enter Your _Name');
$labelNamePrompt->set_use_underline(true);
$labelNamePrompt->set_mnemonic_widget($this->txtName);
// Create the button
$btnGo = new GtkButton('Go!');
// Connect the click event of the button to our function btnGo_clicked()
$btnGo->connect('clicked', array($this, 'btnGo_clicked'));
// Add all our elements to the container panel - just shoves them in starting at the top
$panel->pack_start($labelNamePrompt, false, true);
$panel->pack_start($this->txtName, false, true);
$panel->pack_start($btnGo, false, true);
// Return our element-filled panel
return $panel;
}
/**
* Fires when the Go button is clicked
*/
function btnGo_clicked($btnGo)
{
// Create a dialog box with the following options:
// DIALOG_MODAL - The applicaiton cannot be used while the dialog is open
// DIALOG_DESTORY_WITH_PARENT - Close when the app closes
// MESSAGE_INFO - The icon to display
// BUTTONS_OK - The buttons to display
// The text that will appear in our dialog box
$dlgHello = new GtkMessageDialog($this,
Gtk::DIALOG_MODAL | Gtk::DIALOG_DESTROY_WITH_PARENT,
Gtk::MESSAGE_INFO,
Gtk::BUTTONS_OK,
sprintf('Hello %s, from everyone at TalkPHP!', $this->txtName->get_text())
);
// Show the dialog box until it is closed
$dlgHello->run();
// Destroy the dialog box
$dlgHello->destroy();
}
}
// ----------------
// Create our new Window (aka, application)
// ----------------
new windowMain();
// ----------------
// Run our application
// ----------------
Gtk::main();
All the application does is prompt the user for their name then display it in a popup dialog box.
Screenshots:
I still wouldn't recommend using PHP-Gtk2 for creating full Windows / Linux applications but it is definately an improvment on the previous versions
Alan
|
|
|