Download revision 2014b

Transcript
CHAPTER 8. THE PERL/TK FRONT-END
RWD Nickalls
137
The sign option {+|-} determines the location of the origin of the screen coordinates.
The − sign is associated with the position of the bottom right-hand corner of the widget
relative to the bottom right-hand corner of the screen, and the + sign is associated with
the top left-hand corner of the widget relative to the top left-hand corner of the screen.
In order to make the script function ‘globally’ (i.e. much as a DOS batch-file would),
it first has its mode set to ‘executable’ using the Linux command
$ chmod u+x runcamomile
(which adds the ‘executable’ permission for the user), and then the script (which must
have no file extension) is placed in the $PATH, which in the case of a Linux ‘user’s’
batch-file means that it is placed in the standard directory /usr/local/bin/ (which is
always in the Linux $PATH), i.e.
/usr/local/bin/runcamomile
Now, whichever directory the user types the command runcamomile in, then Linux
will move to the .../datexsim directory and run the tklaunch2.pl program.
8.3
Pressing the “RUN” button
The subroutine and code which starts the Camomile program is as follows: Clicking
on one of the button first deletes the screen widget (to prevent another button being
pressed), calls the associated program or message widget, and finally restores the screen
widget when the launched program terminates. For example pressing the ‘RUN’ button
launches the perl program launchcam12.pl by calling the subroutine launch() as
follows.
sub launch {
if (−e ”launchcam12.pl”)
{# first remove the Tk screen
$topwindow −>destroy if Tk::Exists($topwindow);
# now launch the program
system(”perl ./launchcam12.pl”);
# reinstate the widget when the program terminates
system (”perl ./tklaunch2.pl −geometry 300x400−50−300”)}
else{print ”....ERROR:∖n”;
print ”....can’t find program <launchcam12.pl>∖n∖n”;exit()}
}
8.3.1
Program: tklaunch2.pl
The widget program uses the perl Tk module, and the associated Tk::DialogBox. Note
that the nice Perl5/Tk logo is the image anim.gif which can be found at the following
direcctory. /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-thread-multi/
Tk/