Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Refreshing text without flicker with AddLabel using Win32::GUI

by Popcorn Dave (Abbot)
on Dec 07, 2006 at 05:03 UTC ( #588259=note: print w/replies, xml ) Need Help??


in reply to Re: Refreshing text without flicker with AddLabel using Win32::GUI
in thread Refreshing text without flicker with AddLabel using Win32::GUI

Thanks very much for your reply! You've helped me get leaps and bounds beyond where I was before.

I've finally had a few moments to try to play with what you suggested, and so naturally I'm stuck again. :)

From what you described, I need to pre-define my labels so that I can just refresh the text that is being assigned to them. So far, good. Since this is a stock quote app that I'm writing, I've got a list of stocks I read out of a config file and save to a hash.

My thought was to do something along the lines of:

my %stocks = (^DJI =>{sec_label => $main->AddLabel( stuff...), current_label => #current price of stock, arrow_label => #direction of stock, change_label => #price change, pctchg_label => #percent change} )

and I'm building this dynamically since I may add or delete stocks at any time and that's working out perfectly.

What I'm getting stuck on is how to put parameters in the

$stocks{$key}{arrow_label}->Text( $var );
part where I'm just updating the text. In the arrow_label part of the hash, I want to be able to change the color to either red or green depending if a stock is going down or up respectively. Is there even a way to do that or am I stuck with just text?

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

Replies are listed 'Best First'.
Re^3: Refreshing text without flicker with AddLabel using Win32::GUI
by bmann (Priest) on Dec 08, 2006 at 02:03 UTC
    Once the label is created, Win32::GUI doesn't expose a method to let you change the color. You might be able to use a custom Hook method to override painting the label.

    An alternative would be to create two labels, one red and one green. Make them identical in size and location in the window. Update the green one when the stock goes up, update the red one if the stock goes down.

      That's a great idea! I was thinking I could perhaps "destroy" the label and recreate it every time but that seemed a bit much to have to do. Since that label is the same size, overwriting it should be okay.

      Update:

      Worked like a charm!

      Surprisingly enough, it doesn't seem to complain that you've got two labels in the same place, and will actually update depending on which one you choose.

      use strict; use Win32::GUI; use constant COLOR => '#F4F2E8'; my ($redraw, $count); $count = 0; my $main = Win32::GUI::Window->new( -name => 'Main', -text => 'Redraw Test', -width => 200, -height => 100, -background => COLOR, -onTimer => \&redraw, ); my $arrow_font = Win32::GUI::Font->new( -name => "Wingdings", -size => 28, -bold => 1, ); $main->AddTimer( "redraw", 500 ); my $uparrow = $main->AddLabel( -text => ' ', -left => 55, -font => $arrow_font, -foreground => [255,0,0], -background => COLOR, -top => 10, ); my $dnarrow = $main->AddLabel( -text => ' ', -left => 55, -font => $arrow_font, -foreground => [0,255,0], -background => COLOR, -top => 10, ); $main->Show(); Win32::GUI::Dialog(); sub Main_Terminate { -1; } sub redraw{ $count++; if ($count%2){ $dnarrow->Text(chr(233)); } else {$uparrow->Text(chr(234));} }

      The only thing that I found didn't work is to put '' in the text for the initial label. Once I changed that to ' ' all worked just fine.

      Thanks again for the idea!

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://588259]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2019-06-19 08:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (87 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!