#!/usr/local/bin/perl5 -w use strict; use warnings; require Tk; use Tk; my $Version="1.0"; my @sernums= ("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""); my @partnums= ("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""); # Create main window my $width = 900; my $height = 680; my $main = MainWindow->new(); $main->minsize( ($width, $height)); $main->maxsize( ($width, $height)); $main->title(" SanDisk SFT1"); #$main->setIcon(-file => 'PliantLogo.ico'); $main->configure(-background=>'gray'); #cyan my $menu_bar = $main->Frame(-relief=> 'groove', -borderwidth=> 3, -background=> 'blue', #purple )->pack('-side'=> 'top',-fill=> 'x'); my $file_mb = $menu_bar->Menubutton(-text => 'File', -background => 'blue', #purple -activebackground => 'blue', -foreground => 'white', )->pack(-side=> 'left'); $file_mb->command(-label => 'Exit', -activebackground => 'blue', -command => sub{$main->destroy}); my $help_mb = $menu_bar->Menubutton(-text=> 'Help', -background => 'blue', #purple -activebackground => 'cyan', -foreground => 'white', )->pack(-side=> 'right'); $help_mb->command(-label => 'About', -activebackground => 'blue', -command => \&about_txt); $help_mb->separator(); $help_mb->command(-label => 'Help', -activebackground => 'blue', -command => \&help_txt); #Build the innards my $statusline = $main->Frame(-borderwidth => 3, -relief => 'groove', -background => 'purple')->pack(-side => 'top'); my $status = $statusline->Label(-width => $width, -height => 0, -foreground => 'white', -background => 'purple')->pack(); my $num_slots = 16; my $slots_per_row = 4; my( @descSlot, @sernumSlot, @partnumSlot, @statusSlot, @goSlot, ); my $row; for my $slot ( 1 .. $num_slots ) { $row = make_row( $main, $width, $slot, $slot+$slots_per_row-1 ) unless ($slot-1) % $slots_per_row; make_slot( $row, $slot ); } $main->geometry('+400+200'); # '+10+340' compute(); $status->configure(-text => "Status Display"); $statusSlot[$_]->configure(-text => "Inactive", -background => 'gray') for 1 .. $num_slots; MainLoop(); sub compute { return; } sub validateSerNum { my $sernum = shift; print "validateSerNum called with $sernum\n"; if (($sernum =~ m/^\d{8}/) && (length($sernum) == 8)) { print "Returning 1\n"; return(1); } else { print "Returning 0\n"; return(0); } } sub invalidSerNum { $main->bell; $main->messageBox(-icon => 'error', -message => 'Serial number must be 8 digits!', -title => 'Error', -type => 'Ok'); $main->focusCurrent; } sub validatePartNum { my $partnum = shift; print "validatePartNum called with $partnum\n"; if (($partnum =~ m/^\d{8}/) && (length($partnum) == 8)) { print "Returning 1\n"; return(1); } else { print "Returning 0\n"; return(0); } } sub invalidPartNum { $main->bell; $main->messageBox(-icon => 'error', -message => 'Invalid part number!', -title => 'Error', -type => 'Ok'); $main->focusCurrent; } sub make_row { my( $parent, $width, $lo, $hi ) = @_; my $line = $parent->Frame(-borderwidth => 3, -relief => 'groove', -background => 'gray')->pack(-side => 'top'); $line->Label(-text => sprintf("Slots %02d - %02d", $lo, $hi), -width => $width, -height => 0, -foreground => 'black', -background => 'gray')->pack(); my $row = $parent->Frame(-background => 'cyan',)->pack(-side => 'top', -fill => 'x'); my $descriptionrow = $row->Frame(-background => 'cyan',)->pack(-side => 'left', -pady => 9, -padx => 8); $descriptionrow->Label(-text => 'Serial Number ', -background => 'cyan',)->pack(); $descriptionrow->Label(-text => 'Part Number', -background => 'cyan',)->pack(); $descriptionrow->Label(-text => 'Status', -background => 'cyan',)->pack(); $row } sub make_slot { my( $parent, $x, ) = @_; my $slot = $parent->Frame( -background => 'cyan', )->pack( -side => 'left', -pady => 2, -padx => 15); $descSlot[$x] = $slot->Label( -text => sprintf('Slot %02d',$x), -background => 'cyan', )->pack(); $sernumSlot[$x] = $slot->Entry( -width => 22, -background => 'white', -validate => 'focusout', -textvariable => \$sernums[$x], -validatecommand => \&validateSerNum, -invalidcommand => \&invalidSerNum, )->pack(); $partnumSlot[$x] = $slot->Entry( -width => 22, -background => 'white', -validate => 'focusout', -textvariable => \$partnums[$x], -validatecommand => \&validatePartNum, -invalidcommand => \&invalidPartNum, )->pack(); $statusSlot[$x] = $slot->Label( -background => 'white', -width => 19, -relief => 'groove', -borderwidth => 3, -text => 'dormant', )->pack( -anchor => 'center'); $goSlot[$x] = $slot->Button( -width => 10, -height => 1, -text => 'Start', -background => 'gray', -command => \&compute )->pack( -side => 'top', -anchor => 'center'); }