App-SourcePlot

 view release on metacpan or  search on metacpan

lib/App/SourcePlot.pm  view on Meta::CPAN

            $temp[$index + $flag] = $$array[$index];
        }
    }

    @$array = @temp;
}

=item B<update_status>

Invokes the update method of the main window.

=cut

sub update_status {
    $MW->update;
}

=item B<changeDate>

Changes the date to a new date.

=cut

sub changeDate {
    $dateBut->configure(-state => 'disabled');

    my @months = qw/
        January February March April May June July August
        September October November December/;

    my $name;

    my $Top = $MW->Toplevel;
    $Top->title('Source Plot UT Date');
    $Top->resizable(0, 0);
    my $topFrame = $Top->Frame(
        -relief => 'groove',
        -borderwidth => 2,
    )->pack(-padx => 10, -pady => 10);

    # create the day entry
    $topFrame->Label(-text => "Day:")->grid(-column => 0, -row => 0);
    my $dayEnt = $topFrame->Entry(
        -relief => 'sunken',
        -width => 10,
    )->grid(-column => 1, -row => 0, -padx => 10, -pady => 5);

    # create the month menu button
    $topFrame->Label(
        -text => "Month:",
    )->grid(-column => 0, -row => 1, -padx => 5, -pady => 5);

    my $strp = DateTime::Format::Strptime->new(
        pattern => '%Y/%m/%d',
        time_zone => 'UTC',
        on_error => 'croak');

    my $dt = $strp->parse_datetime($DATE);
    my $monthEnt = $months[$dt->month() - 1];

    my $mb = $topFrame->Menubutton(
        -text => $monthEnt,
        -relief => 'raised',
        -width => 10);

    foreach $name (@months) {
        $mb->command(
            -label => $name,
            -command => sub {
                $mb->configure(-text => $name);
                $monthEnt = $name;
            },
        );
    }
    $mb->grid(-column => 1, -row => 1, -padx => 10, -pady => 5, -sticky => 'w');

    # create the year entry
    $topFrame->Label(
        -text => 'Year:',
    )->grid(-column => 0, -row => 2, -padx => 5, -pady => 5);

    my $yearEnt = $topFrame->Entry(
        -relief => 'sunken',
        -width => 10,
    )->grid(-column => 1, -row => 2, -padx => 10, -pady => 5);
    $yearEnt->bind('<KeyPress-Return>' => sub {
        my $strp = DateTime::Format::Strptime->new(
            pattern => '%Y %B %d',
            on_error => 'croak');

        my $dt = $strp->parse_datetime(
            $monthEnt
            . ' ' . $dayEnt->get()
            . ' ' . $yearEnt->get());

        $DATE = $dt->strftime('%Y/%m/%d');

        destroy $Top;
    });

    # create the update subroutine
    my $complete = sub {
        my $strp = DateTime::Format::Strptime->new(
            pattern => '%B %d %Y',
            on_error => 'croak');

        my $dt = $strp->parse_datetime(
            $monthEnt
            . ' ' . $dayEnt->get()
            . ' ' . $yearEnt->get());

        $DATE = $dt->strftime('%Y/%m/%d');

        foreach my $source (@SOURCE_LIST) {
            $source->erasePoints();
        }

        plot();
    };

    # create the apply button

lib/App/SourcePlot.pm  view on Meta::CPAN

        -text => 'Accept',
        -command => sub {
            &$complete;
            destroy $Top;
        },
    )->pack(-side => 'right');
    $okBut->bind('<KeyPress-Return>' => sub {
        &$complete;
        destroy $Top;
    });

    # create the cancel button
    my $canBut = $buttonF->Button(
        -text => 'Cancel',
        -command => sub {
            destroy $Top;
        },
    )->pack(-side => 'right');
    $canBut->bind('<KeyPress-Return>' => sub {
        destroy $Top;
    });

    # Closing the window should reset $dateBut.
    $Top->bind('<Destroy>', sub {
        my $widget = shift;
        return unless $widget == $Top;
        $dateBut->configure(-state => 'normal');
    });

    $dayEnt->insert(0, $dt->day());
    $yearEnt->insert(0, $dt->year());

    $MW->update;
}

=item B<changeOpt>

Displays a window allowing the options to be changed.

=cut

sub changeOpt {
    my $name;
    my $telEnt = $TEL;
    my ($tb, $tb2);

    $optBut->configure(-state => 'disabled');

    my $Top = $MW->Toplevel;
    $Top->title('Source Plot Options');
    $Top->resizable(0, 0);
    my $topFrame = $Top->Frame(
        -relief => 'groove',
        -borderwidth => 2,
    )->pack(-padx => 10, -pady => 10);

    # place the telescope menuButton
    $topFrame->Label(-text => 'Telescope:')->grid(-column => 0, -row => 0);
    my $f = $topFrame->Frame()->grid(-column => 1, -row => 0, -padx => 10, -pady => 5, -sticky => 'w');
    my $f2 = $topFrame->Frame()->grid(-column => 1, -row => 1, -padx => 10, -pady => 5, -sticky => 'w');
    $tb = $f->Menubutton(
        -text => $telEnt,
        -relief => 'raised',
        -width => 15,
    )->pack(-side => 'left');
    $tb->cascade(-label => 'A - C', -underline => 0);
    $tb->cascade(-label => 'D - F', -underline => 0);
    $tb->cascade(-label => 'G - I', -underline => 0);
    $tb->cascade(-label => 'J - L', -underline => 0);
    $tb->cascade(-label => 'M - O', -underline => 0);
    $tb->cascade(-label => 'P - R', -underline => 0);
    $tb->cascade(-label => 'S - U', -underline => 0);
    $tb->cascade(-label => 'V - X', -underline => 0);
    $tb->cascade(-label => 'Y - Z', -underline => 0);

    my $cm = $tb->cget('-menu');
    my $ac = $cm->Menu;
    my $df = $cm->Menu;
    my $gi = $cm->Menu;
    my $jl = $cm->Menu;
    my $mo = $cm->Menu;
    my $pr = $cm->Menu;
    my $su = $cm->Menu;
    my $vx = $cm->Menu;
    my $yz = $cm->Menu;

    $tb->entryconfigure('A - C', -menu => $ac);
    $tb->entryconfigure('D - F', -menu => $df);
    $tb->entryconfigure('G - I', -menu => $gi);
    $tb->entryconfigure('J - L', -menu => $jl);
    $tb->entryconfigure('M - O', -menu => $mo);
    $tb->entryconfigure('P - R', -menu => $pr);
    $tb->entryconfigure('S - U', -menu => $su);
    $tb->entryconfigure('V - X', -menu => $vx);
    $tb->entryconfigure('Y - Z', -menu => $yz);

    foreach $name ($telObject->telNames()) {
        if ($name =~ /^[A-Ca-c]/) {
            $ac->command(
                -label => $name,
                -command => sub {
                    $tb->configure(-text => $name);
                    $telEnt = $name;
                },
            );
        }
        elsif ($name =~ /^[D-Fd-f]/) {
            $df->command(
                -label => $name,
                -command => sub {
                    $tb->configure(-text => $name);
                    $telEnt = $name;
                },
            );
        }
        elsif ($name =~ /^[G-Ig-i]/) {
            $gi->command(
                -label => $name,
                -command => sub {
                    $tb->configure(-text => $name);
                    $telEnt = $name;
                },
            );
        }
        elsif ($name =~ /^[J-Lj-l]/) {
            $jl->command(
                -label => $name,
                -command => sub {
                    $tb->configure(-text => $name);
                    $telEnt = $name;
                },
            );
        }
        elsif ($name =~ /^[M-Om-o]/) {
            $mo->command(
                -label => $name,
                -command => sub {
                    $tb->configure(-text => $name);
                    $telEnt = $name;
                },
            );
        }
        elsif ($name =~ /^[P-Rp-r]/) {
            $pr->command(
                -label => $name,
                -command => sub {
                    $tb->configure(-text => $name);
                    $telEnt = $name;
                },
            );
        }
        elsif ($name =~ /^[S-Us-u]/) {
            $su->command(
                -label => $name,
                -command => sub {
                    $tb->configure(-text => $name);
                    $telEnt = $name;
                },
            );
        }
        elsif ($name =~ /^[V-Xv-x]/) {
            $vx->command(
                -label => $name,
                -command => sub {
                    $tb->configure(-text => $name);
                    $telEnt = $name;
                },
            );
        }
        elsif ($name =~ /^[Y-Zy-z]/) {
            $yz->command(
                -label => $name,
                -command => sub {
                    $tb->configure(-text => $name);
                    $telEnt = $name;
                },
            );
        }
    }

    # place the middle time field
    $topFrame->Label(
        -text => 'Center Time (in HST):',
    )->grid(-column => 0, -row => 2, -padx => 5, -pady => 5);

    my $timeEnt = $TIME;
    $topFrame->Entry(
        -relief => 'sunken',
        -textvariable => \$timeEnt,
        -width => 10,
    )->grid(-column => 1, -row => 2, -padx => 10, -pady => 5);

    # place the y-axis menuButton
    $topFrame->Label(
        -text => 'y-axis:',
    )->grid(-column => 0, -row => 4, -padx => 5, -pady => 5);

    my $yEnt = $Y_AXIS;
    my $yb = $topFrame->Menubutton(
        -text => $yEnt,
        -relief => 'raised',
        -width => 15);
    foreach $name (@axes) {
        $yb->command(
            -label => $name,
            -command => sub {
                $yb->configure(-text => $name);
                $yEnt = $name;
            },
        );
    }
    $yb->grid(-column => 1, -row => 4, -padx => 10, -pady => 5, -sticky => 'w');

    # inserting cascading choices

    # place the x-axis menuButton
    $topFrame->Label(
        -text => 'x-axis:',
    )->grid(-column => 0, -row => 3, -padx => 5, -pady => 5);
    my $xEnt = $X_AXIS;
    my $xb = $topFrame->Menubutton(
        -text => $xEnt,
        -relief => 'raised',
        -width => 15,
    );
    foreach $name (@axes) {
        $xb->command(
            -label => $name,
            -command => sub {
                $xb->configure(-text => $name);
                $xEnt = $name;
            },
        );
    }
    $xb->grid(-column => 1, -row => 3, -padx => 10, -pady => 5, -sticky => 'w');

    # place the Apply button
    my $F = $Top->Frame->pack();
    my $buttonF = $F->Frame->pack(-side => 'left', -padx => 5, -pady => 10);
    $buttonF->Button(
        -text => 'Apply',
        -command => sub {
            $X_AXIS = $xEnt;
            $Y_AXIS = $yEnt;
            if ($TEL ne $telEnt || $TIME ne $timeEnt) {
                foreach (@SOURCE_LIST) {
                    $_->erasePoints();
                }
            }
            else {
                foreach (@SOURCE_LIST) {
                    $_->eraseTimeDot();
                }
            }
            $TIME = $timeEnt;
            $TIME =~ s/^\s+//;
            $TIME =~ s/\s+$//;
            $TIME =~ s/\s+/:/g;
            $TEL = $telEnt;
            $telObject->name($TEL);
            plot();
        },
    )->pack(-side => 'left');

    # place the ok button
    $buttonF = $F->Frame->pack(-side => 'right', -padx => 5, -pady => 10);
    $buttonF->Button(
        -text => 'Accept',
        -command => sub {
            $X_AXIS = $xEnt;
            $Y_AXIS = $yEnt;
            if ($TEL ne $telEnt || $TIME ne $timeEnt) {
                foreach (@SOURCE_LIST) {
                    $_->erasePoints();
                }
            }
            else {
                foreach (@SOURCE_LIST) {
                    $_->eraseTimeDot();
                }
            }

lib/App/SourcePlot.pm  view on Meta::CPAN

    if (! isWithin($source, @SOURCE_LIST)) {
        $source->color(getColor());
        push @SOURCE_LIST, $source;
    }
}

=item B<getSource>

Prompts the user to enter source coords and name.
Can specify previous source object to edit.

Returns a Source object.

=cut

sub getSource {
    my $source = shift;
    my @Epocs = qw/RJ RB GA AZ/;
    my $name;

    my $Top = $MW->Toplevel;
    $Top->title('Source Plot');
    $Top->resizable(0, 0);
    my $topFrame = $Top->Frame(
        -relief => 'groove',
        -borderwidth => 2,
        -width => 50,
    )->pack(-padx => 10, -fill => 'x', -ipady => 10, -pady => 10);

    $topFrame->Label(
        -text => 'Name:',
    )->grid(-column => 0, -row => 0);
    my $nameEnt = $topFrame->Entry(
        -relief => 'sunken',
        -width => 15,
    )->grid(-column => 1, -row => 0, -padx => 10, -pady => 3);
    $nameEnt->insert(0, $source->name());

    $topFrame->Label(
        -text => 'Ra:',
    )->grid(-column => 0, -row => 1);
    my $raEnt = $topFrame->Entry(
        -relief => 'sunken',
        -width => 15,
    )->grid(-column => 1, -row => 1, -padx => 10, -pady => 3);
    $raEnt->insert(0, $source->ra()) unless $source->is_blank();

    $topFrame->Label(
        -text => 'Dec:',
    )->grid(-column => 0, -row => 2);
    my $decEnt = $topFrame->Entry(
        -relief => 'sunken',
        -width => 15
    )->grid(-column => 1, -row => 2, -padx => 10, -pady => 3);
    $decEnt->insert(0, $source->dec()) unless $source->is_blank();

    $topFrame->Label(
        -text => 'Epoc:',
    )->grid(-column => 0, -row => 3, -padx => 5, -pady => 5);
    my $epocEnt = $source->is_blank() ? $Epocs[0] : $source->epoc();
    my $epocB = $topFrame->Menubutton(
        -text => $epocEnt,
        -relief => 'raised',
        -width => 15,
    );

    foreach $name (@Epocs) {
        $epocB->command(
            -label => $name,
            -command => sub {
                $epocB->configure(-text => $name);
                $epocEnt = $name;
            },
        );
    }
    $epocB->grid(-column => 1, -row => 3, -padx => 10, -pady => 5, -sticky => 'w');

    my $buttonF = $Top->Frame->pack(-padx => 10, -pady => 10);
    $buttonF->Button(
        -text => 'Ok',
        -command => sub {
            $source->configure($nameEnt->get(), $raEnt->get(), $decEnt->get(), $epocEnt);
            destroy $Top;
            $RESPONSE = 1;
        },
    )->pack(-side => 'right');
    $buttonF->Button(
        -text => 'Cancel',
        -command => sub {
            destroy $Top;
            $RESPONSE = -1;
        },
    )->pack(-side => 'right');
    $Top->update;
    $Top->grab;
}

=item B<editSource>

Edits the existing source list.

=cut

sub editSource {
    my (@selected) = ();
    my $udeb = 0;  #debugger

    $eBut->configure(-state => 'disabled');

    my $Top = $MW->Toplevel();
    $Top->geometry('+600+90');
    $Top->title('Source Plot: Edit Window');
    $Top->resizable(1, 1);
    my $topFrame = $Top->Frame(
        -relief => 'groove',
        -borderwidth => 2,
        -width => 50,
    )->grid(-column => 0, -row => 0, -padx => 3, -pady => 3, -sticky => 'nsew');

    # create the header
    my $head = $topFrame->Text(

lib/App/SourcePlot.pm  view on Meta::CPAN

    $undoBut = $manipF->Button(
        -text => 'Undo',
        -command => sub {
            if ($LAST_COMMAND eq 'Add') {
                print "Last command was add\n" if $udeb;
                foreach my $source (@UNDO_LIST) {
                    remove($source, \@SOURCE_LIST);
                    print "removing " . $source->name . "\n" if $udeb;
                }
            }
            elsif ($LAST_COMMAND eq 'Delete') {
                print "Last command was removed\n" if $udeb;
                foreach my $source (@UNDO_LIST) {
                    push(@SOURCE_LIST, $source);
                    print "Adding " . $source->name . "\n" if $udeb;
                }
            }
            elsif ($LAST_COMMAND eq 'Change') {
                print "Last command was changed\n" if $udeb;
                my $source = pop(@UNDO_LIST);
                my $orig = pop(@UNDO_LIST);
                print "Reconfiguring " . $source->name . "\n" if $udeb;
                $source->configure($orig);
                print "Clearing " . $source->name . "\n" if $udeb;
                $source->erasePoints();
            }
            $LAST_COMMAND = '';
            @UNDO_LIST = ();
            @selected = ();
            $undoBut->configure(-state => 'disabled') if $EDIT_OPEN;
            fillWithSourceList($EditWin, 'full');
            plot();
        },
    )->pack(-side => 'left');
    $undoBut->configure(-state => 'disabled') if $EDIT_OPEN;
    $balloon->attach($undoBut, -balloonmsg => "Press to undo the last\nmajor command");

    # create the add button
    my $newBut = $manipF->Button(
        -text => 'New',
        -width => 4,
        -command => sub {
            my $source = App::SourcePlot::Source->new();
            &getSource($source);
            my $res = &waitForResponse();
            if ($res && ! isWithin($source, @SOURCE_LIST)) {
                $source->color(getColor());
                push @SOURCE_LIST, $source;
                fillWithSourceList($EditWin, 'full');
                $LAST_COMMAND = 'Add';
                @UNDO_LIST = ();
                $undoBut->configure(-state => 'normal') if $EDIT_OPEN;
                push @UNDO_LIST, $source;
                plot();
            }
        },
    )->pack(-side => 'left');
    $balloon->attach($newBut, -balloonmsg => "Press to manually\nadd a source");

    # create the planet button
    my $planBut = $manipF->Menubutton(
        -text => 'Planets',
        -width => 7,
        -relief => 'raised',
    );
    {
        my $k = 0;
        foreach my $plan (@planets) {
            my $c = $k;
            $planBut->command(
                -label => $plan,
                -command => sub {
                    &addPlanetSource($plan, $c);
                    print "$TEL is tel  \n" if $locateBug;
                    fillWithSourceList($EditWin, 'full');
                    plot();
                }
            );
            $k ++;
        }
    }
    $planBut->command(
        -label => 'All',
        -command => sub {
            my $j = 0;
            foreach (@planets) {
                &addPlanetSource($_, $j);
                $j ++;
            }
            fillWithSourceList($EditWin, 'full');
            plot();
        }
    );
    $planBut->pack(-side => 'left');
    $balloon->attach($planBut, -balloonmsg => "Press to add a planet\nto the plot");

    $Top->gridRowconfigure(0, -weight => 1);
    $Top->gridColumnconfigure(0, -weight => 1);

    $EditWin->{'Window'} = $Top;
    $EditWin->{'Text'} = $T;
    $EditWin->{'Selected'} = \@selected;
    $EditWin->{'Sources'} = \@SOURCE_LIST;

    fillWithSourceList($EditWin, 'full');

    $MW->update;
}

=item B<fillWithSourceList>

Fills a Text box with the list of current sources.

=cut

sub fillWithSourceList {
    my (@bold, @normal);
    my $Window = shift;
    my $T = $Window->{'Text'};
    my $selected = $Window->{'Selected'};
    my $arrayOfSources = $Window->{'Sources'};



( run in 0.961 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )