PHP-GTK News #14

What at first appeared to be a slow week actually generated a lot of news. There were an astounding 16 patches provided this week (all by one very hard working individual) as well as a few indepth discussions about using PHP-GTK. So without further delay, here is the PHP-GTK news for May 17th through May 24th…

Development

GtkListStore::remove() bug:
|Christian| (not Christian Weiske) from the PHP-GTK IRC channel (freenode #php-gtk) discovered a bug when working with GtkListStore when trying to use GtkListStore->remove($iter) in the callback for $liststore->foreach(). Apparently PHP-GTK frees the memory for the list row twice which causes the application to crash. Upon further investigation Christian Weiske discovered that the same issue occurs when using foreach($liststore as $row) { $liststore->remove($row->iter); }.
From what I can tell, the problem is that the call to remove() causes the underlying Gtk libraries to free the memory allocated for the row, but when the PHP variable is out of scope (either after executing the callback or the foreach loop moves to the next iteration) PHP tries to do the same thing. Of course, I don’t have the best understanding of the inner workings of PHP so my description of the problem may be wrong. Either way, it doesn’t work now and needs a patch to fix the problem.

Patch Fest ‘06:
Christian Weiske supplied 16 patches this week for missing or improperly implemented functionality. That must be a record. Most of the patches have been added as bug reports to make tracking them easier. Unfortunately they will probably not make it into the first alpha release (see below):

Alpha Release Update:
The first official alpha release of PHP-GTK 2 has been pending for a while now, but the time frame has recently become more specific. The issues with the Windows build are still present, but Steph has agreed to do her best to get these straightened out while Andrei is out on a trip to Russia. By the time Andrei returns, all should be ready for the first release and it should be made available shortly thereafter.

Documentation

Call for Help:
I am putting out this unofficial “Call for Help”. The PHP-GTK doc team used to be a force to be reckoned with, but has lately dwindled. The efforts of all who have contributed to this point are not to go unappreciated, but more help is needed if PHP-GTK 2 is to really be taken seriously. One of the things that has made PHP what it is today is the shallow learning curve and this is due in great part to the online documentation. Also, writing documentation is a great way to learn about PHP-GTK 2. The more you experiment with the features and write about them, the more you will learn about how PHP-GTK 2 works. If you would like to get involved, please see the Doccing Tutorial or contact the php-gtk-doc mailing list. All help is appreciated.

Documentation Updates:

General

Web Browser in an Application:
A French PHP-GTK user identified only as “CrazyCat” asked this week if it was possible to embed a web browser in an application. S/He wanted to provide a cross-platform way to display HTML without relying on any third party solutions (such as the user’s installed web browser). The MozEmbed extension, implemented by Anant, is desigend specifically to solve this issue. A demo of the extension at work can be found in the ext/mozembed/demos/ directory of the PHP-GTK 2 source.

Pixmap xpm:
A user named Martin was trying to recreate the XPM example from the wiki without success. The wiki example was written for PHP-GTK 1 and relies on the Gdk::pixmap_create_from_xpm_d() method. This method no longer exists in PHP-GTK 2. Instead the GdkPixbuf class provides the methods needed to work with images of varying types.

New Gnope dll:
Gnope.org released an updated version of the PHP-GTK 2 dll for Windows users this week. This version includes the GtkSourceView and MozEmbed extensions thanks to the work of the mysterious xxoes.

PHP|A A/R/T article:
PHP|Architect has released a new online service known as A/R/T. This service is a repository of free articles and tutorials devoted to PHP and related technologies. A/R/T provides more focused and indepth resources than the format and audience of their magazine allow. The current repository features an article titled “What is PHP-GTK?”. This article discusses the origins of and practicla uses for PHP-GTK.

Memory Leaks:
Andrew Buczacki asked the general mailing list for help resloving some memory issues this week. Memory usage is an issue that haunts some PHP-GTK applications (PHP-GTK 1 specifically, there have not yet been reported cases of PHP-GTK 2 memory leaks). This is due to the nature of PHP. It was originally designed to be used for quick running scripts that don’t have time to chew up memory, therefore memory usage is not normally a concern. PHP-GTK applications on the other hand are designed to run much longer.
Brian A. Stumm has successfully written an application which can run for days without leaking memory. His tips include using global variables for pretty much everything and realizing all of the widgets before starting the main loop.

IRC

Packing and Padding:
There was a discussion on the IRC channel this week about packing widgets into containers and padding. There seems to be a general confusion about the way widgets should be packed into container. There are three things to consider when packing widgets. First, do you want the widget to take up as much space as is available in the container, or do you simply want it to take up just as much as it needs? This is called expanding. When a widget is packed into a container you can tell it whether or not to expand. Second, do you want the widget to resize when the container is resized. This is known as filling. Widgets can be told whether or not to fill when they are packed. Finally, padding can be added around a widget. Different types of containers allow control of expand, fill, and padding in different directions (x => GtkHBox, y => GtkVBox, or both => GtkTable) depending on their nature. See the documentation for more details on packing widgets into specific container types.

13 Responses to “PHP-GTK News #14”

  1. David Says:

    “The MozEmbed extension, implemented by Anant, is desigend specifically to solve this issue. A demo of the extension at work can be found in the ext/mozembed/demos/ directory of the PHP-GTK 2 source.”

    Ok so one of the first lines in this demo is

    $mozComponent = new GtkMozEmbed();

    So where do we get the GtkMozEmbed class??

  2. David Says:

    “Instead the GdkPixbuf class provides the methods needed to work with images of varying types.”

    The php-gtk2 documentation provides no examples of how to use the GdkPixbuf class… could you point us toward any tutorials / examples of its use?

    Thanks

  3. scott Says:

    Hi David,

    If you want to use MozEmbed, you have to enable it when you compile PHP-GTK 2. If you are on a Linux-like system, use the –enable-mozembed flag. If you are on Windows grab the latest dll from Gnope.org.

    Some very simple examples of using GdkPixbuf can be found in the demos/imgbrowse.php file (http://cvs.php.net/viewcvs.cgi/php-gtk/demos/imgbrowser.php?view=markup&) and the PEAR_Frontend_Gtk2 package (http://pear.php.net/package/PEAR_Frontend_Gtk2/). I will move GdkPixbuf up on my documentation priority list.

    Thanks,
    Scott

  4. Christian Weiske Says:

    David,

    Gnope currently does only include GtkSourceView but not MozEmbed. I have the mozembed dlls here, but you need the php-gtk extension for it *and* (that’s the big problem) the full mozilla files which are a 8MB rar file.
    I don’t want to release it until I know which files in this archive are really needed.

  5. David Says:

    Ok will wait and see. Actually what I’m trying to do is display a simple bar chart or graph in a php-gtk2 app on the fly from some data. I was thinking of doing it in html and using MozEmbed, but I guess that can wait. In php-gtk1 I used pixmaps but it was messy… any ideas on how to do it in gtk2?

  6. scott Says:

    The easy but hackish solution is to save your image data to a temp file and then use GtkImage::new_from_file(). There are (or should be) GdkPixbuf methods for loading an image directly from data in memory, but I haven’t used them. I’d have to look into exactly how they work before I can give you any info on that.

  7. Christian Weiske Says:

    David, you can use the Graph package from PEAR, and load the GD image into a GdkPixbuf via GdkPixbuf::new_from_gd();

  8. David Says:

    Thanks for the suggestions. Ok this might be getting off-topic, but I’m having trouble installing the pear package Image_Graph. I downloaded Image_Graph-0.7.2.tgz and then typed

    pear install Image_Graph-0.7.2.tgz

    but it returned

    Package “pear.php.net/Image_Graph” dependency “pecl.php.net/Image_Canvas” has no releases

    I am online but thru a corporate firewall, but the above command should work offline (according to the pear manual)
    Any ideas?
    thx

  9. scott Says:

    pear install -f Image_Graph-0.7.2.tgz

    That will force Image_Graph to install. Image_Canvas (which is PEAR not PECL) is optional so you should be ok.

    If you really want Image_Canvas try running

    pear install Image_Canvas-alpha

    Also make sure that yoru default channel is set correctly.

    pear config-show
    pear config-set default_channel pear.php.net

  10. David Says:

    pear default_channel is set to pear.php.net

    Image_Color and Image_Canvas installed fine:

    >pear install -f Image_Color-1.0.2.tgz
    warning: pear/Image_Color requires PHP extension “gd”
    install ok: channel://pear.php.net/Image_Color-1.0.2

    >pear install -f Image_Canvas-0.3.0.tgz
    warning: pear/Image_Canvas requires PHP extension “gd”
    install ok: channel://pear.php.net/Image_Canvas-0.3.0

    But Image_Graph just won’t install:

    >pear install -f Image_Graph-0.7.2.tgz
    Package “pear.php.net/Image_Graph” dependency “pecl.php.net/PEAR” has no releases

    Again sorry if its off-topic
    Thanks,
    David.

  11. David Says:

    Finally got it working (after much headache).
    Image_Graph wouldn’t install until i took it to a different machine which was online.
    Then gd wouldn’t work until I installed the latest php with php_gd2.dll.
    Then Image_Graph wouldn’t do anything, the getting started guide says:

    After installation, simply include Image_Graph in your project using:
    include ‘Image/Graph.php’;

    Which is a total lie, you have to set the full path to the pear installation. Possibly something to do with me installing gnope recently, not sure.
    Anyway its working now, thanks guys

  12. Christian Weiske Says:

    > Which is a total lie, you have to set the full path to the pear installation.
    That is correct. It seems as if your include_path php.ini directive isn’t set correctly.
    Btw, the gnope forum (gnope.org/forum/) would be the right place for such a discussion :)

  13. Stuart Says:

    Had the same problem as above

    Trying to install the graph package on Xampp (win32) gave the following error after a long pause.

    ‘Package “pear.php.net/Image_Graph” dependency “pecl.php.net/PEAR” has no releases’

    Got it installed using ‘pear install -f -O Image_Graph-0.7.2.tgz’

    Hope this is of some use to someone

Leave a Reply