Re: Problem setting icon for Gtk2::StatusIcon
- From: January Weiner <january uni-muenster de>
- To: gtk-perl-list gnome org
- Subject: Re: Problem setting icon for Gtk2::StatusIcon
- Date: Tue, 3 Mar 2009 00:18:19 +0100
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,
Dear Zentara,
I am well aware of the problems with sleep() and I use it here only
for demonstration purposes only. I completely agree with that, and
also think it is partly irrelevant here.
First of all, even if you comment the line with sleep() in my original
script, the strange behaviour on my system remains. I strongly suspect
that a resize event is present although it should not be required, as
well as that the tray tries to reorganize itself -- but why should it?
after all, I change just the bitmap of a widget that should not
otherwise disappear/reappear or resize!. The reason that I observe it
on my system (and you don't observe on yours) may be the relatively
low screen resolution I have on my X40 and, consequently, a crowded
panel and a system tray.
I thought that "while( Gtk2->events_pending ) { Gtk2->main_iteration()
; }" should at least make sure that the icon is displayed before
proceeding with this sub (whatever happens next, sleep or not). I was
wrong, because, as Quentin pointed out, it is more complex than that
due to the (unnecessary, as the code with TrayIcon demonstrates)
interaction of with the panel.
Next, I think that the problem altogether is rather simple. I do not
need a complex GUI, just a flag, red or green, gtk-apply or
gtk-refresh.
Still, I have made an "old style" miniature program - a generic system
tray messenger. It reads commands from STDIN and displays icons in the
system tray.
See code at the end of this email.
unless you really know what is happening behind the scenes.
Learn about threads, forks, backticks, and piped-opens.
I am sure that there is plenty I have yet to learn.
Now I am going to be annoying, but please, believe me, that I really
value your advice (you already helped me out a few times with perl-tk
:-).
my $image1 = Gtk2::Image->new_from_stock('gtk-refresh', 'menu' ) ;
what is this for?
sub update {
Is there a real reason for using a global instead of passing arguments
to update?
$toggle *= -1; # +1 or -1 toggle
$toggle = !$toggle ;
if( $toggle ) { ... }
or:
$icon->set_from_stock( $toggle ? 'gtk-refresh' : 'gtk-apply' ) ;
Cheers,
j.
#!/usr/bin/perl
# kuku.pl
# a generic system tray applet
# usage: cat | kuku.pl
# (any program) | kuku.pl
# send commands to STDIN to control an applet in the system tray:
# command argument
#
# commands that are understood:
# icon icon_name
# use an icon from the stock (e.g. gtk-apply)
# file filename
# use an icon from a file
# blink 0
# blink 1
# turn blinking off and on
# tolltip text
# set the tooltip text
use strict ;
use warnings ;
use Switch ;
use Gtk2 -init ;
use Gtk2::Helper ;
my $status_icon = Gtk2::StatusIcon->new_from_stock("gtk-apply") ;
Gtk2::Helper->add_watch( fileno( STDIN ), 'in', \&read_input, $status_icon ) ;
Gtk2->main() ;
exit( 0 ) ;
sub read_input {
my ( $fileno, $signal, $icon ) = @_ ;
if( $signal ne 'in' ) {
print "ops: caught signal $signal\n" ;
Gtk2->main_quit() ;
return 1 ;
}
my $command ;
sysread( STDIN, $command, 4096 ) ;
chomp $command ;
my ( $cmd, $arg ) = split( /\s+/, $command, 2 ) ;
switch( $cmd ) {
case 'icon' { $icon->set_from_stock( $arg ) ; }
case 'file' { $icon->set_from_file( $arg ) ; }
case 'blink' { $icon->set_blinking( $arg ) ; }
case 'tooltip' { $icon->set_tooltip( $arg ) ; }
}
1 ;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]