Archive for the 'PHP-GTK' Category

PHP-GTK News #14

Wednesday, May 24th, 2006

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.

PHP|Architect’s A/R/T

Tuesday, May 23rd, 2006

A new article on the evolution of PHP-GTK has been posted on PHP|Architect’s A/R/T. A/R/T is PHP|A’s new companion repository for their magazine. It is a collection of articles and tutorials that allows them to be more focused and indepth than their regular magazine. The articles are all freely available and cover a wide range of topics.

This article is a first in a series of PHP-GTK articles. My goal is to start with PHP developers that have never heard of PHP-GTK and slowly but surely get them to the point where they can develop their own PHP-GTK apps with minimal headaches. Part one of this series doesn’t jump into any development. It simply gives a bit of background. This article explains where PHP-GTK came from and how it can be useful in the real world. As always, I welcom comments, ideas and suggestions, not just about this article but also about future articles that you would like to see written.

PHP-GTK News #12 & #13

Wednesday, May 17th, 2006

The news is back with a double shot covering the last two weeks. Issues in this news update appear to go a little deeper than in previous weeks. The developement items dive into segfaults and the differences between C code and PHP code. The General userland issues get into the details of working with GtkTreeView and GtkTreeStore, two of the more complex objects in PHP-GTK 2.

Developement

GtkWidget::size_request() Patch:
Christian added a fix to GtkWidget::size_request() that make the method return a GtkRequisition object instead of modifying an existing one. This makes the method PHP-ish instead of Gtk-ish. size_request() can be used to get the size a child widget will request when shown on the screen. The actual size may be different because of restrictions set by the widget’s parent container or other factors.

Drag-and-drop bugs:
Christian reported several drag-and-drop bugs over the last two weeks. Three of the four bug reports highlight segfaults that occur when dragging data or working with dragged information. The other bug report deals with a corrupted double-linked list. The issues appear at first glance to be related to the MIME type of the data that is being moved around. The three segfault issues do not occur when the data is text/plain.

Patch for gtk_selection_data_set_uris/gtk_selection_data_get_uris:
Christian supplied a patch via the bugs system that implements gtk_selection_data_set_uris and gtk_selection_data_get_uris. These two functions are used for drag-and-drop operations.

E_STRICT and PHP-GTK 2:
PHP-GTK 2 builds off of Gtk+2.0 which is a C library. In Gtk+2.0, functions are overridden from one class to another without necessarily keeping the same signature. PHP doesn’t really appreciate this when error reporting is set to E_STRICT. PHP will report errors about mismatching method signatures in widgets. For example, GtkToolbar::set_style() has a different signature than GtkWidget::set_style(). GtkToolbar::set_style() determines whether or not icons, text, or both will appear in the toolbar where as GtkWidget::set_style() sets a GtkStyle object for a widget. Eventhough, GtkToolbar is a descendant of GtkWidget, there is no need for setting a GtkStyle object on a GtkToolbar, because GtkToolbar is a container and styles have no impact on containers. Understanding this subtlety is obviously too much to expect from PHP (the language not the developers or community). At the moment, it looks like something that we will have to live with.

Documentation

Translating Docs:
A few individuals have come forward offering to help translate the PHP-GTK 2 docs. For anyone else interested in helping with the translations, here are the steps to follow:

  1. Read the “PHP-GTK 2 Documentation” tutorial
  2. Translate the following files (if needed):
    • preface.xml
    • bookinfo.xml
    • language-defs.ent
  3. Update stylesheets/common/.xml (if needed).
  4. If the above has already been done for your language, translate some other XML file.
  5. Send your translated files to the documenation mailing list
  6. Someone will review your files to make sure that they are well-formed and valid. If all is good, they will be committed to CVS (after we are sure the build system will still work).
  7. Translates some other files and send them to the list. After a few rounds, someone will petition the powers that be for some CVS karma and you will be able to commit the files yourself

Documentation updates:

General

Setting Data for a GtkTreeViewColumn:
Michale Crowl experienced some confusion trying to work with GtkTreeViewColumns. No matter how he set up his view, all of the columns were appearing the same. This was due to the fact that he was accidently setting all columns to use the same cell of each row in the model. The last argument to the GtkTreeViewColumn constructor tells the column which cell in the row to grab its value from. Passing 0 as the column number tells the GtkTreeViewColumn to look in the first cell fo the row. Passing 2 will tell the column to grab its value from the third cell in the row.

GtkTreeView::scroll_to_cell():
Benjamin is trying to convert his PHP-GTK 1 applications to PHP-GTK 2. One of the features he relied on in PHP-GTK 1 was GtkCTree and the GtkCTree::moveto method. When porting his application to PHP-GTK 2 he moved to using GtkTreeView because GtkCList is deprecated. The replacement for GtkCList::moveto is GtkTreeView::scroll_to_cell. This brings the given cell in the GtkTreeView into view. It can be used, as Benjamin is trying to do, to implement a more powerful search than the one that is built into GtkTreeView.

Image in a GtkTreeView:
Ron Tarrant had a question about adding an image to a GtkTreeView (it seems everyone has tree view questions these days). He was able to set up the model correctly using GdkPixbuf::gtype as the column type, but wasn’t sure what to pass as the image. As Christian pointed out, the data to be passed should be a GdkPixbuf. A GdkPixbuf can be obtained pretty easily by calling GdkPixbuf::new_from_file().

PEAR

New Releases:
Gtk2_FileDrop-0.1.1 - The latest version of this package fixes a MIME_Type warning. This package can be used to quickly and easily add drag-and-drop capabilities to your applications.
PEAR_Frontend_Gtk2-0.1.2 - This version of the PHP-GTK 2 front end for the PEAR installer fixes a bug when running “pear -G” from the commandline.

PHP-GTK News #11

Wednesday, May 3rd, 2006

Development

Patches:
The following patches have been added to PHP-GTK 2

These patches mark the completion of step one in the alpha release plan. Next the Windows issues must tackled, along with the selection of one of the two Scintilla extensions and updates to the packaging script.

Reflection for set_visible():
Christian added reflection information for the GtkWidget::set_visible patch that was added last week. This provides information to be used by the Reflection extension. It also makes it possible to automatically generate documentation XML for this method.

Drag-n-drop Segfault:
A few issues were reported this week with drag-n-drop functionality. The drag-n-drop implementation can cause a few seg faults. These can happen when a signal handler is connected to “drag-data-get“, after closing a window when drag-n-drop was used or when dumping the selection “drag-data-get” callback.

Documentation

New Glade tutorial:
Christian added a new tutorial on using .glade files to build the UI of an application. This is not a tutorial on using Glade itself, but a tutorial on what to do next once you have created the .glade file.

General

Exteding widgets:
Dave wrote into the general mailing list this week asking how he can use a custom Gtk+1.2 widget in a PHP-GTK 1 application. His custom widget is written in C. Custom widgets for PHP-GTK 1 or 2 can be used by writing an extension for PHP-GTK.
On a somewhat related note, if you simply want to create your own widget in PHP-GTK 1 or 2 you can extend GtkWidget or any other class. This allows you to create things like a calendar button that sets a date, or a custom entry completion widget.

Gnope.org:
Christian is everywhere these days it seems. He has released a new package on Gnope.org that is a new spin on IDEs. Gnope/Dev_ClickPhp is a drag-n-drop developement environment. It is still in the very early stages but still worth taking a look at.

PHP-GTK News #10

Wednesday, April 26th, 2006

Another slower week for PHP-GTK as people, myself included, tend to the work that pays the bills.

Development
Planned Patches for Alpha Release:
Last week a rough release plan was announced for PHP-GTK 2 alpha1. Part of this plan included applying a few patches. This week Andrei gave us a list of the patches that he hopes to apply:

  1. PangoAttribute support.
  2. GtkRadioButton::get_group (and maybe related ones). (Applied 2006-04-23)
  3. GtkAboutDialog::get/set_website_label
  4. GtkPlug/GtkSocket (Applied 2006-04-24)
  5. Scintilla extension.
  6. GtkTreeModel::iter_parent, iter_n_children and any additional ones that are easy to implement.

General

New book on PHP-GTK 2 available:
As was posted earlier this week, “Pro PHP-GTK” is now available. This is the first an only book to cover PHP-GTK 2 in detail. Details can be found in the previous post.

Context menus in GtkTreeView:
Christian was having some trouble creating context menus for selected rows in a GtkTreeView. Fortunately, he was able to solve the problem himself. Here is a section of his one-man email thread:

I have a GtkTreeView and connect “button-press-event” to show a context
menu for the currently selected row.
The popup works, but I get the previously selected row only - not the
one that is (newly) selected when I right-click the list.
An example code is here:
http://xml.cweiske.de/rightclicktree.phps
Just run it and right-click a not selected item; the popup will show the
value of the selection - which is always the old one, not the new selection.
Does anyone know how to get the new selection data?
connect_after doesn’t work here.
———
While writing this mail the idea to use “button-release-event” crossed
my mind and it works. Thanks for reading :)

PHP-GTK RAD tool:
ANUBIS, a RAD tool for PHP-GTK, was released this week. That is all I can say about it because I only read English. If someone has more details please feel free to post them in a comment below. For those who are multi-lingual, details can fe found at www.zendrael.com.

PEAR

Added to PEAR:
Structures_Form_Gtk2: This packaeg provides PHP-GTK 2 elements for Structures_Form (also accpeted into PEAR this week). Along with Sturctures_Form, this package allows generic forms to be created independant of the UI.

On a personal note, I would like to serve fair warning that either next week or the week after, news will not be posted as my first child will be born shortly and I probably won’t be near a computer. I will do my best to make sure that the follow week’s news covers everything in the two week span. News posting will continue on the regular schedule after the one week break.