Home > Archive > PerlTk > October 2004 > system tray icon under perl tk
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
system tray icon under perl tk
|
|
| buildmorelines 2004-10-11, 8:56 am |
| Is there a NATIVE, PORTABLE (will apear in linux and windows), way to
do a tray icon near clock in perl/TK without resorting to OS specific
APIs/modules?
| |
| zentara 2004-10-11, 8:56 am |
| On 11 Oct 2004 04:34:21 -0700, bulk88@hotmail.com (buildmorelines)
wrote:
>Is there a NATIVE, PORTABLE (will apear in linux and windows), way to
>do a tray icon near clock in perl/TK without resorting to OS specific
>APIs/modules?
I don't know if it meets your requirements, but here is how I made
a toolbar icon for a Control Panel I made for Tk::Zinc. This is just
the chopped down part of the code for the icon itself.
The full code can be seen here.
http://www.perlmonks.org/index.pl?node_id=310044
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
#minimum 8 buttons
my $numberbuttons = 8;
my $motion_flag = 1;
my $delay = 10;
my $width = 25*$numberbuttons;
my $height = 100;
my %bgroup;
my $textmessage = 'How's the scroll working? Right Click Blue stops
scroll.';
my $iconb64 =
'R0lGODdhEAAQAKUAAAAAAC8wL72+vcK8sOCxWfi
oFeqtO+6sMO6sMuSvTY6Ojt6yXv+lAF5fXu6r
L0BAAP/SAA8PD///AP/oAIBSAK+CL0dHR5aAVkApAL+/AP+8AHN0c6ysrM64jvymCcC9s9qzau2s
NOauR+auSOSvTtuyZ15eXsK8rcS8rP//////////////////////////////////////////////
/////////////////////////////////////////////ywAAAAAEAAQAAAGb0CAUBgQDARIQWDI
LBIKhgMioWQKFQuGdrtoWIvbsENgbWTDWzITi05b
hQ8IBK0eRgAPiV4yoVTqABYXFBh7EhlvAGZb
GnIPiRtnbRxlknRlHW0MY28CHm0dXlYCHyAhIiMk
JYBDJkgnAigCCktDQQA7';
my $mw = MainWindow->new;
$mw->geometry($width.'x'.$height.'-15-15'); # lower right hand corner
$mw->configure(-background => 'black');
$mw->resizable(0,0);
$mw->overrideredirect(1);
$mw->withdraw;
#bottombaricon setup
my $mwicon = MainWindow->new;
$mwicon->geometry('16x16-80-0'); # lower right hand corner
$mwicon->resizable(0,0);
$mwicon->configure(-background => 'black', -cursor => 'hand2');
$mwicon->overrideredirect(1);
my $icon = $mwicon->Photo(-data => $iconb64);
$mwicon->Label(-image => $icon)->pack(-expand => 1, -fill => 'both');
$mwicon->Tk::bind("<Button-1>",sub{$mw->deiconify} );
###################
MainLoop;
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
| |
| buildmorelines 2004-10-12, 3:56 am |
| Sorry its not. I need it in the tray, and for it to be portable, your
code and the one at perlmonks doesnt seem to do that.
zentara <zentara@highstream.net> wrote in message news:<asukm0ll5rnajhke4rhurtgnhh9ni2mr3g@4ax.com>...
> On 11 Oct 2004 04:34:21 -0700, bulk88@hotmail.com (buildmorelines)
> wrote:
>
>
> I don't know if it meets your requirements, but here is how I made
> a toolbar icon for a Control Panel I made for Tk::Zinc. This is just
> the chopped down part of the code for the icon itself.
>
> The full code can be seen here.
> http://www.perlmonks.org/index.pl?node_id=310044
>
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> use Tk;
>
> #minimum 8 buttons
> my $numberbuttons = 8;
> my $motion_flag = 1;
> my $delay = 10;
>
> my $width = 25*$numberbuttons;
> my $height = 100;
> my %bgroup;
> my $textmessage = 'How's the scroll working? Right Click Blue stops
> scroll.';
>
>
> my $iconb64 =
> 'R0lGODdhEAAQAKUAAAAAAC8wL72+vcK8sOCxWfi
oFeqtO+6sMO6sMuSvTY6Ojt6yXv+lAF5fXu6r
> L0BAAP/SAA8PD///AP/oAIBSAK+CL0dHR5aAVkApAL+/AP+8AHN0c6ysrM64jvymCcC9s9qzau2s
> NOauR+auSOSvTtuyZ15eXsK8rcS8rP//////////////////////////////////////////////
> /////////////////////////////////////////////ywAAAAAEAAQAAAGb0CAUBgQDARIQWDI
> LBIKhgMioWQKFQuGdrtoWIvbsENgbWTDWzITi05b
hQ8IBK0eRgAPiV4yoVTqABYXFBh7EhlvAGZb
> GnIPiRtnbRxlknRlHW0MY28CHm0dXlYCHyAhIiMk
JYBDJkgnAigCCktDQQA7';
>
>
> my $mw = MainWindow->new;
> $mw->geometry($width.'x'.$height.'-15-15'); # lower right hand corner
> $mw->configure(-background => 'black');
> $mw->resizable(0,0);
> $mw->overrideredirect(1);
> $mw->withdraw;
>
> #bottombaricon setup
> my $mwicon = MainWindow->new;
> $mwicon->geometry('16x16-80-0'); # lower right hand corner
> $mwicon->resizable(0,0);
> $mwicon->configure(-background => 'black', -cursor => 'hand2');
> $mwicon->overrideredirect(1);
> my $icon = $mwicon->Photo(-data => $iconb64);
> $mwicon->Label(-image => $icon)->pack(-expand => 1, -fill => 'both');
> $mwicon->Tk::bind("<Button-1>",sub{$mw->deiconify} );
> ###################
> MainLoop;
| |
| zentara 2004-10-12, 8:55 am |
| On 11 Oct 2004 19:50:02 -0700, bulk88@hotmail.com (buildmorelines)
wrote:
>Sorry its not. I need it in the tray, and for it to be portable, your
>code and the one at perlmonks doesnt seem to do that.
[color=darkred]
I don't think you will find anything that is portable. Even within
Linux, there are so many different Window Managers, that
there can be no portability; made even harder to be compatible
between linux and windows.
Someone just asked recently how to get an icon onto the KDE
toolbar. No one has done it yet.
Your best bet, is to use something like Tk::Toolbar, and create
your own toolbar.
Alot of people are looking for this. If you find a way, let us know.
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
| |
| buildmorelines 2004-10-15, 3:56 am |
| zentara <zentara@highstream.net> wrote in message news:<tlinm0hb1jvohv9s2m22pcdrmi91mk6j9i@4ax.com>...
> On 11 Oct 2004 19:50:02 -0700, bulk88@hotmail.com (buildmorelines)
> wrote:
>
>
>
> I don't think you will find anything that is portable. Even within
> Linux, there are so many different Window Managers, that
> there can be no portability; made even harder to be compatible
> between linux and windows.
>
> Someone just asked recently how to get an icon onto the KDE
> toolbar. No one has done it yet.
>
> Your best bet, is to use something like Tk::Toolbar, and create
> your own toolbar.
>
> Alot of people are looking for this. If you find a way, let us know.
There sort is, wxwidgets/wxwindows gui toolkit which has a wrapper for
perl called wxperl. Wxwidgets is to impliment a portable gui and
library that uses the native os's widgets and look and feel (no UNIX
look on win32 how TK used to have). They have a taskbar icon thing
that works under all win32s, and under gnome (after a certain
version), and whatever window managers are compatible to
freedesktop.org tray icon specification (some new KDEs support it, and
some other really new managers).
My problem with wxwidgets is that that I am a really newbie
programmer, self tought perl person, who doesnt know much on what they
are doing (I written about 120 lines so far in perl and they WORK
(thank god for TMTOWTDI)). And Wxperl's documantation is a 7 page
hello world tutorial and a brief couple magazine articles. They rest
of the documantation is a copy of the documantation for the C
wxwidgets, with notes if wxperl implimented it or not (yes or no style
note). I do not know or understand any C/C++ what so ever.
Perl/TK has many very nice books, and I think I have a more realistic
chance of being able to use it, than Wxperl, due to the documantation.
So I am asking if I its wxperl or the highway? or if I can use
perl/tk?
| |
| zentara 2004-10-15, 8:56 am |
| On 14 Oct 2004 18:54:10 -0700, bulk88@hotmail.com (buildmorelines)
wrote:
>zentara <zentara@highstream.net> wrote in message news:<tlinm0hb1jvohv9s2m22pcdrmi91mk6j9i@4ax.com>...
>
>
>There sort is, wxwidgets/wxwindows gui toolkit which has a wrapper for
>perl called wxperl. Wxwidgets is to impliment a portable gui and
>library that uses the native os's widgets and look and feel (no UNIX
>look on win32 how TK used to have). They have a taskbar icon thing
>that works under all win32s, and under gnome (after a certain
>version), and whatever window managers are compatible to
>freedesktop.org tray icon specification (some new KDEs support it, and
>some other really new managers).
>
>My problem with wxwidgets is that that I am a really newbie
>programmer, self tought perl person, who doesnt know much on what they
>are doing (I written about 120 lines so far in perl and they WORK
>(thank god for TMTOWTDI)). And Wxperl's documantation is a 7 page
>hello world tutorial and a brief couple magazine articles. They rest
>of the documantation is a copy of the documantation for the C
>wxwidgets, with notes if wxperl implimented it or not (yes or no style
>note). I do not know or understand any C/C++ what so ever.
>
>Perl/TK has many very nice books, and I think I have a more realistic
>chance of being able to use it, than Wxperl, due to the documantation.
>So I am asking if I its wxperl or the highway? or if I can use
>perl/tk?
Thanks for the tip about Wxperl....yeah I know, it's alot tougher to
get a handle on it.
Hopefully one day, someone will get those libs to work with tcl and Tk.
Please keep us informed of what you find, it would make a great module.
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
| |
| Ala Qumsieh 2004-10-15, 3:57 pm |
| zentara wrote:
> Please keep us informed of what you find, it would make a great module.
I had a bit of code that did something similar using Win32::API and the
Shell_NotifyIcon function. It wasn't very stable though. I'll try to
look it up. Perhaps it can inspire someone.
--Ala
| |
| buildmorelines 2004-10-16, 3:56 pm |
| Ala Qumsieh <notvalid@email.com> wrote in message news:<foSbd.13698$nj.8308@newssvr13.news.prodigy.com>...
> zentara wrote:
>
> I had a bit of code that did something similar using Win32::API and the
> Shell_NotifyIcon function. It wasn't very stable though. I'll try to
> look it up. Perhaps it can inspire someone.
>
> --Ala
I dont want to use raw win32 API, I want it to have a realistic chance
of being portable, and I dont really want to muck with linux/unix
(perl gtk modules), but I need it to be portable to linux/unix.
| |
| Ala Qumsieh 2004-10-16, 3:56 pm |
| buildmorelines wrote:
> I dont want to use raw win32 API, I want it to have a realistic chance
> of being portable, and I dont really want to muck with linux/unix
> (perl gtk modules), but I need it to be portable to linux/unix.
What you are asking for is impossible. Putting an icon in the system
tray is very dependent on the API of the window manager you're using. So
even under linux, KDE code and GNOME code will be different. Any
portable code will necessarily have to check what window manager it is
running under, and execute the appropriate system calls. The best you
can do is wrap the window manager-specific code in if() statements that
will execute the correct calls.
--Ala
| |
| buildmorelines 2004-10-19, 8:56 pm |
| Ala Qumsieh <notvalid@email.com> wrote in message news:<csacd.6614$6q2.55@newssvr14.news.prodigy.com>...
> buildmorelines wrote:
>
> What you are asking for is impossible. Putting an icon in the system
> tray is very dependent on the API of the window manager you're using. So
> even under linux, KDE code and GNOME code will be different. Any
> portable code will necessarily have to check what window manager it is
> running under, and execute the appropriate system calls. The best you
> can do is wrap the window manager-specific code in if() statements that
> will execute the correct calls.
>
> --Ala
I was trying to ask if TK has a portable tray icon thing in it. Guess
it doesnt. I think when I have the time I will just have to use
WxPerl.
If/elsifing and the code maintenence associated with that is too much
work for me.
| |
| Slaven Rezic 2004-10-19, 8:56 pm |
| bulk88@hotmail.com (buildmorelines) writes:
> zentara <zentara@highstream.net> wrote in message news:<tlinm0hb1jvohv9s2m22pcdrmi91mk6j9i@4ax.com>...
>
>
> There sort is, wxwidgets/wxwindows gui toolkit which has a wrapper for
> perl called wxperl. Wxwidgets is to impliment a portable gui and
> library that uses the native os's widgets and look and feel (no UNIX
> look on win32 how TK used to have). They have a taskbar icon thing
> that works under all win32s, and under gnome (after a certain
> version), and whatever window managers are compatible to
> freedesktop.org tray icon specification (some new KDEs support it, and
> some other really new managers).
I have only an ancient version of KDE (I think it's 2.x). With a
little bit playing with property() I was able to display a Perl/Tk
toplevel in the tray:
use Tk;
$top = new MainWindow;
$top->withdraw;
$t = $top->Toplevel();
$t->Button(-text => "X",
-command => sub {
$t->messageBox(-message => "Yes!");
})->pack;
$t->update;
my($type,@windows) = $top->property('get', '_KDE_NET_SYSTEM_TRAY_WINDOWS', 'root');
$top->property('set', '_KDE_NET_SYSTEM_TRAY_WINDOWS', "WINDOW", 32, [@windows, ($t->wrapper)[0]], "root");
$top->property('set', '_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR', 'WINDOW', 32, [0x23], ($t->wrapper)[0]);
warn join ", ", $top->property('get', '_KDE_NET_SYSTEM_TRAY_WINDOWS', 'root');
MainLoop;
__END__
Note that in the script above the root window is hardcoded with the
value 0x23. In a real module the value should be determined with the
help of X11::Protocol or the "xwininfo -root" program (or is it
possible with Perl/Tk functions?).
Newer KDE versions probably use an official freedesktop.org property,
usually named with a _NET_ prefix. With "xprop -root" you can list all
available properties on your system. It should not be too hard to
adapt my example for newer window managers.
For Windows, there was a suggestion to use Win32::API. Either that or
Win32::GUI. Take a look at my "tkruler" application, especially at the
"create_systray_icon" function there.
All this put together would be a nice contribution to CPAN? Feel free
to be a volunteer :-)
Regards,
Slaven
--
Slaven Rezic - slaven <at> rezic <dot> de
need xpm or ppm output from GD?
http://search.cpan.org/search?mode=...ery=GD::Convert
| |
| buildmorelines 2004-10-21, 8:56 pm |
| Slaven Rezic <slaven@rezic.de> wrote in message news:<87wtxm30u9.fsf@vran.herceg.de>...
>
> I have only an ancient version of KDE (I think it's 2.x). With a
> little bit playing with property() I was able to display a Perl/Tk
> toplevel in the tray:
>
> use Tk;
>
> $top = new MainWindow;
> $top->withdraw;
>
> $t = $top->Toplevel();
> $t->Button(-text => "X",
> -command => sub {
> $t->messageBox(-message => "Yes!");
> })->pack;
> $t->update;
>
> my($type,@windows) = $top->property('get', '_KDE_NET_SYSTEM_TRAY_WINDOWS', 'root');
> $top->property('set', '_KDE_NET_SYSTEM_TRAY_WINDOWS', "WINDOW", 32, [@windows, ($t->wrapper)[0]], "root");
> $top->property('set', '_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR', 'WINDOW', 32, [0x23], ($t->wrapper)[0]);
>
> warn join ", ", $top->property('get', '_KDE_NET_SYSTEM_TRAY_WINDOWS', 'root');
>
> MainLoop;
>
> __END__
>
> Note that in the script above the root window is hardcoded with the
> value 0x23. In a real module the value should be determined with the
> help of X11::Protocol or the "xwininfo -root" program (or is it
> possible with Perl/Tk functions?).
>
> Newer KDE versions probably use an official freedesktop.org property,
> usually named with a _NET_ prefix. With "xprop -root" you can list all
> available properties on your system. It should not be too hard to
> adapt my example for newer window managers.
>
> For Windows, there was a suggestion to use Win32::API. Either that or
> Win32::GUI. Take a look at my "tkruler" application, especially at the
> "create_systray_icon" function there.
>
> All this put together would be a nice contribution to CPAN? Feel free
> to be a volunteer :-)
>
> Regards,
> Slaven
I read tkruler (uninstalled version, dunno if installation will change
the actual program) and I see how you implimented systray icon,
unfortuantly, its still using native win32. Atleast if I ever do
decide to use win32s in perl, I have a real world code example.
| |
| Slaven Rezic 2004-10-21, 8:56 pm |
| bulk88@hotmail.com (buildmorelines) writes:
> Slaven Rezic <slaven@rezic.de> wrote in message news:<87wtxm30u9.fsf@vran.herceg.de>...
>
>
> I read tkruler (uninstalled version, dunno if installation will change
> the actual program) and I see how you implimented systray icon,
> unfortuantly, its still using native win32. Atleast if I ever do
> decide to use win32s in perl, I have a real world code example.
There's no way around it. Unless the systray functionality is built
into Tk (but I never saw a TIP (= Tcl/Tk change proposal) on this topic)
you will have to either
* code the beast as a XS extension to perl
* or use one of the perl modules accessing the Win32 API like
Win32::API or Win32::GUI
For the X11 side you can use my sample code above. Encapsulate both
parts into a module or function which includes
sub make_systray_icon {
if ($^O eq 'MSWin32') {
use windows implementation from tkruler
} else {
use X11 implementation like the sample code above
}
}
and you're done.
Regards,
Slaven
--
Slaven Rezic - slaven <at> rezic <dot> de
Berlin Perl Mongers - http://berlin.pm.org
|
|
|
|
|