Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Fellow monks,

I'm still relatively new to the world of Win32::GUI and so I'm trying to port a working Tk stock price app that I wrote. BBFU was kind enough to point me to the direction of Timer for the timed calling of a subroutine, but now I'm stumped by the actual act of refreshing text labels.

In my Tk program, I write the labels, and when I go to refresh, I replace them all with blank lines, then rewrite them. Maybe not the best way to do it, but in Tk I'm not noticing any delay in the "erasing" and the "rewriting".

My first thought was to write a small test app to see if I could figure this out, but I'm stumped as to why once the string is at it's max length, it won't "erase" the extra bits when fed a smaller string.

use strict; use Win32::GUI(); my $interval = 100; my $main = Win32::GUI::Window->new( -name => 'Main', -width => 150, -height => 100, -onTimer => \&redraw_Timer, ); $main->AddTimer( "redraw_Timer", $interval); $main->Show(); Win32::GUI::Dialog(); sub Main_Terminate { -1; } sub redraw_Timer{ my $temp = localtime; return $main->AddLabel(-text => $temp); }

Now when translating this to my stock price app, I've got 8-10 stocks that I'm watching, and obviously as prices flucuate, I'm going to be stung by having something at +.90 perhaps go to +1.12, then down to +.81 and I'm going to have extra characters that are still being displayed.

In my stock app I'm displaying the initial results like this:

foreach (@test) { $_ =~ s/"//g; my (@color) = $change > 0 ? [ 0, 0, 255 ] : [ 255, 0, 0 ]; $main->AddLabel( -text => $arrow, -font => $arrow_font, -left => 55, -foreground => @color, -background => COLOR, -top => $h, ); # current security price $main->AddLabel( -text => pack( "A10", $current ), -font => $sec_font, -left => 70, -top => $h, -background => COLOR, ); # change in security price $main->AddLabel( -text => pack( "A10", $change ), -font => $sec_font, -left => 130, -top => $h, -background => COLOR, ); }

where test is a quote delimited string returned from Yahoo Finance. I'm not bothering with Text::CSV as it's never returning anything with an embedded apostrophe in it.

So when I want to update the information, I'm using the same technique but blank lines instead of the data that I'm scraping.

Is there a better way to go about displaying the data in one fell swoop that I've missed? If so, can someone point me to either the spot in the docs or some kind of tutorial?

Thanks in advance!

Revolution. Today, 3 O'Clock. Meet behind the monkey bars.

In reply to Refreshing text without flicker with AddLabel using Win32::GUI by Popcorn Dave

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2022-01-18 22:18 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (54 votes). Check out past polls.