[BACK]Return to task.pl CVS log [TXT][DIR] Up to [tkperl]

Annotation of task.pl, Revision 1.0

1.0     ! philip      1: #! /usr/bin/perl -w
        !             2:
        !             3: # Philip Plane
        !             4: # philip@xinqu.net
        !             5: # EW Task Tool Version 1.0
        !             6:
        !             7: use Tk;
        !             8: use Tk::widgets qw/Dialog ErrorDialog ROText/;
        !             9: use strict;
        !            10:
        !            11: # Generate task declaration suitable to EW.
        !            12: # example supplied looks like this:
        !            13:
        !            14: #FLIGHT DECLARATION
        !            15: #-------------------
        !            16: #
        !            17: #Description:      To Heaven and Back
        !            18: #Take Off LatLong: 0000000N00000000E TAKE OFF
        !            19: #Start LatLon:     0000000N00000000E START
        !            20: #TP LatLon:        0000000N00000000E TURN POINT
        !            21: #TP LatLon:        0000000N00000000E TURN POINT
        !            22: #TP LatLon:        0000000N00000000E TURN POINT
        !            23: #TP LatLon:        0000000N00000000E TURN POINT
        !            24: #TP LatLon:        0000000N00000000E TURN POINT
        !            25: #TP LatLon:        0000000N00000000E TURN POINT
        !            26: #TP LatLon:        0000000N00000000E TURN POINT
        !            27: #TP LatLon:        0000000N00000000E TURN POINT
        !            28: #TP LatLon:        0000000N00000000E TURN POINT
        !            29: #TP LatLon:        0000000N00000000E TURN POINT
        !            30: #Finish LatLon:    0000000N00000000E FINISH
        !            31: #Land LatLon:      0000000N00000000E LAND
        !            32:
        !            33: my $mw = MainWindow->new;
        !            34: $mw->CmdLine;
        !            35: $mw->title("Turnpoints");
        !            36: $mw->minsize(175,50);
        !            37: $mw->configure(-menu => my $menubar = $mw->Menu);
        !            38:
        !            39: my $file = $menubar->cascade(qw/-label File -underline 0 -menuitems/ =>
        !            40:     [
        !            41:      [command    => 'Open', -command => [\&load_dat]],
        !            42:      [command    => 'Exit', -command => [\&exit]],
        !            43:     ]);
        !            44:
        !            45: my $igc = $menubar->cascade(qw/-label Task -underline 0 -menuitems/ =>
        !            46:     [
        !            47:      [command    => 'Add', -command => [\&add_to_task]],
        !            48:      [command    => 'Delete', -command => [\&del_from_task]],
        !            49:      [command    => 'Write', -command => [\&write_task]],
        !            50:     ]);
        !            51:
        !            52: my $help = $menubar->cascade(qw/-label Help -underline 0 -menuitems/ =>
        !            53:     [
        !            54:       [command => 'About'],
        !            55:       [command => 'Add'],
        !            56:       [command => 'Delete'],
        !            57:       [command => 'Write'],
        !            58:       [command => 'Open'],
        !            59:     ]);
        !            60:
        !            61: my $DIALOG_ABOUT = $mw->Dialog(
        !            62:     -title          => 'About Task tool',
        !            63:     -bitmap         => 'info',
        !            64:     -default_button => 'OK',
        !            65:     -buttons        => ['OK'],
        !            66:     -text           => "EW Task tool\nPhilip Plane\n" .
        !            67:                       "9 March 2007\n\nPerl Version $]" .
        !            68:                        "\nTk Version $Tk::VERSION\n\n" .
        !            69:                        "Creates task definitions for the EW MicroRecorder",
        !            70: );
        !            71:
        !            72: $help->cget(-menu)->entryconfigure('About',
        !            73:     -command => [$DIALOG_ABOUT => 'Show'],
        !            74: );
        !            75:
        !            76: my $DIALOG_ADD = $mw->Dialog(
        !            77:     -title          => 'Adding to Task',
        !            78:     -bitmap         => 'info',
        !            79:     -default_button => 'OK',
        !            80:     -buttons        => ['OK'],
        !            81:     -text           => "To add a turnpoint from the turnpoint list " .
        !            82:                       "to the task, select the turnpoint from the " .
        !            83:                        "turnpoint list, then select Add from the Task " .
        !            84:                        "menu. The turnpoint will be added to the bottom " .
        !            85:                        "of the task.",
        !            86: );
        !            87:
        !            88: $help->cget(-menu)->entryconfigure('Add',
        !            89:     -command => [$DIALOG_ADD => 'Show'],
        !            90: );
        !            91:
        !            92:
        !            93: my $DIALOG_DELETE = $mw->Dialog(
        !            94:     -title          => 'Delete from task',
        !            95:     -bitmap         => 'info',
        !            96:     -default_button => 'OK',
        !            97:     -buttons        => ['OK'],
        !            98:     -text           => "To delete a turnpoint from the task, select " .
        !            99:                       "the turnpoint from the task list, then " .
        !           100:                        "select Delete from the task menu. The turnpoint " .
        !           101:                        "will be deleted from the task.",
        !           102: );
        !           103:
        !           104: $help->cget(-menu)->entryconfigure('Delete',
        !           105:     -command => [$DIALOG_DELETE => 'Show'],
        !           106: );
        !           107:
        !           108: my $DIALOG_WRITE = $mw->Dialog(
        !           109:     -title          => 'Write task',
        !           110:     -bitmap         => 'info',
        !           111:     -default_button => 'OK',
        !           112:     -buttons        => ['OK'],
        !           113:     -text           => "Opens a window with the task presented in the " .
        !           114:                       "format used by the EW MicroRecorder. " .
        !           115:                        "This is intended to be cut and pasted into the " .
        !           116:                        "configuration file on the MicroRecorder. " ,
        !           117: );
        !           118:
        !           119: $help->cget(-menu)->entryconfigure('Write',
        !           120:     -command => [$DIALOG_WRITE => 'Show'],
        !           121: );
        !           122:
        !           123: my $DIALOG_OPEN = $mw->Dialog(
        !           124:     -title          => 'Open file',
        !           125:     -bitmap         => 'info',
        !           126:     -default_button => 'OK',
        !           127:     -buttons        => ['OK'],
        !           128:     -text           => "Opens a turnpoint file in Cambridge .DAT " .
        !           129:                       "format. This is loaded into the left pane " .
        !           130:                        "to allow turnpoints the be selected and added " .
        !           131:                        "to the task. " ,
        !           132: );
        !           133:
        !           134: $help->cget(-menu)->entryconfigure('Open',
        !           135:     -command => [$DIALOG_OPEN => 'Show'],
        !           136: );
        !           137:
        !           138: $mw->Label(-text=>"Turnpoints")->grid( "x", $mw->Label(-text=>"Task"));
        !           139:
        !           140: my $lb = $mw->Scrolled("Listbox",
        !           141:                -scrollbars => "e",
        !           142:                 -selectmode => "single")->grid(-row=> 0,
        !           143:                                                -column=> 0,
        !           144:                                                -rowspan=> 2,
        !           145:                                                -sticky=> "nsew");
        !           146:
        !           147: $mw->Button(-text=>"Add ->", -command=> \&add_to_task )->grid(-row=> 0,
        !           148:                                                               -column=> 1,
        !           149:                                                               -sticky=> "sew");
        !           150:
        !           151:
        !           152: my $task = $mw->Scrolled("Listbox",
        !           153:                -scrollbars => "e",
        !           154:                 -selectmode => "single")->grid(-row=> 0,
        !           155:                                                -column=> 2,
        !           156:                                                -rowspan=> 2,
        !           157:                                                -sticky=> "nsew");
        !           158:
        !           159: $mw->Button(-text=>"Del <-", -command=> \&del_from_task )->grid(-row=> 1,
        !           160:                                                                 -column=> 1,
        !           161:                                                                 -sticky=> "new");
        !           162:
        !           163:
        !           164: my @dat = ();
        !           165: my %lat = ();
        !           166: my %lng = ();
        !           167:
        !           168: sub load_dat {
        !           169:     my $types = [
        !           170:                 ['DAT Files','.dat'],
        !           171:                 ['DAT Files','.DAT'],
        !           172:                 ];
        !           173:
        !           174:     my $igc = $mw->getOpenFile(-initialdir=>'C:',
        !           175:                               -filetypes=>$types);
        !           176:     if ( defined $igc ){
        !           177:        my @igc = split /\//,$igc;
        !           178:        my $igcfile = pop @igc;
        !           179:         open IGC, $igc or die "Can't open $igc : $!\n";
        !           180:         my @log = <IGC>;
        !           181:         close IGC;
        !           182:         while ( $_ = shift @log ){
        !           183:             if ( $_ =~ /^\d/ ){
        !           184:                @dat = split(/\,/,$_);
        !           185:                 if ( $dat[4] =~ /T|S|F/ ){
        !           186:                         if ( $dat[5] eq "" ) { $dat[5] = $dat[0] }
        !           187:                         $lat{$dat[5]} = $dat[1];
        !           188:                         $lng{$dat[5]} = $dat[2];
        !           189:                         $lb->insert('end',$dat[5]);
        !           190:                 }
        !           191:             }
        !           192:        }
        !           193:     }
        !           194: }
        !           195:
        !           196: sub add_to_task {
        !           197:        my @selection = $lb->curselection();
        !           198:         foreach ( @selection ){
        !           199:                my $turnpoint =$lb->get($_);
        !           200:                 $task->insert('end',$turnpoint);
        !           201:         }
        !           202: }
        !           203:
        !           204: sub del_from_task {
        !           205:        my @selection = $task->curselection();
        !           206:         foreach ( @selection ){
        !           207:                $task->delete($_);
        !           208:         }
        !           209: }
        !           210:
        !           211: sub write_task {
        !           212:        my $bwin = $mw->Toplevel();
        !           213:        $bwin->title("Flight Declaration");
        !           214:         my $text = $bwin->Scrolled("Text")->pack();
        !           215:         $text->delete("1.0","end");
        !           216:         $text->insert("end","FLIGHT DECLARATION\n");
        !           217:         $text->insert("end","-------------------\n");
        !           218:         $text->insert("end","\n");
        !           219:         $text->insert("end","Description:      To Heaven and Back\n");
        !           220:         my @elements = $task->get(0,'end');
        !           221:         my $start = shift @elements;
        !           222:         my $finish = pop @elements;
        !           223:         my $lat = $lat{$start};
        !           224:         my $lng = $lng{$start};
        !           225:         $lat =~ s/://;
        !           226:         $lng =~ s/://;
        !           227:         $text->insert("end","Start LatLon:     " . $lat . $lng . " " . $start . "\n");
        !           228:         foreach ( @elements ){
        !           229:                my $lat = $lat{$start};
        !           230:                my $lng = $lng{$start};
        !           231:                $lat =~ s/://;
        !           232:                $lng =~ s/://;
        !           233:                $text->insert("end","TP LatLon:        " . $lat . $lng . " " . $_ . "\n");
        !           234:         }
        !           235:        $lat = $lat{$finish};
        !           236:         $lng = $lng{$finish};
        !           237:         $lat =~ s/://;
        !           238:         $lng =~ s/://;
        !           239:         $text->insert("end","Finish LatLon:    " . $lat . $lng . " " . $finish . "\n");
        !           240: }
        !           241: MainLoop;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>