PHP
  Home arrow PHP arrow Building Your Own System Tray Application Using PHP-GTK
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Building Your Own System Tray Application Using PHP-GTK
By: K.K.Sou
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2008-09-30


    Table of Contents:
  • Building Your Own System Tray Application Using PHP-GTK
  • Set up the main application
  • Second example of GtkStatusIcon
  • Display a popup menu
  • Popup menu on right mouse click
  • A note about subclassing a widget

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Building Your Own System Tray Application Using PHP-GTK
    ( Page 1 of 6 )

    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!

    In this article, I will use the Notepad application which we developed in the previous article and turn that into a system tray application. As usual, the complete sample code is available for download at the end of the article.

    Assumptions

    This article assumes that you have successfully installed PHP-GTK v2.0 or v2.0.1, with the glade library properly set up.

    It is also recommended that you have Glade 3 installed, so that you can load the glade file and explore the widgets and their respective settings.

    And lastly, it is assumed that you have read the article “Building Your Own Desktop Notepad Application Using PHP-GTK ” and are familiar with the framework, the various components, the classes and the methods used in the Notepad application. Try to understand that base code first so that you can appreciate the beauty of PHP-GTK in linking the system tray icon to the main application.

    So, are you ready? Let’s get started!

    Hello World GtkStatusIcon

    The system tray application is made possible in PHP-GTK with the help of the  GtkStatusIcon widget.

    To make it easier for you to understand this widget, I’ve developed a hello world GtkStatusIcon program. This is the simplest complete system tray application that can be written using PHP-GTK, with just 20 lines of code:

    <?php

    // setup main application

    $window = new GtkWindow();

    $window->set_size_request(240, 120);

    $window->connect_simple('destroy', array('Gtk','main_quit'));

    $label = new GtkLabel('Hello World, GtkStatusIcon!');

    $window->add($label);

    $window->hide_all();


    // setup system tray icon

    $statusicon = new GtkStatusIcon();

    $statusicon->set_from_stock(Gtk::STOCK_FILE);

    $statusicon->connect('activate', 'on_activate');


    Gtk::main();


    function on_activate($statusicon) {

    global $window;

    if ($window->is_visible()) $window->hide_all();

    else $window->show_all();

    }


    ?>

    When you first start the application, you will see only a file icon appearing in the system tray (the leftmost icon):



    When you click on the file icon, the main application window will open up:



    When you click on the file icon again, the application window will be hidden again.



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

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT