PHP-GTK News #5

Developement
There was a lot of development activity this week. To quote Andrei, “We are rapidly on our way to releasing an alpha of PHP-GTK 2…” This is good news for everyone involved with PHP-GTK. Now, on to the news.
Exceptions:
Here is a question for you. How do you handle an exception that is thrown in a segment of the code you don’t have access to? The answer, uh nobody really knows. And apparently neither does PHP-GTK 2. If an exception is thrown during a callback PHP-GTK just kind of stands around waiting for someone else to handle it. Uncaught exceptions in callbacks cause the PHP code to stop executing, but the Gtk main loop keeps waiting for PHP to finish. This causes the code to hang. Setting a custom exception handler does not help either. A bug has been filed and Andrei is on the case.


GtkCalendar::get_date() Patch:

Andrei applied a relatively simple patch for GtkCalendar::get_date(). This method now works as expected. It returns an array containing the month, day and year that was selected from the GtkCalendar.

Gtk::idle_add() Segfault:

Andrei applied another small fix for Gtk::idle_add(). The method was causing segfaults but doesn’t anymore. Gtk::idle_add() is a function that will call a callback on every Gtk main loop iteration that does not have anything else to do. You can use it to do work in the background without afecting the responsivness of your application. If the use clicks on something or any other type of signal is fired, the idle callback gets ignored until all other events have been handled.

GtkComboBox:

After a request by Christian, Andrei reworked the constructor for GtkComboBox. It now takes an optional GtkTreeModel argument. This make GtkComboBox a little more PHPish. It is no longer necesasry (or possible) to call GtkComboBox::new_with_model(). If you want to create a GtkComboBox with a model just pass it to the constructor like this:

$model = new GtkTreeStore(Gtk::TYPE_LONG, Gtk::TYPE_STRING);
$model->append(array(1, ‘One’));
$model->append(array(2, ‘Two));
$combo = new GtkComboBox($model);

The same was done for GtkIconView. GtkIconView is a widget that displays a list of icons in a grid. It could be used to create something similar to the list of “smilies” on a PHPBB comment page.

set_cell_data_func:

set_cell_data_func is used to assign the value of a cell based on the return value of a callback. This is useful in cases where the value cannot be taken directly from the model but instead must be interpretted from the value of one of its columns. This method was originally implemented as part of GtkTreeViewColumn, but Andrei moved it to GtkCellLayout. This allows any object that implements the GtkCellLayout interface to use set_cell_data_func.

GtkUIManager Patch:

Tom Rogers supplied patches for GtkUIManager which Andrei slightly modified and then applied. One patch fixed the implementation of GtkUIManager::add_ui_from_string() which parses a string of UI information and merges it with the current UI data. Another patch fixed GtkUIManager::get_toplevels(). get_toplevels() returns a list of top level widgets such as menubars, toolbars, and popups. The last patch provides the correct implementation for GtkUIManager::get_action_groups().

More win32 compiling patches:

Tom Rogers supplied yet another set of patches for compiling PHP-GTK 2 on win32. The compilation process is becoming more and more stable with every patch.

GdkPixbuf::new_from_xmp_data():

Andrei made updates to CVS that added this method to GdkPixbuf. XPM data is an image format very similar to ASCII art. An image is made up of characters, each one representing a different color. With this method, creating images on the fly is much easier. Take a look at the Pixmap turorial for PHP-GTK 1 for an example of using XMPs.

GdkPixbuf::new_from_gd():

Andrei also implemented GdkPixbuf::new_from_gd() which allows creating pixbufs from GD images.

Even more GdkPixbuf updates:
The implemenation of GdkPixbuf::get_pixels() has been fixed. This method returns a string representation of all the pixels in a GdkPixbuf. Althought the type returned is a string it is really binary data. It could be used to make modifications to the pixbuf and then write it back.

GtkPlug and GtkSocket overrides:
Anant provided patches for GtkPlug::get_id(), GtkSocket::get_id() and GtkSocket::add_id(). These methods help with embdedding windows from one process into windows from another. The patches have not yet been applied. GtkPlug and GtkSocket are not available on Windows.

Documentation

Christian added lots of constructor examples this week. Take a look at the GtkAboutDialog page for an example of his new examples.

Good-bye PHP-GTK 1:
PHP-GTK 1 Docs closed. The PHP-GTK 1 docuemtation has been closed for updates. Only the CVS HEAD may be updated now. All documentation efforts should go toward the PHP-GTK 2 docs. Unfortunately all documentation updates are on hold while Steph tries to figure out the build system.

General

More GtkCalendar Craziness:
(Andre Jansen)
When a GtkCalendar first appears, it will have a day-of-month highlighted unless instructed otherwise (with select_day(0)). However, the “cursor” - the dotted rectangle that allows to select a date with the cursor keys - is absent. It will appear out of the upper left hand corner upon repeatedly pressing the right arrow key. One would expect the cursor to coincide with the preselected date instead - as was the case in PHP-GTK1.

phpGladeTool Released

The phpGladeTool is a tool with a single objective, to help the PHP-GTK programmers on interface designing. The screens of the system will be designed with Glade 2 and the phpGladeTool will generate the PHP-GTK 2 code, based on XML file generated by Glade. Beyond the php-gtk code, a structure of business logic is generated, based on methods/event called by the interface(button clicks, etc).
PEAR
Newly added classes:
Gtk2_IndexedComboBox and Gtk2_EntryDialog have both been accepted.
Called for Votes:

PEAR_PackageUpdate_Gtk2: PEAR_PackgeUpdate_Gtk2 is a PHP-GTK 2 front end for PPU. It is designed to be used by PHP-GTK 2 packages and applications that want to include auto-updating features.

Leave a Reply