in reply to Program design with GUI interface
$SIG{CHLD} = "IGNORE"; use Tk; use integer; $rlApps = [map{[m<^(.*):(.*)>m]} <DATA>]; $longestName = 0; foreach (@$rlApps) { my $l = length $_->[0]; $longestName = $l if $l > $longestName; } chomp($hostName = `/usr/bin/hostname`); $ENV{DISPLAY} = $hostName . $ENV{DISPLAY} if $ENV{DISPLAY} eq ":0.0"; $bgColour = "LightSteelBlue3"; %buttonColours = ( "-background" => "grey35", "-foreground" => "yellow2", "-activebackground" => "grey45", "-activeforeground" => "yellow", "-disabledforeground" => "grey55"); $mainWin = MainWindow->new( "-background" => $bgColour); $mainWin->title("xlaunch"); $mainWin->resizable(0, 0); $appsSelectFrame = $mainWin->Frame( "-relief" => "ridge", "-background" => $bgColour, "-borderwidth" => 2)->pack( "-side" => "top", "-fill" => "y", "-expand" => 1); foreach (0 .. $#{$rlApps}) { my $buttonName = $rlApps->[$_]->[0] . "Button"; $$buttonName = $appsSelectFrame->Button( "-text" => $rlApps->[$_]->[0], %buttonColours, "-width" => $longestName)->pack( "-side" => "top", "-padx" => 5, "-pady" => 5); $$buttonName->configure( "-command" => [\&invokeApp, $_]); } $controlButtonFrame = $mainWin->Frame( "-relief" => "flat", "-background" => $bgColour, "-borderwidth" => 2)->pack( "-side" => "top"); $controlButtonFrame->Button( "-text" => "Quit", %buttonColours, "-command" => sub {exit;})->pack( "-side" => "right", "-padx" => 5, "-pady" => 5); MainLoop(); sub invokeApp { my $appSub = shift; my $cmd = $rlApps->[$appSub]->[1]; my $pid; if($pid = fork) { return; } elsif(defined($pid)) { exec $cmd; } else { die "Fork error: $!\n"; } } __END__ Acrobat Reader:/usr/local/bin/acroread CGM Viewer:/usr/openwin/bin/xterm -sb -sl 500 -title "CGM Viewer" -e / +ogis00/app/bin/cgm_viewer Petrobank:/usr/openwin/bin/xterm -sb -sl 500 -title "Petrobank" -e /og +is00/app/bin/petrobank Geolog:/usr/openwin/bin/xterm -sb -sl 500 -title "Geolog" -e /ogis00/a +pp/bin/geolog Netscape:/usr/dt/bin/netscape WebPlot:/usr/openwin/bin/xterm -sb -sl 500 -title "WebPlot" -e /ogis00 +/app/bin/webplot Xgeo:/usr/openwin/bin/xterm -sb -sl 500 -title "Xgeo" -e /ogis00/app/b +in/xgeo ZMAP:/usr/openwin/bin/xterm -sb -sl 500 -title "ZMAP" -e /ogis00/app/b +in/zmap Calculator:/usr/dt/bin/dtcalc File Manager:/usr/dt/bin/dtfile Xterm:/usr/openwin/bin/xterm -sb -sl 2000
I hope you find it useful.
Cheers,
JohnGG
|
|---|