Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Updating Perl/Tk Canvas based on network input

by fx (Pilgrim)
on Nov 12, 2010 at 17:18 UTC ( [id://871102]=perlquestion: print w/replies, xml ) Need Help??

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

Fellow Monks,

My mind is drawing a blank here so please help by providing the obvious pointers that I've clearly overlooked! A look through "Mastering Perl/Tk", even the chapter on "Interprocess Communicationwith Pipes and Sockets" hasn't helped...

I have a need to update the items on a Perl/Tk Canvas based on input being received from a TCP socket (background: trying to add a nice(r) frontend to an existing command line tool).

Basically I need to increment or decrement the height of some bars (drawn as rectangles or a series of stacked horizontal lines - not sure which is best yet) and update some text based on what is coming in the socket.

I'm having problems figuring out where to bind any callbacks to widgets/objects so that I can redraw/adjust my lines/rectangles/text.

Don't worry about what's coming in the socket - that's already working. Basically it's a count of running processes, number of things seen, etc, and everything works in the command line version. But I want pretty graphs!! With histogram bars that change height to represent the state of the various background tasks, etc, being represented by the data coming in the socket! :)

fx, Infinity is Colourless

  • Comment on Updating Perl/Tk Canvas based on network input

Replies are listed 'Best First'.
Re: Updating Perl/Tk Canvas based on network input
by zentara (Archbishop) on Nov 12, 2010 at 18:17 UTC
    I'm having problems figuring out where to bind any callbacks to widgets/objects so that I can redraw/adjust my lines/rectangles/text.

    Look how I did it in Tk Realtime data aquisition

    P.S. In Tk, you can always run little timers, that will auto refresh the canvas at a specified interval, like every 10 ms. Then all you need to do, is receive your data into an array, which the update sub would read from. 10 ms is very fast for human eyes to perceive, so it looks smooth.


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

      Ah yes, Tk::after seems to have sorted it. The "repeat" call as the one I was looking for. I had looked (very quickly, admittedly, and without much gusto to be honest...) for a class or function called "timer" in the Tk docs but the (IMHO) bizarre naming of Tk::after had led me to overlook it.

      However, Tk::after now in place and all working well. I now have a series of bars going up and down for pretty pictures!! :)

      fx, Infinity is Colourless

Re: Updating Perl/Tk Canvas based on network input
by choroba (Cardinal) on Nov 12, 2010 at 17:28 UTC
    Tk::fileevent might help you - if the socket is readable, you can update the rectangles.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://871102]
Approved by sierpinski
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-24 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found