Commit 12a8fa73 authored by Mac Newbold's avatar Mac Newbold

Graphical interface to Power.

parent a5e1db7f
#!/usr/local/bin/perl -w
use strict;
use Tk;
#Color values
my $main_bg = 'grey80';
#other Variables
my $op="";
my @machines=();
#Build the Widgets now
#set up main
my $main = MainWindow->new();
$main->title("Power");
#$main->minsize( qw(200 100) );
$main->configure(-background => $main_bg );
#add some frames
my $msg_frm =
$main->Frame( -relief=>'sunken', -borderwidth=>2, -background=>$main_bg
)->pack(-side=>'bottom', -fill=>'x');
my $msg_area =
$msg_frm->Label(-background=>$main_bg) ->pack(-side=>'left');
my $op_frm =
$main->Frame( -relief=>'flat', -background=>$main_bg
) ->pack (-side=>'bottom', -fill=>'x');
my $button_frm =
$op_frm->Frame( -relief=>'flat', -background=>$main_bg
) ->pack (-side=>'bottom', -fill=>'x');
my $mach_frm =
$main->Frame( -relief=>'flat', -background=>$main_bg
) ->pack (-side=>'left', -fill=>'x');
my $mach_frm1 =
$mach_frm->Frame( -relief=>'flat', -background=>$main_bg
) ->pack (-side=>'left', -fill=>'x');
my $mach_frm2 =
$mach_frm->Frame( -relief=>'flat', -background=>$main_bg
) ->pack (-side=>'left', -fill=>'x');
my $button_frm1 =
$mach_frm1->Frame( -relief=>'flat', -background=>$main_bg
) ->pack (-side=>'bottom', -fill=>'x');
my $button_frm2 =
$mach_frm2->Frame( -relief=>'flat', -background=>$main_bg
) ->pack (-side=>'bottom', -fill=>'x');
#set up the operations
my $op_on = $op_frm->Radiobutton( -variable=> \$op, -text => 'Turn On',
-background=>$main_bg,-value=>'on'
)->pack(-side=>'top',-fill=>'x',
-anchor=>'w');
my $op_off = $op_frm->Radiobutton( -variable=> \$op, -text => 'Turn Off',
-background=>$main_bg,-value=>'off'
)->pack(-side=>'top',-fill=>'x',
-anchor=>'w');
my $op_cyc = $op_frm->Radiobutton( -variable=> \$op, -text => 'Reboot',
-background=>$main_bg,-value=>'cycle'
)->pack(-side=>'top',-fill=>'x',
-anchor=>'w');
#set up the machines
my @mach;
my @machvals
#= (0,0,0,0,0,0,0,0,0,0,0,0)
;
$mach[1] =
$mach_frm1->Checkbutton(-variable=>\$machvals[1], -text=>"test1",
-background=>$main_bg
)->pack(-side=>'top',-fill=>'x', -anchor=>'w');
$mach[2] =
$mach_frm1->Checkbutton(-variable=>\$machvals[2], -text=>"test2",
-background=>$main_bg
)->pack(-side=>'top',-fill=>'x', -anchor=>'w');
$mach[3] =
$mach_frm1->Checkbutton(-variable=>\$machvals[3], -text=>"test3",
-background=>$main_bg
)->pack(-side=>'top',-fill=>'x', -anchor=>'w');
$mach[4] =
$mach_frm1->Checkbutton(-variable=>\$machvals[4], -text=>"test4",
-background=>$main_bg
)->pack(-side=>'top',-fill=>'x', -anchor=>'w');
$mach[5] =
$mach_frm1->Checkbutton(-variable=>\$machvals[5], -text=>"test5",
-background=>$main_bg
)->pack(-side=>'top',-fill=>'x', -anchor=>'w');
$mach[6] =
$mach_frm1->Checkbutton(-variable=>\$machvals[6], -text=>"test6",
-background=>$main_bg
)->pack(-side=>'top',-fill=>'x', -anchor=>'w');
$mach[7] =
$mach_frm2->Checkbutton(-variable=>\$machvals[7], -text=>"test7",
-background=>$main_bg
)->pack(-side=>'top',-fill=>'x', -anchor=>'w');
$mach[8] =
$mach_frm2->Checkbutton(-variable=>\$machvals[8], -text=>"test8",
-background=>$main_bg
)->pack(-side=>'top',-fill=>'x', -anchor=>'w');
$mach[9] =
$mach_frm2->Checkbutton(-variable=>\$machvals[9], -text=>"test9",
-background=>$main_bg
)->pack(-side=>'top',-fill=>'x', -anchor=>'w');
$mach[10] =
$mach_frm2->Checkbutton(-variable=>\$machvals[10], -text=>"test10",
-background=>$main_bg
)->pack(-side=>'top',-fill=>'x', -anchor=>'w');
$mach[11] =
$mach_frm2->Checkbutton(-variable=>\$machvals[11], -text=>"alpha",
-background=>$main_bg
)->pack(-side=>'top',-fill=>'x', -anchor=>'w');
$mach[12] =
$mach_frm2->Checkbutton(-variable=>\$machvals[12], -text=>"beta",
-background=>$main_bg
)->pack(-side=>'top',-fill=>'x', -anchor=>'w');
#set up the buttons
my $go =
$button_frm->Button(-text=>'Go!',-background=>$main_bg,
-relief=>'raised',-command=>
sub {
my $n=0;
@machines=();
while ($n <= $#machvals ) {
if (defined($machvals[$n])&&$machvals[$n]==1) {
push(@machines,"test$n") if ($n <= 10);
push(@machines,"alpha") if ($n==11);
push(@machines,"beta") if ($n==12);
}
$n++;
}
if ($#machines<0) {
&message
($msg_area,
"Please select at least one machine.");
} elsif (!$op) {
&message ($msg_area,
"Please select an operation.");
} else {
my @output=();
open(PWR,"power $op @machines |");
while (<PWR>) {
chop;
push (@output,$_);
}
&message ($msg_area,
join ("\n",@output));
}
})
->pack(-side=>'left',-anchor=>'s',-fill=>'x',
-padx=>'2',-pady=>'2');
#my $about_btn=
# $button_frm->Button(-text=>'About', -background => $main_bg,
# -relief=>'raised',-command=> sub {
# &message( $msg_area,
# "By Mac Newbold, Flux Research Group,\n",
# "University of Utah Computer Science Dept."); } )
# ->pack(-side=>'left',-anchor=>'s',-fill=>'x',
# -padx=>'2',-pady=>'2');
my $help_btn=
$button_frm->Button(-text=>'Help',-background => $main_bg,
-relief=>'raised',-command=>sub {
&message( $msg_area,
"Select a function (on, off, or cycle)\n",
"Then mark all machines to update\n",
"and press the Go! button"); } )
->pack(-side=>'left',-anchor=>'s',-fill=>'x',
-padx=>'2',-pady=>'2');
my $exit_btn=
$button_frm->Button(-text=>'Exit', -background => $main_bg,
-relief=>'raised',-command=>sub{$main->destroy})
->pack(-side=>'left',-anchor=>'s',-fill=>'x',
-padx=>'2',-pady=>'2');
MainLoop();
sub message {
(my $area,my @msg) = @_;
my $text= join('',@msg);
$area->configure(-text=> $text );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment