deadpickle has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use warnings; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; use threads; use threads::shared; my $die: shared = 0; my $verification_control: shared = 0; my $waytemp_local: shared = 'C:\Users\deadpickle\Desktop\files\waytemp +'; my $wayfinal_local: shared = "/home/deadpickle/Desktop/project_downloa +ds/wayfinal"; my $thread_verification = threads->new( \&verification); my $timer2 = Glib::Timeout->add(100, \&messagedialog); my $window = Gtk2::Window->new('toplevel'); my $button = Gtk2::Button->new( 'GO'); $window->signal_connect(delete_event => sub { $die = 1; $thread_verifi +cation->join; Gtk2->main_quit}); $button->signal_connect('button-press-event' => sub { $verification_co +ntrol = 1}); $window->add( $button); $window->show_all; Gtk2->main; sub verification { while(1){ if ( $die == 1 ){ goto END }; if ( $verification_control == 1 ){ for(;;){ print "GO\n"; my $count; if($die == 1){ goto END }; #open waytemp and load the waypoint locations then clo +se the file; the values will remain in the variables for later use open TEMP, '<', "$waytemp_local" or die; my @temp = <TEMP>; print "@temp\n"; chomp @temp; close TEMP; #count the lines in the waytemp file; disregard the fi +rst line since it is just the "time" stamp my $line = @temp - 1; #check if the waytemp file is NEW; checks only the fir +st line in the file if ( $temp[0] eq 'NEW') { #print the waypoints to the waytemp file; add OLD +to the top open TEMP, '>', "$waytemp_local" or die; print TEMP "OLD\n"; for ( $count = 1; $count >= $line; $count++) { print TEMP "$temp[$count]\n"; } close TEMP; #run the dialog that verifies the waypoints; needs + user input $verification_control = 2; if ( $verification_control == 2) { for (;;) { #if 'yes' if ( $verification_control == 3) { last} #if 'no' if ( $verification_control == 4) { goto NO +} } } #upload the new wayfinal file copied from the new +waytemp open FINAL, '>', 'C:\Users\deadpickle\Desktop\file +s\wayfinal' or die; for ( $count = 1; $count >= $line; $count++) { print FINAL "$temp[$count]\n"; } close FINAL; NO: } $verification_control = 1; } $verification_control = 0; } } END: } #Message Dialog box that asks to verify the new waypoints recieved fro +m the server sub messagedialog { #Run the message dialog if the waytemp file is stamped with a "NEW +" if( $verification_control == 2) { my $messagedialog_verification = Gtk2::MessageDialog->new( und +ef, 'destroy-with-parent', 'question', 'yes-no', "Verify waypoints?") +; $messagedialog_verification ->set_position( 'center'); my $response = $messagedialog_verification->run; #if the file is verified $verification_control = 3 if $response eq 'yes'; #if the file is not verified $verification_control = 4 if $response eq 'no'; $messagedialog_verification->destroy; } return 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Gtk2: not entering for loop
by zentara (Cardinal) on Aug 16, 2007 at 11:55 UTC |