Re: [perl-win32-gui] $Window-TextField-Text()
Eric Bennett wrote: On Fri, 15 Dec 2000, Robert Sherman wrote: any idea as to why in the script below, in sub Button2_Click, TextField1 does not change to "Processing..." prior to running the process_file sub? A similar call in the process_file sub changes the field to "Done!" when it finishes, and that call works fine... The Text method is queueing a message to TestField1 to change, but that message cannot be acted upon until the current *_Click event exits. What ends up happening is that process_file runs, then afterward the text changes twice quickly as the messages are processed. correct, and very well explained! thanks Eric ;-) How to fix it? I don't have enough experience with Win32::GUI. I can help here. in the process_file sub, put a call to DoEvents() inside the loop. this will ensure that all queued messages are processed before going on with the loop: foreach $line (INFILE) { $Window-DoEvents(); # body of the loop... } this will, of course, make your loop run slightly slower (almost irrelevant if there is no activity on the window). but there is the advantage (other than having the Textfield saying "Processing...") of being able to stop the loop in the middle by killing the window, or with a 'dedicated' stopbutton, for example. cheers, Aldo __END__ $_=q,just perl,,s, , another ,,s,$, hacker,,print;
Re: [perl-win32-gui] $Window-TextField-Text()
THANK YOU!! THANK YOU! THANK YOU! now my Stop button works in my program. I could never figure out why it wasn't registering the click. Jonathan Southwick [EMAIL PROTECTED] - Original Message - From: "Aldo Calpini" [EMAIL PROTECTED] To: "Eric Bennett" [EMAIL PROTECTED] Cc: "Robert Sherman" [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Monday, December 18, 2000 11:20 AM Subject: Re: [perl-win32-gui] $Window-TextField-Text() Eric Bennett wrote: On Fri, 15 Dec 2000, Robert Sherman wrote: any idea as to why in the script below, in sub Button2_Click, TextField1 does not change to "Processing..." prior to running the process_file sub? A similar call in the process_file sub changes the field to "Done!" when it finishes, and that call works fine... The Text method is queueing a message to TestField1 to change, but that message cannot be acted upon until the current *_Click event exits. What ends up happening is that process_file runs, then afterward the text changes twice quickly as the messages are processed. correct, and very well explained! thanks Eric ;-) How to fix it? I don't have enough experience with Win32::GUI. I can help here. in the process_file sub, put a call to DoEvents() inside the loop. this will ensure that all queued messages are processed before going on with the loop: foreach $line (INFILE) { $Window-DoEvents(); # body of the loop... } this will, of course, make your loop run slightly slower (almost irrelevant if there is no activity on the window). but there is the advantage (other than having the Textfield saying "Processing...") of being able to stop the loop in the middle by killing the window, or with a 'dedicated' stopbutton, for example. cheers, Aldo __END__ $_=q,just perl,,s, , another ,,s,$, hacker,,print;
[perl-win32-gui] $Window-TextField-Text()
any idea as to why in the script below, in sub Button2_Click, TextField1 does not change to "Processing..." prior to running the process_file sub? A similar call in the process_file sub changes the field to "Done!" when it finishes, and that call works fine... TIA -rob = use Win32::GUI; $Window = new Win32::GUI::Window( -name = "Window", -title = "EXCISE", -left = 100, -top= 100, -width = 430, -height = 200, -menu = $Menu, ); $Window-AddTextfield( -name = "TextField1", -left = 30, -top= 10, -width = 300, -height = 20, -prompt = " Input file:", ); $Window-AddTextfield( -name = "TextField2", -left = 30, -top= 40, -width = 300, -height = 20, -prompt = " Output file name:", ); $Window-AddTextfield( -name = "TextField3", -left = 30, -top= 70, -width = 50, -height = 20, -prompt = " Keep this many fields from the beginning of each record:", ); $Window-AddTextfield( -name = "TextField4", -left = 30, -top= 100, -width = 50, -height = 20, -prompt = " Keep this many fields from the end of each record:", ); $Window-AddButton( -name = "Button1", -left = 150, -top= 135, -width = 90, -height = 30, -text = "Browse for file", ); $Window-AddButton( -name = "Button2", -left = 245, -top= 135, -width = 90, -height = 30, -text = "Process file", ); $Window-Show(); sub Button1_Click { $file = get_file_name; $path = $file; $path =~ s/(^.*\\)(.*$)/$1/; $Window-TextField1-Text("$file"); } sub Button2_Click { if ($file) { $front = $Window-TextField3-Text; $end = $Window-TextField4-Text; $outfile = $Window-TextField2-Text; $Window-TextField1-Text("Processing..."); process_file($file, $front, $end); } else { $file = $Window-TextField1-Text; $path = $file; $path =~ s/(^.*\\)(.*$)/$1/; $front = $Window-TextField3-Text; $end = $Window-TextField4-Text; $outfile = $Window-TextField2-Text; $Window-TextField1-Text("Processing..."); process_file($file, $front, $end); } } sub Window_Terminate { return -1; } sub get_file_name { $ret = GUI::GetOpenFileName( -title = "File Browser", -file = "\0" . " " x 256, -filter = [ "Text documents (*.txt)" = "*.txt", "All files", "*.*", ], ); return $ret; } sub process_file { my $file = shift; my $front = shift; my $end = shift; ## ##begin excise code ## open (INFILE, "$file"); open (OUTFILE, "$outfile"); foreach $line (INFILE) { @output_front = (); @output_end = (); $output_string = 0; $count_shift = 0; $count_pop = 0; @array = split (/,/,$line); while ($count_shift $front){ @shifted = shift @array; push (@output_front, @shifted); $count_shift++; } while ($count_pop $end){ @popped = pop @array; push (@output_end, @popped); $count_pop++; } @rev_output_end = reverse @output_end; push (@output_front, @rev_output_end); $output_string = join (",", @output_front); print OUTFILE ("$output_string"); } ## ## end excise code ## $Window-TextField1-Text("Done!"); } Win32::GUI::Dialog();
Re: [perl-win32-gui] $Window-TextField-Text()
On Fri, 15 Dec 2000, Robert Sherman wrote: any idea as to why in the script below, in sub Button2_Click, TextField1 does not change to "Processing..." prior to running the process_file sub? A similar call in the process_file sub changes the field to "Done!" when it finishes, and that call works fine... $Window-TextField1-Text("Processing..."); process_file($file, $front, $end); The Text method is queueing a message to TestField1 to change, but that message cannot be acted upon until the current *_Click event exits. What ends up happening is that process_file runs, then afterward the text changes twice quickly as the messages are processed. How to fix it? I don't have enough experience with Win32::GUI. You could set a timer to execute process_file. Other ways would be to post a message which triggers a callback and put it in there. You could also try putting a yield in front of process_file. Yield will usually cause events to be processed. Just guessin' - Eric B.