Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange Waiting ... hard to explain, read for more info

Status
Not open for further replies.

chamberlain2007

Programmer
Apr 29, 2007
1
Hello, I'm writing a simple FTP client in Perl-Gtk2. The function that I'm having a problem with is downloading the file. Have a look at this code.

$list->signal_connect('button-press-event' =>
sub {
my @selected = $list->get_selected_indices;
my $menu = Gtk2::Menu->new();
my $menuitem1 = Gtk2::MenuItem->new("Get file");
my $menuitem2 = Gtk2::MenuItem->new("Switch directory");
$menuitem1->signal_connect(activate => \&getfile, @selected);
$menuitem2->signal_connect(activate => sub { print "Clicked2"; } );
$menuitem1->show();
$menuitem2->show();
$menu->append($menuitem1);
$menu->append($menuitem2);
my ($widget, $event) = @_;
return FALSE unless $event->button == 3;
$menu->popup(
undef,
undef,
undef,
undef,
$event->button,
$event->time);
}
);
sub getfile {
my $host = $host_enter->get_text();
my $conn = Net::FTP->new($host, Debug => 0)
or &dienice("$@");
my $user = $user_enter->get_text();
my $pass = $pass_enter->get_text();
$conn->login($user, $pass)
or &dienice($conn->message);
$conn->cwd("wlan")
or &dienice($conn->message);
my (undef, @see) = @_;
foreach my $q (@see) {
my $w = $list->{data}->[$q]->[0];
print "Downloading file $w\n";
$conn->get($w);
print "Got file $w\n";
return;
}
return;
}

What it is supposed to do is download the selected file when the user clicks on the "Get File" option on the context menu. The problem is that it doesn't download he file until the use clicks on the "Get file" option for a second time. If someone knows why this might be happening, lease let me know!
 
Try adding a lot of print statements in your code, maybe before and after each Perl function, and see how many of them print each time you click the button. My guess is that, the first time you click the button, the code might not even be called at all... or something in the code gets interrupted (which would only print half of the prints you had in there in that case).

-------------
Cuvou.com | The NEW Kirsle.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top