Home arrow PHP arrow Page 6 - Building Your Own System Tray Application Using PHP-GTK

A note about subclassing a widget - PHP

You have seen how easy it is to write your own desktop applications using PHP-GTK in the article “Building Your Own Desktop Notepad Application Using PHP-GTK.” Once you have learned how to write desktop applications using PHP-GTK, you will be pleased to know that writing system tray applications is just a matter of adding a couple of lines of code. The bulk of your code remains exactly the same!

  1. Building Your Own System Tray Application Using PHP-GTK
  2. Set up the main application
  3. Second example of GtkStatusIcon
  4. Display a popup menu
  5. Popup menu on right mouse click
  6. A note about subclassing a widget
By: K.K.Sou
Rating: starstarstarstarstar / 7
September 30, 2008

print this article



One of the biggest advantages of subclassing a widget, as you can see from this example, is that you can neatly encapsulate all the signal handlers and related methods into a class.

As you start to build bigger and more complex PHP-GTK2 applications, you will find that the number of signal handlers corresponding to each widget become more and more difficult to manage and maintain.

The ability to encapsulate signal handlers and methods that are used only by the widget itself makes it particularly attractive for debugging and maintaining codes.

However, there are always two sides to a coin. The main “disadvantage” of subclassing a widget is that you are not able to use these subclassed widgets in Glade. Glade only recognizes standard GTK widgets. So all the widgets you use in Glade have to be the standard GTK widgets.

Of course, you can intermix both in your application. In this example, I used Glade in the main application, but used the subclass approach when setting up the system tray icon.

The complete sample code and glade file

Click on the following links to download the complete sample code and the corresponding glade file.


Final Words

We’ve come to the end of this article. In this tutorial, you saw how you can easily convert any standard PHP-GTK2 application into a system tray application.

You first set up the main application as per your original desktop application. Then you add a system tray icon with the help of the widget GtkStatusIcon.

The system tray icon behaves like a button, responding to both left and right mouse clicks. For a left mouse click, we usually hide or reveal the main application. For a right mouse click, we usually pop up a menu listing some commonly-used functions.

Now that you know how to create system tray applications, I hope you will have lots of fun in the next couple of days converting some of your existing PHP-GTK applications into system tray applications!

>>> More PHP Articles          >>> More By K.K.Sou

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: