Re: Problem setting icon for Gtk2::StatusIcon



On Mon, 2 Mar 2009 20:49:05 +0100
January Weiner <january weiner gmail com> wrote:

Here is similar code, that does not use sleep.
I sped it up to 3 secs for visual effect.  Sleep will get
you into trouble in eventloop apps.... do not design with it,
unless you really know what is happening behind the scenes.
Learn about threads, forks, backticks, and piped-opens.

#!/usr/bin/perl
use strict   ;
use warnings ;
use Gtk2::TrayIcon;

Gtk2->init;

my $toggle = 1;

my $status_icon = Gtk2::TrayIcon->new("test");
my $image = Gtk2::Image->new_from_stock('gtk-apply', 'menu' ) ;
my $image1 = Gtk2::Image->new_from_stock('gtk-refresh', 'menu' ) ;

$status_icon->add( $image ) ;
$status_icon->show_all;

# speeded up the 5 sec delay
my $timer = Glib::Timeout->add( 2000, \&update ) ;

Gtk2->main() ;
exit( 0 ) ;

sub update {
  $toggle *= -1;  # +1 or -1 toggle

# thread or fork off long running subs here and change icon
# accordingly


  if($toggle < 0){
     $image->set_from_stock('gtk-refresh', 'menu' ) ;
     while( Gtk2->events_pending() ) { Gtk2->main_iteration() ; }
    }else{
       $image->set_from_stock('gtk-apply', 'menu' ) ;
       while( Gtk2->events_pending() ) { Gtk2->main_iteration() ; }
  }

 return 1 ;
}

__END__

zentara

-- 
I'm not really a human, but I play one on earth.
http://www.zentara.net/~zentaran/My_Petition_to_the_Great_Cosmic_Conciousness.html 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]