At 02:54 PM 24/04/2001 -0700, you wrote: Hi,
You may want to see my script attached. I still don't quite understand how to get the cancel to work while download is in progress. I always appreciate your help, as I am new to gui development. thankyou. Jeremy >| is there a way for it to listen while it downloads for the >| cancel event? >Your sub Cancel_Click should NOT exit, however, the exit statement is never >reached due to the return. >Return -1 is correct, this is how you tell the GUI to end the message loop. >Now the message loop exits back into your script from where it was called. >At this point, YOU must watch for the GUI to exit: > >last if Win32::GUI::DoEvents() < 0; > >instead of just Win32::GUI::DoEvents(); > >The chain goes: >1) you call Dialog() or DoEvents() inside GUI >2) GUI calls subs according to messages - like Cancel_Click when Exit button >is clicked. >3) your sub is active >4) your sub returns -1 >5) GUI stops looking for messages and returns -1 >6) your script continues > >Have fun, >Harald > >_______________________________________________ >Perl-Win32-GUI-Users mailing list >Perl-Win32-GUI-Users@lists.sourceforge.net >http://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users >
use Win32::GUI; use Win32::API; use Net::FTP; use Cwd; [EMAIL PROTECTED] = file, 0 # mode (send/recieve),1 # mode (ascii/binary),2 # ftphost, 3 # user, 4 # pass, 5 # port, 6 # passive (y/n) 7 # CWD 8 # # # #if (@ARGV) { TransferSetup(); #}else { # print "***Error: Not a StandAlone program\n"; # sleep 1; #} sub TransferSetup() { my $file = 'Killing Heidi - Mascara.mp3'; # the file to recieve my $SendRecieveMode = 'recieve'; # which way is the transfer my $TransferMode = 'asc'; # binary or ascii my $FtpHost = 'jeremy'; # hostname my $UserName = 'jeremy'; #user my $Pass = 'blank'; #pass my $Port = '21'; #port my $Passive = '0'; # 0 for nonpassive, 1 for passive my $CWD = 'D:\backup\perl stuff\perltidy-20010304\perltidy-20010304\\'; $ftp = Net::FTP->new($FtpHost, Timeout => 60) || exit; $ftp->login("$UserName","$Pass") || exit; $ftp->port($Port); if ( $TransferMode eq "bin" ) { $ftp->type(binary()); } if ($SendRecieveMode eq "recieve") { &RecieveTransfer($file,$CWD,$TransferMode); } else { die; } } sub RecieveTransfer { my $RemoteFile = $_[0]; print "$RemoteFile\n"; my $buffer=''; my $size = $ftp->size($RemoteFile); CreateProgressWin(); Win32::GUI::DoEvents(); my $blksize = 10240; my $track = 0; my $pos = 0; my $CurrentLocalDir = $_[1]; my $TransferMode = $_[2]; $blksize = 6240 if ( $size >= 300000 ); $TransferBox->Label_1->Text("$RemoteFile"); $TransferBox->Status->Text("Retrieving $RemoteFile..."); $TransferBox->TransferProgressBar_1->SetRange(0, 100); $TransferBox->TransferProgressBar_1->SetPos(0); $TransferBox->Size->Text("$track bytes of $size bytes"); $TransferBox->Progress->Text(int($pos)."%"); $TransferBox->Show(); if ( TransferMode eq 'asc' ) { if (!open ( FILE, "> $CurrentLocalDir"."/".$RemoteFile )) { Msg_Box("Can't create a file to put the data for $RemoteFile: $!.",48,"Can't Create File"); return 0; } } else { if (!open ( FILE, "> $CurrentLocalDir"."/".$RemoteFile )) { Msg_Box("Can't create a file to put the data for $RemoteFile: $!.",48,"Can't Create File"); return 0; } binmode FILE; } if (! ($data = $ftp->retr($RemoteFile)) ) { Msg_Box("Can't open a data retrieval socket for $RemoteFile.",48,"Can't Open Socket"); return 0; } while() { Win32::GUI::DoEvents(); $TransferBox->Size->Text("$track bytes of $size bytes"); $percent = $track/$size; $pos = 100*$percent; $TransferBox->Progress->Text(int($pos)."%"); $TransferBox->TransferProgressBar_1->SetPos($pos); $TransferBox->DoEvents(); last unless $len = $data->read($buffer,$blksize); $track += $len; my $written = syswrite(FILE, $buffer, $len); $TransferBox->Show(); unless(defined($written) && $written == $len) { Msg_Box("Cannot write to local file $CurrentLocalDir.\\.$RemoteFile: $!",48,"Can't Write To File"); $data->abort; $TransferBox->Hide(); close(FILE); return undef; } } $TransferBox->Hide(); Win32::GUI::DoEvents(); close(FILE); $data->close(); # implied $ftp->response return 1; } sub Msg_Box ($$$) { my ($msg, $buttons, $title) = (shift, shift, shift); return Win32::MsgBox($msg, $buttons, $title); } sub CreateProgressWin { $TransferBox = new Win32::GUI::Window( -left => 670, -top => 264, -width => 392, -height => 141, -name => "TransferBox", -text => "File Transfer" ); $TransferBox->Show(); $TransferBox->AddProgressBar( -text => "Transfer Progress", -name => "TransferProgressBar_1", -left => 13, -top => 53, -width => 356, -height => 12, ); $TransferBox->AddButton( -text => "", -name => "GroupBox_1", -left => 3, -top => 3, -width => 375, -height => 87, -style => WS_CHILD | WS_VISIBLE | 7, # GroupBox ); $TransferBox->AddButton( -text => "Kill", -name => "Cancel", -left => 352, -top => 93, -width => 29, -height => 21, -foreground => 16744448, ); $TransferBox->AddLabel( -text => "File :", -name => "Label_1", -left => 10, -top => 13, -width => 200, -height => 13, -foreground => 0, ); $TransferBox->AddLabel( -text => "Size (Bytes):", -name => "Size", -left => 11, -top => 31, -width => 200, -height => 13, -foreground => 0, ); $TransferBox->AddLabel( -text => "Progress (%) :", -name => "Progress", -left => 166, -top => 70, -width => 89, -height => 13, -foreground => 0, ); #$TransferBox->AddStatusBar( # -text => "Transfer Status:", # -name => "StatusBar_1", # -left => 0, # -top => 799, # -width => 1150, # -height => 17, # ); $TransferBox->AddButton( -text => "", -name => "transferStatus", -left => 5, -top => 88, -width => 339, -height => 24, -style => WS_CHILD | WS_VISIBLE | 7, # GroupBox ); $TransferBox->AddLabel( -text => "Transfer Status :", -name => "Status", -left => 11, -top => 96, -width => 250, -height => 13, -foreground => 0, ); #Win32::GUI::Dialog(); #return 1; } #Win32::GUI::Dialog(); sub MainWindow_Terminate { return -1; } #Win32::GUI::Dialog(); sub Cancel_Click { return -1; #exit; }