> -----Original Message----- > From: Adrian Stovall [mailto:[EMAIL PROTECTED]] > Sent: Thursday, February 14, 2002 10:24 AM > To: [EMAIL PROTECTED] > Subject: What the heck is idletasks()? [was: Changing the Icon in a > Perl/T k toplevel/mainwindow...] > What is idletasks? More specifically, why is it absolutely > necessary in > this instance?
Warning: 2 short questions - relatively long reply !! #What is idletasks? ->idletasks is documented under the Tk::Widget documentation. Basically, it brings your application 'up-to-date' by processing all pending events. If idletasks is specified then no new events are processed and only idle callbacks are invoked. ->update is a similar beast but also takes into account user events. So you would use 'update' to also allow processing of button clicks, mouse motion, etc. type events. To process ALL pending events - for all widgets - use: $main->update; Now - one question remains: #why is it necessary in this particular case? I can only speculate that the window must be mapped before it can be changed by the window manager. I repeat the original code below: ################# use Tk; use strict; my $file="C:/Windows/Tiles.bmp"; my $mw = tkinit; $mw->resizable(0,0); $mw->idletasks; my $icon = $mw->Photo(-file => $file); $mw->iconimage($icon); MainLoop; ################## There are a few things which we know for certain. If you move the $mw->resizable(0,0) to, say, just before the MainLoop call - then the 'Tk' icon is shows up? What is that all about? I told it to use my $icon photo object? Did it use the object or not? Let's slow down the code by adding a few 'sleeps' to actually SEE what is happening and we use the iconimage command with no arguments to get the image it is currently using!! Run this one... #################### use Tk; use strict; my $file="C:/Windows/Tiles.bmp"; my $mw = tkinit; $mw->idletasks; sleep(3); my $icon = $mw->Photo(-file => $file); $mw->iconimage($icon); $mw->idletasks; sleep(3); $mw->resizable(0,0); MainLoop; ################### AH HAH ! It actually 'did' use the icon I told it to. Now we know a bit more - now here comes some more speculation. I think that the toplevel gets reparented on specific window manager commmands. $mw->resizable is likely one of those commands. Let's prove it by adjusting the script to print out the toplevel wrapper frame id. #################### use Tk; use strict; my $file="C:/Windows/Tiles.bmp"; my $mw = tkinit; $mw->idletasks; print "\nFrame 1: ",$mw->frame; sleep(3); my $icon = $mw->Photo(-file => $file); $mw->iconimage($icon); $mw->idletasks; print "\nFrame 2: ", $mw->frame; sleep(3); $mw->resizable(0,0); $mw->idletasks; print "\nFrame 3: ",$mw->frame; MainLoop; ################### Vindication ! A new wrapper frame id is indeed used. Your iconimage won't work now. Now let's go back and review the original code - this time adding in three print statements. The iconimage in the original code is indeed working on the correct frame. ################# use Tk; use strict; my $file="C:/Windows/Tiles.bmp"; my $mw = tkinit; print "\nOriginal Wrapper: ",$mw->frame; $mw->resizable(0,0); $mw->idletasks; print "\nWrapper after resizable: ", $mw->frame; my $icon = $mw->Photo(-file => $file); $mw->iconimage($icon); print "\nWrapper after iconimage: ", $mw->frame; MainLoop; ################## Sorry for the lengthy post !! Jack _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs