PHP-GTK2 Newsletter
Migration to the new PHP-GTK v2.0 release |
| Written by kksou | ||
| Wednesday, 05 March 2008 | ||
|
I have migrated a considerable amount of codes to the new PHP-GTK v2.0 release. Here are some tips and tricks I've found along the way...
if (defined("GObject::TYPE_STRING")) {
$model = new GtkListStore(GObject::TYPE_STRING, GObject::TYPE_STRING,
GObject::TYPE_LONG, GObject::TYPE_DOUBLE);
} else {
$model = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING,
Gtk::TYPE_LONG, Gtk::TYPE_DOUBLE);
}
or
if (Gtk::check_version(2, 12, 0) == null)) {
$model = new GtkListStore(GObject::TYPE_STRING, GObject::TYPE_STRING,
GObject::TYPE_LONG, GObject::TYPE_DOUBLE);
} else {
$model = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING,
Gtk::TYPE_LONG, Gtk::TYPE_DOUBLE);
}
GtkTreeViewColumn::set_alignment(double xalign); For left alignment, you have to put a 0.0. For right alignment, it's 1.0. Try putting a 0 or 1. You will get an error. (For the alpha and beta versions, it's works with 0 and 1.) To illustrate the case, I managed to replicate the problem faced by Matt in his post titled GtkCellLayout::set_cell_data_func issue in Gtk2. Try the code below: Warning: file_get_contents(/var/www/html/php-gtk2/thoughts/php/0033.4.php) [function.file-get-contents]: failed to open stream: No such file or directory in /home/fann/kksou.com/php-gtk2/util/phpgtk2_lib_t34.php(1250) : eval()'d code on line 1 You will get the error messages: Warning: Unable to invoke callback '' specified in test1.php on line 71 in test1.php on line 29 Note: the code above is a slight modification from the familiar GtkTreeView sample code: Sample Code 33: How to display a 2D array in GtkTreeView - Part 5 - get user selection Would you want to guess which is the offending statement causing the error? It's line 43! $field_justification = array(0, 0, 0.5, 1); Interesting, right? The error message is totally unrelated! If you change the above to: $field_justification = array(0.0, 0.0, 0.5, 1.0); The code runs ok now! If you reset the above statement to: #echo "col = $col\n"; Now you get another error message: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1667326510 bytes) in 033.4.php on line 28 To confuse you further, now comment out line 54:
#$cell_renderer->set_property("xalign", $field_justification[$col]);
Ha, the program now runs ok! Even though we're using integer and not double in line 43: Conclusion: Think simple. The PHP-GTK v2.0 release does not change much. And out of the many programs that I've migrated, I have not encountered any strange bugs yet. Take a look at the error message. Use that as a reference, but don't rely entirely on it. User reviews There are no user reviews yet. Note: You have to be a registered member to leave a comment. Free registration here. |
||
| < Prev | Next > |
|---|




