GUI
The following simple script creates a Tk based application which looks like:
The application window has a top menubar with a pulldown menu to set the colour of the 3D object and the Tk scale widget is used to specify an angle of rotation. The scrollbar is connected to the canvas widget.
frame .fr1 -width 18c -height 15.0c -bd 2 ;#main frame
#toplevel .fr1
pack .fr1
frame .fr1.menubar -relief raised -bd 2
pack .fr1.menubar -padx 1 -fill x
menubutton .fr1.menubar.graphics -text Graphics -underline 0 -menu \
.fr1.menubar.graphics.menu
button .fr1.menubar.qb -text Quit -underline 0 -com exit
pack .fr1.menubar.graphics -side left
pack .fr1.menubar.qb -side right
#Graphics menu
menu .fr1.menubar.graphics.menu
.fr1.menubar.graphics.menu add cascade -label "Line Colour" \
-menu .fr1.menubar.graphics.menu.fmenu
menu .fr1.menubar.graphics.menu.fmenu
.fr1.menubar.graphics.menu.fmenu add radiobutton -label "Magenta" \
-com {ChangeColour "Magenta"}
.fr1.menubar.graphics.menu.fmenu add radiobutton -label "Yellow" \
-com {ChangeColour "Yellow"}
.fr1.menubar.graphics.menu.fmenu add radiobutton -label "White" \
-com {ChangeColour "White"}
frame .fr1.panl -width 2.0c -height 12.0c -bg black
frame .cfr -width 16.0c -height 12.0c -bd 1
pack .fr1.panl .cfr -in .fr1 -side left -padx 2 -fill x
canvas .can -width 12.0c -height 11.8c -xscrollcommand ".xs set" \
-yscrollcommand ".ys set"
scrollbar .ys -command ".can yview"
pack .can .ys -in .cfr -side left -fill x -fill y
scrollbar .xs -orient horizontal -command ".can xview"
place .xs -in .fr1 -x 3.2c -y 13.2c -width 12.0c
scale .scal -label "rotate box throu" -bigincrement 30 \
-from 0 -to 360 -showvalue True -orient horizontal -tickinterval 0 \
-variable cval -com {rotate_box $cval}
pack .scal -in .fr1.panl
tkwait visibility .scal
SetupPhigs .can
MakeCube
proc ChangeColour { curcolour } {
ChCol $curcolour
}
Note the options for the scale widget. Processing is suspended by call to "tkwait" toawait until the scale widget is visible. This ensure that the canvas widget is created before its X identifiers are accessed. Without it, PHIGS will try to open its workstation in a non-existent X window and will complain.
create this script in a file in the working directory. You can invoke your extended "wish" shell by including the line
#!./myappas the first line of your script. Otherwise run myapp interactively from the command-line and source this script (ensure that the script file is executable). The result should be:
You will find that PHIGS fails to update the workstation. You can force an update by sending an X event by interacting with the scale or the pulldown menu.
Tk does not support 3D graphics nor does it support rotation of items displayed within the canvas widget. In this example PHIGS is used to achieve these functionality. The result of a rotation as well as colour change looks like:
For the interested reader, we refer to Tk based GOOD which is an object oriented framework for graphical applications running under X with support for SGI GL etc. It is free but beware of documents written in German.