--- Tk Genie ---

If genie is started up as "genie -B" it will start in Tk/Tcl mode At the % prompt, you can use all the normal TCL commands, as well as the following commands for communicating with GENIE:

gcl "command"

This command takes a string and sends it to GENIE where it is executed as if you

had typed it at the command line. Output from the command is returned

as a TCL list consisting of output from {PRINTN, PRINTIN, PRINTEN, <C debugging output>}

gcl "set/file \"/usr/local/genie/examples/hrp08396.raw\""

set output_from_genie [ gcl "w=get(1)" ]

 

If you only require the output from PRINTN, then you can skip the list and the other output streams by using:

set a [ gcl "PRINTN 5" -out ] # sets a to "5"

Buttons and Menus can be created in Tk/Tcl and bound to GENIE events:

button .b1 -text "set file" -command { gcl "set/file \"myfile.dat\"" }

pack .b1

A Tk driver has been written for PGPLOT, based on the Tk canvas widget. Opening a drawing device is a two stage process - first you create an object of type "pgwindow" in TCL by e.g.

pgwindow .p1 -width 600 -height 600

pack .p1

 

The window can have any name, but must end in a number between 1 and 5; this number

is used to associate the device with PGPLOT e.g for the above you would then do

gcl {dev1Þvice:open("tk1")}

gcl {win_unscaled 0.1 0.9 0.1 0.9 $red}

gcl {draw/text 0.5 0.5 "hello" $blue}

 

As the driver is based on a TK canvas, and all PGPLOT items are canvas items, .p1 can be used like a normal canvas e.g.

.p1 create text 50 50 -text "hello"

All pgplot items are drawn with the canvas tag "pgitem" so you can set up procedures to be called on a mouse click on an item e.g.

.p1 bind pgitem <Button-2> { puts stdout "PGPLOT item %W pressed at %x %y" }

PROBLEM: a GENIE coloured window (i.e. one created by e.g. WIN_UNSCALED) is implemented by filling a rectangle of the size of the window with the specified colour; as this rectangle is also a pgitem, you will get events and bindings generated all over the window. To avoid this, colour your window from the Tk end e.g.

pgwindow .p1 -background red

And create all GCL windows in the default background colour.

You can also make PGPLOT items dragable with e.g. mouse button 1

proc MarkAnItem { x y w } {

global item_state

set item_state($w,item) [ $w find closest $x $y ]

set item_state($w,x) $x

set item_state($w,y) $y

}

 

proc DragAnItem { x y w } {

global item_state

set dx [ expr $x - $item_state($w,x) ]

set dy [ expr $y - $item_state($w,y) ]

$w move $item_state($w,item) $dx $dy

set item_state($w,x) $x

set item_state($w,y) $y

}

 

.p1 bind pgitem <Button-1> { MarkAnItem %x %y %W }

.p1 bind pgitem <B1-Motion> { DragAnItem %x %y %W }

Note that the gcl "hardcopy" command will only write PGPLOT items to a file i.e. anything you add or move using Tk will be missing. If you want to get the whole plot, you can use the canvas postscript generation options:

button .b2 -text "Hardcopy" -command { .p1 postscript -file picture.ps }

A Tk Interface is under development at ISIS, and the idea is to provide a rudimentary interface and also a set of useful utilities e.g. a tcl "display" command that will, as well as drawing a plot, aloow you to interactively change e.g. line colour by clicking on a line. However, the above should allow anybody who wishes the ability to knock up a GUI for a GCL command procedure they write.

Watch the WWW pages for further developments

 

--

Freddie Akeroyd Email: faa@isise.rl.ac.uk

ISIS Facility Tel: +44 1235 445457

Rutherford Appleton Laboratory Fax: +44 1235 445720

Chilton, DIDCOT, OX11 OQX WWW: http://www.isis.rl.ac.uk/