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

Hi Monks,

I'm very new to Tk so I'm not even sure it's Tk I really want to use.

I am using Lirc::Client to pick up remote control events.

I want a GUI of sorts (Tk or X11::Protocol or ...) that will change depending on what the user has pressed on the remote control.

The GUI will not be interactive itself, purely displaying data depending on the Lirc events caught.

How would you go about doing this?

I have a Tk GUI running and I have the Lirc::Client running but is there a way to get them to talk?

Thanks for your help.

J

Replies are listed 'Best First'.
Re: Tk and Lirc
by thundergnat (Deacon) on Feb 23, 2006 at 19:19 UTC

    I'm not running Linux so I can't really test this, but something like this should do what you are seeking.

    **Untested**

    use strict; use warnings; use Tk; use Tk::ROText; use Lirc::Client; use IO::Select; my $top = MainWindow->new; my $text = $top->ROText( -background => 'white', )->pack; my $lirc = Lirc::Client->new( 'progname' ); my $select = IO::Select->new(); $select->add( $lirc->sock ); $top->repeat( 200, \&getcodes ); MainLoop; sub getcodes{ if( my @ready = $select->can_read(0) ){ my @codes = $lirc->next_codes; $text->delete( '1.0', 'end' ) if @codes; for my $code (@codes){ $text->insert( 'end', "$code\n" ); #do whatever else you want with $code } } }
Re: Tk and Lirc
by zentara (Cardinal) on Feb 23, 2006 at 19:15 UTC
    If you could post a tiny snippet using Lirc::Client, showing how you get output, it would make it easier. Your problem is in finding a way to keep the Lirc read-loop going, without blocking the Tk GUI. It basically should be pretty easy, but you have 2 paths to take. One is let the Tk event-loop monitor the Lirc ( at fast time intervals ) and put the results into a text box. The other option, is to start the Tk gui, then let the Lirc read-loop run after the gui is up and running, and in your Lirc-read-loop print the output with $text->insert('end', $output\n"); When you do it that way, you will have to call $mw->update everytime thru the loop.

    But if you could show a small code snippet, we could show you the best ways.


    I'm not really a human, but I play one on earth. flash japh