
PapaGeek
User
Mar 21, 2014, 6:47 AM
Post #1 of 6
(5741 views)
|
Wait for and generate a user defined event within Tk windows
|
Can't Post
|
|
My process gives the user the ability to change the date on which reports are generated. This process performs web screen scraping of financial data and can take several minutes to complete. I created a window that asks if you are sure you want to change the date, and if the answer is yes, it uses a progress bar to show how the process is progressing. Within the menu code that can request the date change the coding looks like:
if ($requestedDate ne $lastUpdate) { say "Ask if its OK"; setUpdateDates ($lastUpdate, $requestedDate); ShowWindow('UpdateWindow'); say "return from update window"; } The problem is that the “ShowWindow” call returns immediately and does not wait for the actual update to occur. ShowWindow is part of a user written window manager that handles a stack of “named windows” allowing only one window to be visible at a time:
sub ShowWindow { my ($nextWindow) = @_; my $prevWindow = $WindowStack[-1]; push @WindowStack, $nextWindow; getWindow($prevWindow) -> withdraw(); getWindow($nextWindow) -> deiconify(); getWindow($nextWindow) -> raise(); } I want to change my code to look something like this:
if ($requestedDate ne $lastUpdate) { say "check for date change"; setUpdateDates ($lastUpdate, $requestedDate); CreateEvent(“UpdateIsCompleted”); ShowWindow('UpdateWindow'); WaitForEvent(“UpdateIsCompleted”); say "return from update window"; } Then inside my sub that asks and controls the update, I will add the line:
GenerateEvent(“UpdateIsCompleted”); Where needed. I’m looking for sample code on line for user defined event handling and can’t seem to find any. Can this be done in Perl?
|