Archive for July, 2007

PHP-GTK Explorer

Sunday, July 22nd, 2007

There is a “secret weapon” that I’ve been using for a long time in learning and exploring php-gtk2.

Last weekend, I’ve got some time. Decided to polish this up a bit and share with the rest of you who are keen in using php-gtk2.

So here it is — the “PHP-GTK Explorer”. It’s like the Dev_Inspector (from gnope.org), but with a lot more functionalities added.

One of the most important keys in mastering php-gtk2 is to understand the object hierarchy of a widget, i.e. knowing who are its ancestors, its siblings and its children. The “PHP-GTK Explorer” have three different tabs to show you these three views.

View 1: The Object Hierarchy For GtkToggleButton

View 1: The Object Hierarchy For GtkToggleButton

View 2: GtkToggleButton and its siblings

View 2: GtkToggleButton and its siblings

 

View 3: GtkToggleButton and its children

View 3: GtkToggleButton and its children

There are a lot more exciting features of PHP-GTK Explorer that makes the learning of PHP-GTK2 more fun and easy.

You can find more details and download a copy here:

http://www.kksou.com/php-gtk2/products/php-gtk-explorer/

/kksou

http://www.kksou.com/php-gtk2
The place for php-gtk2 sample codes

GtkCellRendererAccel - it’s working!

Tuesday, July 10th, 2007

I decided to try out the new widget GtkCellRendererAccel (available in gtk+2.10) last weekend.

Just like GtkCellRendererSpin, the only information currently available on the net is the following:

http://developer.gnome.org/doc/API/2.0/gtk/GtkCellRendererAccel.html

I must have read this more than a hundred times, trying to figure out what it is trying to say and how everything fits together.

It looked simple. Supposedly, you create a new GtkCellRendererAcce, set the ‘accel-key’ with the key value, and then the ‘accel-mods’ with the modifier key. That’s it! The widget should automatically display the keyboard accelerator in the treeview.

But after going through at least 200+ different combinations and settings, IT JUST DOESN’T WORK!!!

After two night, I gave up. I thought this must be one of those features that are yet to be implemented.

I moved on to look at GtkCellRendererSpin. That’s the sample code you saw yesterday on GtkCellRendererSpin (please refer to the previous post).

Decided to give just one more night of try with GtkCellRendererAccel before really giving it up.

Am I glad I did! Just imagine my joy when I saw the Alt-A appearing in the treeview!

Turns out that I’ve “overly complicated” the widget. It’s actually a simple widget for displaying keyboard accelerator. Nothing more! All the handling of the keyboard accelerator has to be handled by yourself. That’s why you don’t see any methods or signals for handling the keyboard accelerators.

Also, it’s really that simple to use as the document above claimed. All you need is to create a new GtkCellRendererAcce, set the ‘accel-key’ with the key value, and then the ‘accel-mods’ with the modifier key. That’s it! The widget will automatically display the keyboard accelerator in the treeview.

I will be coming out with three sample codes to illustrate the use of GtkCellRendererAccel.

Here’s Part 1:

How to display keyboard accelerator in GtkTreeView with GtkCellRendererAccel - Part 1?

Part 2 and 3 will be posted in the next two days.

/kksou

http://www.kksou.com/php-gtk2
The place for php-gtk2 sample codes

Sample code for GtkCellRendererSpin

Tuesday, July 10th, 2007

Tried last night to decipher probably the only information (at least currently) available for GtkCellRendererSpin - one of the new widgets in gtk+2.10:

http://developer.gnome.org/doc/API/2.0/gtk/GtkCellRendererSpin.html

After some trials and errors, finally figured out what it is trying to say.

So here’s a sample code to illustrate how to use this new widget:

How to input or edit numbers in GtkTreeView with GtkCellRendererSpin?

/kksou

http://www.kksou.com/php-gtk2
The place for php-gtk2 sample codes

Two new classes: Wizard and Wizard_Page

Thursday, July 5th, 2007

If you wish to set up wizards in PHP-GTK2, and can’t wait for the “bugs” (as explained in “Some problems with GtkAssistant”) to be fixed, you might want to take a look at the following sample code:

How to set up wizards using GtkDialog - Part 2 - using OOP and classes?

This example gives the same result as How to set up wizards using GtkDialog - Part 1?

The only difference is that it’s re-written using OOP and classes.

The Wizard class is used almost similar to the GtkAssistant.

The Wizard_Page is used for setting up each page of the wizard. It helps to make the code cleaner and easier to maintain. All the signal handlers and processing functions can be nicely encapsulated into this class.

You will find that it’s now much easier to set up wizards, with the ability to set each page’s contents on-the-fly (using the prepare “signal”), and carry out appropriate actions based on user’s inputs (using the apply “signal”).

/kksou

http://www.kksou.com/php-gtk2
The place for php-gtk2 sample codes

Implementing the GtkAssistant using GtkDialog

Wednesday, July 4th, 2007

After playing with GtkAssistant for a couple of days, I decided that it does not give us enough control to make it truly useful. For example, how do you change the background color of the title? How do you change the button label of ‘Forward’ to ‘Next’? Not to mention that the signal ‘apply’ is not responding, and the method set_forward_page_func() is not working too! (For more details, please refer to my previous article titled article titled “Some problems with GtkAssistant”.

I looked through all the existing methods available in GtkAssistant, and realized that we can actually implement all the functionalities of GtkAssistant using GtkDialog!

The entire sample code with explanations are here:

How to set up wizards using GtkDialog - Part 1?

There are a couple of advantages using the GtkDialog version:

  • You can use any versions of php-gtk2 without gtk+2.10 (yes, the Gnope version too).
  • You get a lot more power and control of every single widget in the wizard. For example, you can freely change the size, shape, label and positioning of the action buttons (i.e. the Next, Back and Close buttons), or the color, font and font size of the title.

Besides GtkAssistant, there are a couple other widgets in PHP-GTK2 which are quite similar:

  • GtkButtonBox is easier to use. But you can accomplish all the functionalities of GtkButtonBox using just GtkVBox/GtkHBox + GtkButton with more power and control.
  • GtkFileChooserDialog is easier to use. But you can accomplish all the functionalities of GtkFileChooserDialog using GtkDialog + GtkFileChooser with more power and control.
  • GtkFileChooserButton is easier to use. But you can accomplish all the functionalities of GtkButtonBox using GtkButton + GtkFileChooser with more power and control.
  • GtkColorSelectionDialog is easier to use. But you can accomplish all the functionalities of GtkButtonBox using GtkDialog + GtkColorSelectionwith more power and control.

/kksou

http://www.kksou.com/php-gtk2
The place for php-gtk2 sample codes

Some problems with GtkAssistant

Monday, July 2nd, 2007

If you have tried the sample code in:

How to set up wizards using GtkAssistant - Part 2 - respond to forward button?

You will find that the signal ‘apply‘ doesn’t work yet in the beta release of php-gtk2. Have tried it on both windows and linux. Both just do not respond to the Forward button.

Fundamental to a GtkAssistant is to be able to know when the user clicks the Forward button. In the example above, when the user clicks the Forward button, we should get the contents of the two text entry fields and perform some action. Without the ‘apply’ signal, there’s no way you can get hold of the contents of the two GtkEntry!

Another important method that is missing from this beta release of php-gtk2 is the set_forward_page_func(). This method allows you to set your own self-defined handler that will be called when the usr clicks the Forward button. For example, if your wizard allows users to choose between Express, Complete and Custom setup. If the user chooses Express setup, you can jump from Page 2 direct to Page 6. Currently, this method is missing in the beta release of php-gtk2 - both windows and linux.

Without the ‘apply’ signal and the method set_forward_page_func(), it’s really difficult to come out with anything useful using GtkAssistant.

Hopefully the PHP-GTK2 development team will add these soon…

/kksou

http://www.kksou.com/php-gtk2
The place for php-gtk2 sample codes

“How to install php gtk2 on linux?” - updated to use the beta release of PHP-GTK2

Monday, July 2nd, 2007

Updated the article How to install php gtk2 on linux? today to use the beta release of PHP-GTK2. Also included GtkExtra.

Some highlights:

  • Uses pango-1.16.4 (previously pango-1.14.7)
  • Uses gtk+-2.10.12 (previously gtk+-2.10.6)
  • Uses php-5.2.3 (previously php-5.1.6)
  • Uses php-gtk-2.0.0beta (previously php-gtk-2.0.0alpha)
  • Tried using cairo-1.2.6. Didn’t work. Switch back to cairo-1.2.4.
  • Included gtk+extra-2.1.1

If you have been running the alpha release of php-gtk2 on your linux, take this opportunity to upgrade to the beta release of php-gtk2 — a lot more exciting functionalities as highlighted here.

/kksou

http://www.kksou.com/php-gtk2
The place for php-gtk2 sample codes