PHP
  Home arrow PHP arrow Page 2 - 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 - Set up the main application
    ( Page 2 of 6 )

    The program first sets up the application normally. It creates a new window and sets the size to 240 pixels by 120 pixels. We also register for the "destroy" signal so that the program will quit normally when the user clicks the close button.

    $window = new GtkWindow();

    $window->set_size_request(240, 120);

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

    We then add a label that says 'Hello World, GtkStatusIcon!' to the window.

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

    $window->add($label);

    Finally, we hide this window first so that the application starts hidden. It will only appear when the user clicks on the system tray icon.

    $window->hide_all();

    Now that the main application is set up, let us proceed to set up the status icon.

    Set up the system tray icon

    The key to understanding the GtkStatusIcon is to think of it as a “GtkButton.”

    It is a special “button” that you can place in the system tray, as opposed to within your main application.

    Setting up a system tray icon is as simple as creating a new instance of GtkStatusIcon and assigning an icon to it. In this example, we use the stock image Gtk::STOCK_FILE.

    $statusicon = new GtkStatusIcon();

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

    If you have a gif, jpg or png file, you can set the icon directly from the image file:

    $statusicon->set_from_file($image_filename);

    Since the tray icon behaves like a button, it responds to both left mouse and right mouse clicks.

    For a standard GtkButton, we use the "clicked" signal for a left mouse click, and the "button-press-event" signal for a right mouse click.

    For GtkStatusIcon, the signals are different. For a left mouse click, the signal is 'activate'. For a right mouse click, the signal is 'popup-menu'.

    In this hello world example, we will only monitor the left mouse click:

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

    In the callback function, we first test if the window is visible. If it is, we hide the window. If the window is hidden, we reveal it.

    function on_activate($statusicon) {

    global $window;

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

    else $window->show_all();

    }

    We will show how to process a right mouse click on the tray icon and a popup  menu in the next example.



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

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





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