Using GrADS with Athena Widgets

Previous section: Writing simple scripts | Next section: Going further...


Writing the sample script

GAGUI Window

In the previous section you have been introduced to the basic aspects of GAGUI scripting. In this section we will walk you through the sample script that you first learned how to run in an earlier section. The following section will wrap things up, while the glory details are given in the Reference section.

In addition of the GUI specific functions that you have seen so far, the GAGUI scripting processor can handle any GrADS command that you would enter at the command line interface, e.g.,

set gxout shaded
which selects the color shading style for contour plots.

When debugging a script it is sometimes helpful to have every GAGUI command being executed to be echoed to the screen. You turn this echo feature ON with this function.

Debug(on)
You have commented this function out in the sample script by placing the character '#' in front of it; you can also use '*' as a comment character.

A label is an inactive widget which displays some text, e.g., an informative title. The first argument, "root" in this case, is the name you give to the widget so that you can refer to it later on:

MakeLabel(root,"GrADS")

Next we create a pushdown menu called File. As usual, the first argument, file is the name of the widget

MakeMenu(file, " File ")

Now that we have created a menu, we define its items. For the first item:

MakeMenuItem(open, file, "Open", Load, "open")
The parameters this particular item are: The definition of the other items in this menu follows.
MakeMenuItem(sdf, file, "SDF Open", Load, "sdfopen")
MakeMenuItem(xdf, file, "XDF Open", Load, "xdfopen")
MakeMenuItem(fsel, file, "File Selection ", FileSel, NULL )
MakeMenuItem(browse,file, "View Text File", Browse, NULL)
MakeMenuItem(junk, file, "_______________", NULL, NULL )
MakeMenuItem(exec, file, "Exec", Load, "exec")
MakeMenuItem(run, file, "Run", Load, "run")
MakeMenuItem(gui, file, "GUI", Load, "gui")
MakeMenuItem(junk, file, "_______________", NULL, NULL )
MakeMenuItem(fresh, file, "Refresh", Cmd, " ")
MakeMenuItem(init, file, "Reinit", Cmd, "reinit")
MakeMenuItem(exit, file, "Exit", Cmd, "quit")
Consult the Reference section for a description of the callbacks (fourth argument of MakeMenuItem()) used for these menu items. Notice that a NULL callback is used to introduce a horizontal line separating groups of items which are functionally related.

Had we turned debug ON before, we could turn it off here

Debug(off)

Next we create a menu GrADS metafile printing related operations. Note that we use the Load callback for specifying the metafile name.

MakeMenu ( print, " Print " )
MakeMenuItem(printit, print, "Print", Cmd, "print")
MakeMenuItem(enable, print, "Enable Print", Load, "enable print")
MakeMenuItem(disable, print, "Disable Print", Cmd, "disable print")

The following menu creates shortcuts for setting GrADS graphic options. Notice the use of callback CmdStr which pops up a dialog box asking the user to complement the command to be executed.

MakeMenu ( options, " Options " )
MakeMenuItem(shade, options, "Shaded", Cmd, "set gxout shaded" )
MakeMenuItem(cont, options, "Contour", Cmd, "set gxout contour" )
MakeMenuItem(grfill, options, "Grid Fill", Cmd, "set gxout grfill" )
MakeMenuItem(grvals, options, "Grid Values", Cmd, "set gxout grid" )
MakeMenuItem(vec, options, "Vector", Cmd, "set gxout vector" )
MakeMenuItem(strm, options, "Streamlines", Cmd, "set gxout stream" )
MakeMenuItem(bar, options, "Bar Chart", Cmd, "set gxout bar" )
MakeMenuItem(line, options, "Line Plot", Cmd, "set gxout line" )
MakeMenuItem(barb, options, "Wind Barbs", Cmd, "set gxout barb" )
MakeMenuItem(junk, options, "_______________", NULL, NULL )
MakeMenuItem(ci, options, "Contour Interval", CmdStr, "set cint" )
MakeMenuItem(tit, options, "Draw Title", CmdStr, "draw title " )

Here is a crude menu for defining GrADS dimensions. We plan to develop a specific callback with rubber bands, sliding bars, etc, for defining the GrADS dimension environment. For now, this menu will server as a place holder.

MakeMenu( dim, "Dim")
MakeMenuItem(lat, dim, "Latitude", CmdStr, "set lat " )
MakeMenuItem(lon, dim, "Longitude", CmdStr, "set lon " )
MakeMenuItem(lev, dim, "Level", CmdStr, "set lev " )
MakeMenuItem(time, dim, "Time", CmdStr, "set time " )
MakeMenuItem(junk, dim, "_________", NULL, NULL )
MakeMenuItem(x, dim, "x", CmdStr, "set x " )
MakeMenuItem(y, dim, "y", CmdStr, "set y " )
MakeMenuItem(z, dim, "z", CmdStr, "set z " )
MakeMenuItem(t, dim, "t", CmdStr, "set t " )

Now, let's create simple buttons. Buttons work pretty much like menu items but they do not belong to any menu and are directly clickable.

MakeButton( clear, "Clear", Cmd, "clear" )
MakeButton( quit, "Quit", Cmd, "quit" )
MakeButton( rein, "Reinit", Cmd, "reinit")
MakeButton( prompt, "ga>", CmdWin, NULL )
Notice the CmdWin callback which spawns a separate window with a GrADS Command Window widget with a scrollable history list and what not.

Here are the buttons (and toggle) which handle the display of GrADS default expressions. Currently only the hold toggle variable is implemented.

MakeButton( var, "Var", VarSel, NULL )
MakeToggle( hold, "Hold", FALSE, NULL, Toggle, "hold" )
MakeButton( prev, " << ", Display, "<<" )
MakeButton( play, "Display", Display, "DISPLAY" )
MakeButton( next, " >> ", Display, ">>" )

Once you define buttons and menus you need to enforce their relative position. The very first button is always placed at the upper left corner.

First row:

SetWidgetPos(file, PLACE_UNDER, root, NO_CARE, NULL)
SetWidgetPos(print, PLACE_UNDER, root, PLACE_RIGHT, file )
SetWidgetPos(options, PLACE_UNDER, root, PLACE_RIGHT, print )
SetWidgetPos(dim, PLACE_UNDER, root, PLACE_RIGHT, options )
SetWidgetPos(rein, PLACE_UNDER, root, PLACE_RIGHT, dim )
SetWidgetPos(prompt, PLACE_UNDER, root, PLACE_RIGHT, rein )

Second row:

SetWidgetPos(hold, PLACE_UNDER, file, NO_CARE, NULL)
SetWidgetPos(var, PLACE_UNDER, file, PLACE_RIGHT, hold )
SetWidgetPos(prev, PLACE_UNDER, file, PLACE_RIGHT, var )
SetWidgetPos(play, PLACE_UNDER, file, PLACE_RIGHT, prev )
SetWidgetPos(next, PLACE_UNDER, file, PLACE_RIGHT, play )
SetWidgetPos(clear, PLACE_UNDER, file, PLACE_RIGHT, next )
SetWidgetPos(quit, PLACE_UNDER, file, PLACE_RIGHT, clear )

You can optionally select a font for ALL widgets:

GetFont(font,"-*-helvetica-bold-o-normal--*-*-*-*-*-*-*-*" )
AllWidgetFont(font)

and select a font for and individual widget. Here is one example:

GetFont(myfont,"-*-helvetica-bold-o-normal--14-*-*-*-*-*-*-*" )
SetWidgetFont(root,myfont)

In order to make your widgets appear on the screen you must issue this command.

ShowDisplay()

After your widgets appear on the screen, you can set the color of your widgets. The following colors are pre-defined: white, back, red, green, blue, yellow.

GetNamedColor(gray,"grey")
GetNamedColor(Blue,"LightSkyBlue")
GetNamedColor(pink,"gold")
AllFgColor(black)
AllBgColor(Blue)
SetBgColor(root,white)
SetFgColor(root,red)
SetFgColor(prompt,yellow)
SetBgColor(prompt,red)
SetBgColor(prev,pink)
SetBgColor(play,pink)
SetBgColor(next,pink)
SetBgColor(hold,gray)
SetBgColor(var,gray)
SetBgColor(clear,gray)
SetBgColor(rein,gray)
SetBgColor(quit,gray)
Notice that the X window color "gold" has been assigned to the color variable pink. You usually you don't do silly things like this, but I wanted to make a point.

And you must call this function at the end of your first GUI script. This instructs the X Toolkit to enter an infinite loop, monitoring keyboard and mouse events.

MainLoop()
Repeating: you must call MainLoop().

When all is said and done, you can save the sample script to somewhere in your local disk, say to a file named sample.gui. Then, at the GrADS prompt type

ga-> gui sample.gui
to execute the sample script. You should see something like this:

GAGUI Window

Please refer to the Running the sample script for additional information.

Previous section: Writing simple scripts | Next section: Going further...