PHP-GTK News #4
Development
A little reorganization:
Christian reorganized the overrides file a little bit to keep things in alphabetical order. That will make life much easier down the road but doesn’t have any impact on the features or implementation of PHP-GTK 2.
More on GdkGC:
Andrei continued working on GdkGC. This week he implemented set_dashes() and set_values(). GdkGC::set_dashes() determines the way dashed lines are drawn. It can be used to vary the length of the on and off segments of a dashed line. For example, you could make the dashes 10 pixels and make the whitespace in between 20 pixesl. GdkGC::set_values() is a method for setting many GdkGC values in one shot.
More More on GdkGC:
After exposing the GdkGC fields (exposing means making them available in PHP-GTK) such as foreground and background, Andrei asked for feedback on the way to access GdkGC fields. He wanted to know if we needed $gc->foreground = $value or if $gc->set_foreground($value) was enough. If direct field access is needed, that will require writing overrides for all of the fields. The concensus is less work is better. $gc->set_foreground() is enough.
Extra Fields:
Andrei also added the ability to define extra programmatic fields. That is a fancy name for properties. At the moment, this is just for the PHP-GTK 2 generator, the tool that creates the PHP-GTK 2 source code. Userland definable extra properties will come later.
GtkFileChooser Patches:
Christian supplied override patches for GtkFileChooser::get_filenames() and GtkFileChooser::get_uris(). What at first appeared to be a routine set of overrides sparked a rather complicated discussion. As many developers have experienced, characther encodings can cause trouble. The problem that can appear with the GtkFileChooser methods is that the OS can speak a different encoding than PHP. This means that a string containing a file path in one encoding may work for accessing the file but will appear corrupted when it is displayed in an application.
After a lengthy discussion, it was determined that an optional argument to these methods will at least give the user the option to explain what the return value is going to be used for. If it is going to be used for display, it should be converted to UTF-8 and the optional convert argument should be passed as true. If it is going to be used to grab the file from the file system, the convert argument should be passed as false, or left out as false is the default. The pathces were finally applied on 2006-03-14.
var_dump($widget):
Trying to debug PHP-GTK 2 code using var_dump is difficult at best. Because of all the relationships between parent and children and the fact that every widget has other objects (namely GtkStyle) as properties, the output can easily climb into the thousands of lines. It has been requested that the output of var_dump on a widget be trimmed down a bit to make debugging easier. If nothing else, it would be helpful if the contents of GtkStyle didn’t appear in the output, but the levels of parent/child relationships need to be taken under control too.
Instead of trying to rewrite the PHP-GTK 2 widgets to work differently with var_dump, it would probably be better to create a new function widget_dump() that does what we want. Andrei’s response: write it. Unfortunately, I don’t have the time or talent to write it. If anyone does, please send a message to the dev mailing list. Here is a quick psuedo PHP version that hasn’t been tested or particularly
well thought out:
function widget_dump($widget, $maxLevel = 1, $level = 1)
{
$r = new ReflectionClass($widget);
echo strpad(’ ‘, ‘ ‘, $level, STRPAD_LEFT);
echo $r->getName() . ” {\n”;
foreach ($r->getProperties() as $prop) {
if ($prop->getType() != ‘object’) {
echo strpad(’ ‘, ‘ ‘, $level, STRPAD_LEFT);
echo $prop->getName() . ‘=>’ . $prop->getValue() . “\n”;
} else {
if ($level < $maxLevel) {
widget_dump($prop->getValue(), $maxLevel, $level +1);
}
}
}
echo strpad(’ ‘, ‘ ‘, $level, STRPAD_LEFT);
echo “}\n”;
}
Documentation
Steph put in many hours on getting the PHP-GTK 2 docs up on gtk.php.net. It appears that this isn’t as simple as anyone thought. There are plenty of different things to consider but she is getting much closer.
General
GtkComboBox focus:
Andre Jansen was having trouble detecting when a GtkComboBox received for lost focus. His signal handler for ‘focus-in-event‘ was not working as he had hoped. In fact it wasn’t working at all. It appears that GtkComboBox does not listen for ‘focus-in-event‘ or ‘focus-out-event‘. Instead you must use just plain ‘focus‘. This signal is fired both when the widget receives and loses focus.
function printFocus()
{
echo “TEST\n”;
}$window = new GtkWindow();
$window->connect_simple(’destroy’, array(’Gtk’, ‘main_quit’));$combo = new GtkComboBox();
$combo->connect_simple(’focus’, ‘printFocus’);$vBox = new GtkVBox();
$vBox->add($combo);
$vBox->add(new GtkButton(’TEST’));$window->add($vBox);
$window->show_all();
Gtk::main();
IRC
‘key-press-event‘:
rza was trying to work with ‘key-press-event‘ to handle certain keys one way and other keys in the default way. For example, he wanted a widget to listen to the ‘key-press-event‘ but also to react in the default manner when the tab key is pressed.
The correct way to do this is with two signal handlers. The first checks the key that was pressed and decides if the special action should take place. If so, just do the action and return true. A return value of true indicates to the PHP-GKT that no more signal handlers should be called for the current event. If false is returned, PHP-GTK will continue to call signal handlers until one of them returns false or there are no more handlers to call. So if the key should not fire the special action, return false and the default action will happen. This holds true for both PHP-GTK 1 and PHP-GTK 2.
GtkComboBox::pack_start():
I was confused about the Gtk2_IndexedCombo proposal on PEAR so I asked Christian about it on IRC. What confused me was that he was using pack_start as a method of GtkComboBox. According to the gtk.org documentation that method doesn’t exist. Unfortunately, gtk.org lied! The method does exist and is even included in the PHP-GTK 2 docs. It is used to add cell renderers for displaying multiple columns in the model.
Clipboards:
rza, of Wu Tang fame, asked about copying data to a clipboard. There is a whole section in the Gtk+2.0 manual about copying data from and pasting data to clipboards: http://developer.gnome.org/doc/API/2.0/gtk/gtk-Clipboards.html
Double Click:
Apparenly tracking a user double-click is pretty hard. It appears to have caused trouble for many people on IRC. kioto finally came up with the correct solution: checking the event type.
$obj->connect(’button-press-event’, ‘my_callback’);
function my_callback($obj, $event)
{
if ($event->type == GDK_2BUTTON_PRESS) {
echo ’some stuff here’ . “\n”;
}
}
PEAR
Call for Votes:
Gtk2_IndexedCombo and Gtk2_EntryDialog have been moved to the Call for Votes stage. If you have the ability to vote for PEAR packages, please lend your support. Not only will the packages make your PHP-GTK 2 coding life easier but they draw more attention to PHP-GTK 2 which in turn makes your coding life easier again because more people means more help.
Proposed:
Gtk2_QuickForm - This package aims to be a non-HTML version of HTM_QuickForm. It may need a name change (to PHP_QuickForm maybe) since it isn’t necessarily PHP-GTK 2 based, but at the moment the only supporting elements are for PHP-GTK 2. The package will make it as easy to create input forms in PHP-GTK 2 as it is in HTML.
