Re: Flashing label



On Wed, 2004-07-14 at 04:05, Jan Hudec wrote:
On Wed, Jul 14, 2004 at 16:16:58 +1000, Daniel Kasak wrote:
What would be involved in making a label flash?
I'd have to do something like create a new thread that wakes up every so 
often and alternates the colour of the label, right?

You should seldom need or use threads in Gtk application. A Gtk
application runs in an event loop (Glib::MainLoop). That event loop
takes care of user actions, but can also deal with other things.
One of them is "idle", which happens every time there are no other
events to process and "timeout", which happens after given time, perhaps
periodicaly. You can do background computation with idles
(Glib::Idle->add). You can do periodic things with timeouts
(Glib::Timeout->add). You can wait for input on arbitrary filedescriptors
with io watches (Glib::IO->add_wathc).

for the most part stay away from idles as they'll peg cpu usage.

I'd had a brief look at threading under Perl, and I'm getting confused 
already ( nothing new, I know ). It looks like there are a number of 
methods of threading under Perl. I also seem to remember getting a 
warning when I was compiling Perl that threading was disabled unless I 
explicitely enabled it.

Gtk2-perl does not play too well with perl threading. There were some GC
issues. I believe they are fixed in latest devel, though I am not sure.

1.05x (soon to be 1.060) will allow the use of perl ithreads although
the situations where they're truly required are few and as you mentioned
this isn't one of them. if you access gui objects from more than one
thread there's quite a bit of overhead in that you must use gdk's
protection mechanisms (mutexes etc.) to prevent nasty problems.

the best source of info i've found for threading in perl is the perl
thread tutorial:
        http://www.perldoc.com/perl5.8.0/pod/perlthrtut.html
but don't do it unless you're left with no other choice.

-rm




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]