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)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:
SetWidgetPos(display, NO_CARE, NULL, PLACE_RIGHT, var)
SetWidgetPos(quit, NO_CARE, NULL, PLACE_RIGHT, display)
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.guiYou should see something like this:
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")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.
MakeMenuItem(sdfopen, file, "SDF Open", Load, "sdfopen")
Click here for the modified script. Try it out. You should see something like this:
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")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.
GetNamedColor(sblue,"LightSkyBlue")
Finally, we reset the widget colors
SetBgColor(file,sblue)The function SetBgColor() sets the widget's background color; the function SetFgColor() sets the widget's foreground color.
SetBgColor(var,gray)
SetBgColor(display,gray)
SetBgColor(quit,red)
SetFgColor(var,yellow)
SetFgColor(display,yellow)
SetFgColor(quit,yellow)
Click here for the modified script. Try it out. You should get something like this:
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: