deadpickle has asked for the wisdom of the Perl Monks concerning the following question:

What I would like to do is take my tk programs and build them around a system tray for both Windows and Linux. I guess the idea would be that the icon would reside in the system tray. You could then right click on the icon and you would be given options. Also you could bring up the tk widgets that display the default settings for the program. I have done some reading and noticed that Win32::GUI and PerlTray have these kinds of options. The real question is if I could possibly blend these different widgets so that I would not have to rewrite my tk programs. Anyone have any ideas that could help me out?

Replies are listed 'Best First'.
Re: Windows/Linux System Tray and tk
by Anonymous Monk on Jul 14, 2007 at 09:40 UTC
    http://www.xray.mpe.mpg.de/mailing-lists/ptk/2001-10/msg00124.html
     
    > Hi all,
    > 
    > is it possible on Win32 to have the main window of a
    > Perl Tk application dissappear in the System Tray (this
    > area at the bottom right near the clock in the taskbar)?
    
    Perl/Tk itself has no method calls for it, but you
    can combine Win32::GUI and Perl/Tk. For an example look
    at the "tkruler" application at 
    http://ptktools.sourceforge.net
    
    Regards,
        Slaven
    
Re: Windows/Linux System Tray and tk
by zentara (Cardinal) on Jul 14, 2007 at 12:07 UTC
    Well just for your information, Gtk2 has the ability
    #!/usr/bin/perl use warnings; use strict; use Gtk2::TrayIcon; Gtk2->init; my $icon= Gtk2::TrayIcon->new("test"); $icon->add( Gtk2::Label->new("test") ); $icon->show_all; Gtk2->main;
    See Wooty for a little more pizazz.

    Now Gtk2 and Tk mainloops can be made to work together, so that may give you an option. Basically, you make a Tk timer to update the Gtk2 loop every 10 millisecs. You can do the reverse too .... let a Gtk2 timer do a $mw->update every so often.

    #!/usr/bin/perl -w use strict; use Gtk2; use Tk; my $mw = MainWindow->new(-title=>'Tk Window'); Gtk2->init; my $window = Gtk2::Window->new('toplevel'); $window->set_title('Gtk2 Window'); my $glabel = Gtk2::Label->new("This is a Gtk2 Label"); $window->add($glabel); $window->show_all; my $tktimer = $mw->repeat(10, sub{ Gtk2->main_iteration while Gtk2->events_pending; }); $mw->Button(-text=>' Quit ', -command => sub{exit} )->pack(); MainLoop;

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      I was going to try and test Gtk2::TrayIcon. I went to install the module and recieved this error:
      CPAN.pm: Going to build T/TS/TSCH/Gtk2-1.145.tar.gz *** can not find package gtk+-2.0 >= 2.0.0 *** check that it is properly installed and available in PKG_CONFIG_PA +TH at Makefile.PL line 67 Warning: No success on command[/usr/bin/perl Makefile.PL INSTALLDIRS=s +ite] TSCH/Gtk2-1.145.tar.gz /usr/bin/perl Makefile.PL INSTALLDIRS=site -- NOT OK Running make test Make had some problems, won't test Running make install Make had some problems, won't install Failed during this command: TSCH/Gtk2-1.145.tar.gz : writemakefile NO '/usr +/bin/perl Makefile.PL INSTALLDIRS=site' returned status 2304
      I believe that Gtk2 is installed since I have ran programs that used it before. Any ideas on how to fix this?
        Perl/Gtk2 is based on the c Gtk2 libs, so you need to install the c libs before the Perl modules that interface to them. Your linux distribution may have the runtime Gtk2 (Gnome libs) as a separate package, with the "devel libs" in another rpm (or whatever). SO if you can run Gtk2 programs, but can't compile them, install the "gtk2-gnome devel" package.

        If that is not possible, get the c libs yourself See Perl/Gtk2 Faq

        The basic libs are only needed, not the entire Gnome library set. They must be installed in a certain order

        pkgconfig cairo glib pango atk gtk2
        You usually have to keep the same pkgconfig location.... defaults to /usr/local, but it's easiest to keep them in /usr, so when you configure them, do
        ./configure --prefix=/usr

        Get the latest versions from Gtk+ downloads then install in the order above, then install the Perl modules in the same order.


        I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Windows/Linux System Tray and tk
by vkon (Curate) on Jul 14, 2007 at 16:06 UTC
    It is possible with Tk GUI using Tcl::Tk module,
    see how Tcl/Tk supports this at page http://wiki.tcl.tk/4090

    BR
    Vadim.