Using GrADS with Athena Widgets

Previous section: Running the sample script | Next section: Writing the sample script


Writing simple scripts

Now that you understand the basic functionality of GAGUI you are ready to learn how to write your own GUI script, or at least how to customize the provided sample scripts for your own taste and needs. In this section we introduce the most basic GAGUI functions by constructing a much simpler version of the sample script. In the next section we will walk you through the sample script described in the previous section. A detailed description of each GUI function and associated callbacks can be found in the Reference Section.

Example 1: Opening files, displaying variables, and quitting

The most basic GUI function is MakeButton which creates a button and associate a function (callback) with it. Here is how you create a button for opening a file
MakeButton( open, "Open", Load, "open" )
The first argument, open, is a name you give to the widget so that later you can modify some of its attributes such as color or font. The string "Open" is the text that will be drawn on the button. The third argument, Load, is the name of an internally defined callback function which in this case is a function for open GrADS data files. The last argument, "open" is the GrADS command for opening the file (other options are "sdfopen" or "xdfopen").

To select the default expression we use the VarSel callback:

MakeButton( var, "Var", VarSel, NULL)

To display the default expression we use the Display callback:

MakeButton( display, "Display", Display, "display" )
Finally, we need a way out so we make a Quit button:
MakeButton( quit, "Quit", Cmd, "quit" )
The callback Cmd executes the GrADS command "quit" specified as the last argument. The next step is to specify the relative position of each widget, i.e., who goes to to right of whom.
SetWidgetPos(var, NO_CARE, NULL, PLACE_RIGHT, open)
SetWidgetPos(display, NO_CARE, NULL, PLACE_RIGHT, var)
SetWidgetPos(quit, NO_CARE, NULL, PLACE_RIGHT, display)
The second and third arguments of SetWidgetPos() are needed when we have more than one row of widgets which is not our case in this example. Finally, all GrADS GUI scripts must end with this function:
MainLoop()
Click here for the full script. Save it to a file in your local disk, say ex1.gui, and execute it:
ga-> gui ex1.gui
You should see something like this:

GAGUI Example 1

Play around, try to add additional buttons. Suggestion: add Clear and Reinit buttons.

Example 2: Creating menus

Let's get a bit fancy. Instead of a button for opening a file let's create a File menu where we could open or sdfopen a file. First we create the menu with the syntax:
MakeMenu ( file, "File" )
Here file is the name of the menu, while file "File" is the text that will be drawn on the menu. Next we create the 2 menu items:
MakeMenuItem( open, file, "Open", Load, "open")
MakeMenuItem(sdfopen, file, "SDF Open", Load, "sdfopen")
The first argument is the name of widget for referring to it later if you want to. The second argument, file is the name of the menu this item belongs to. Arguments 3 thru 5 are menu item title, callback and callback argument, similar to the MakeButton() function above.

Click here for the modified script. Try it out. You should see something like this:

GAGUI Example 2

Example 3: Tinkering with colors

All is well and good but these white widgets look ugly. Let's add some color to make them more interesting. First we issue this command to force the widgets to appear on the screen:
ShowDisplay()
Next, we define colors:
GetNamedColor(gray,"grey")
GetNamedColor(sblue,"LightSkyBlue")
The first argument of GetNamedColor() is the name you give to the color for later use; the second argument is the name X windows uses for the color; you can view the list of available X11 color names with the showrgb command in a Unix shell. The colors white, back, red, green, blue, and yellow are automatically defined.

Finally, we reset the widget colors

SetBgColor(file,sblue)
SetBgColor(var,gray)
SetBgColor(display,gray)
SetBgColor(quit,red)
SetFgColor(var,yellow)
SetFgColor(display,yellow)
SetFgColor(quit,yellow)
The function SetBgColor() sets the widget's background color; the function SetFgColor() sets the widget's foreground color.

Click here for the modified script. Try it out. You should get something like this:

GAGUI Example 3

Example 4: Tinkering with fonts

Choosing a nice font for your widgets can greatly improve their appearance. The first step is to get desired font:
GetFont(font,"-*-helvetica-bold-o-normal--14-*-*-*-*-*-*-*" )
The first argument of GetFont() is the name you give to the font for later use; the second argument is the name X windows uses for the font. You can find out which fonts are available with your X server through the command xlsfonts available on most Unix systems, and in Windows 95/NT if you have X11R6.3 installed.

Once the font has been defined you can then reset the font of all widgets

AllWidgetFont(font)
The function SetWidgetFont() can also be used for setting the font of individual widgets; see the Reference Section.

Click here for the modified script. Try it out. You should get something like this:

GAGUI Example 4

Previous section: Running the sample script | Next section: Writing the sample script