#!/usr/bin/perl -w # use English; use Chemistry::MolecularMass; use Tk; use Tk::DialogBox; use strict; sub calculate ; my $mm = new Chemistry::MolecularMass; my $MW = MainWindow->new(-background=>'#DEDE20'); ### --- Prevents Main Window Resizing $MW->bind('' => sub{ my $xe = $MW->XEvent; $MW->maxsize($xe->w, $xe->h); $MW->minsize($xe->w, $xe->h); }); ### --- Main Window Title $MW->title("Molecular Mass"); ### --- Create Button Frame my $button_frame = $MW->Frame(-background => '#DEDE20'); $button_frame->pack(-side => 'bottom', -expand => '1', -fill => 'both'); ### --- Create About Button $button_frame->Button(-text => "About", -foreground => "#007300", -activebackground => "#98FB98", -background => "#E8F988", -font => 'Arial', -command => sub { my $dialogA = $MW->DialogBox( -title => "About this program: MolecularMass.pl", -buttons => [ "OK" ], ); $dialogA->add("Label", -borderwidth => '3', -background => "#FAEBD7", #ANTIQUE WHITE -font => 'bold', -justify => 'left', -relief => 'sunken', #One seriously long text string follows on the next line --> -text => "FOR BEST RESULTS USE: PERL 5.6.1 \& Tk 8.0 OR BETTER\nThis program requires use of the perl module Chemistry::MolecularMass.\nVersion 1.0 -- 07\/27\/2003 Original Code Written by Jay Madigan.\n\t Adapted from TheElements.pl written by Jay Madigan c.2000\n************************************************************************************************\nThis program is freeware and may be modified and\/or redistributed \nunder the same terms as the GNU public license of PERL. \nNo warranty on this code is assumed or implied. ")->pack; ### --- Prevents Dialog Box Resizing $dialogA->bind('' => sub{ my $xeD = $dialogA->XEvent; $dialogA->maxsize($xeD->w, $xeD->h); $dialogA->minsize($xeD->w, $xeD->h); }); $dialogA->Show; } )->pack(-side => 'right', -expand => '1', -fill => 'both'); ### --- Create Exit Button my $exit = $button_frame->Button(-text => 'Exit', -foreground => 'red', -activebackground => "#FF9090", -background => "#E8F988", -font => 'Arial', -command => sub { exit; }); $exit->pack(-side => 'right', -expand => '1', -fill => 'both'); ### --- Create Calculate Button my $calculate = $button_frame->Button(-text => 'Calculate', -foreground => "blue", -activebackground => "#ADD8E6", -background => "#E8F988", -font => 'Arial', -command => sub { calculate; }); $calculate->pack(-side => 'right', -expand => '1', -fill => 'both'); ### --- Create Molecular Mass Frame my $mass_frame = $MW->Frame(-background => '#DEDE20')->pack(-expand => '1', -fill => 'both', -side => 'bottom'); $mass_frame->Label(-background => '#DEDE20',-text => "Molecular Mass:", -font => 'Arial')->pack(-side => 'left'); my $mass_value = $mass_frame->Entry(-highlightbackground => 'black',-highlightthickness => '2',-font => 'Arial', -width => '10', -relief => 'sunken')->pack(-side => 'left'); # ### --- Create Entry Frame my $entry_frame = $MW->Frame(-background => '#DEDE20')->pack(-expand => '1', -fill => 'both', -side => 'bottom'); $entry_frame->Label(-background => '#DEDE20', -foreground => 'red', -font => 'Arial', -text => "Enter Chemical Formula:")->pack(-side => 'left'); my $calculate_value = $entry_frame->Entry(-highlightbackground => 'red',-highlightthickness => '2', -font => 'Arial', -width => '15', -relief => 'sunken')->pack(-side => 'left'); MainLoop; #### BEGIN SECTION FOR SUBROUTINES ---- sub calculate { my $value = $calculate_value->get; my $mass = $mm->calc_mass($value); print "$mass\n"; ## generate "sqwauk box" if invalid entry was made ## resulting in null output if(!(defined $mass)){ my $dialogW = $MW->DialogBox( -title => "ERROR! Please Try Again.", -buttons => [ "OK" ], ); $dialogW->add("Label", -text => " \"$value\" is not a valid entry. ", -font => "Arial", -foreground => "red")->pack; ### --- Prevents Dialog Box Resizing $dialogW->bind('' => sub{ my $xeW = $dialogW->XEvent; $dialogW->maxsize($xeW->w, $xeW->h); $dialogW->minsize($xeW->w, $xeW->h); }); $dialogW->Show; } $mass_value->delete('0', 'end'); $mass_value->insert('0', $mass); #$name_value->delete('0', 'end'); #$name_value->insert('0', $name); }