Prev Next Title Contents

GRAPHIC USER INTERFACE


It is possible to modify and adapt the user interface within the Gifa program. The graphic user interface (GUI) is completely built from a simple set of basic commands which permits to build menus, dialogue boxes, etc...

BUTTONBOX, PULLDOWNMENU, CLOSEBUTTON,

The command BUTTONBOX creates a new entry in the menu bar, and create the menu bar for the first time. Parameters of the command are the name of the menu as it appears in the menu bar, then a list of entries consisting of the name of the button and the Gifa command associated to it. The lists end with a *. The special entry separator does not set a button but a separator in the box.

Any legal command can be used to be associated with a given button, a built-in command as well as a macro, and will be executed as if entered form the terminal. So the WHILE, FOR, IF .. THEN, GOTO commands are not available but the IF .. any_command syntax is valid. The action of the command in independent from the way it is called, except for the user prompting for values, which is performed with dialogue boxes in the case of a command called from a button.

Example given :

BUTTONBOX "my first menu" \

Hello "print 'Hello World'" \

separator \

Dim dim \

"Test Dim" "if ($dim == 2) print 'We are in 2D'" \

Back ("read" ; $name) \

Reread "read $name" \

*

Which gives :

Note :

Depending o the state of PULLDOWNMENU, the menus that are created will appear as static button boces (as shown above) or as regular pulldownmenus. The choice cannot be changed while there is a menubar already opened, but it is possible to close the current menu bar, to change mode, and to rebuild a new menu bar.

The command CLOSEBUTTON closes the menu bar and all the associated menus. It is equivalent to closing the menu bar from the close box.

MESSAGE

This command permits to build macros which have exactly the same behaviour than built-in commands. The macro example

message "Enter new size" set newsize := $_

will react as follow :

nothing will appear if called with a parameter :

example 256

the user will be prompted if called without parameters :

example

the user will be prompted in a dialogue box if the macro is called without parameters from a menu button.

In any case, this is independent of the way the macro is actually called, either directly or from within another macro.

FORMBOX, DIALOGBOX, CLOSEWIDGET

The first two commands are closely related.

DIALOGBOX permits to build sophisticated dialogue boxes, several fields can be built into the dialogue box, that the user has to fill-up. Each filed is internally associated to a Gifa variable, that the remain of the macro processes. The command appears as follow :

DIALOGBOX [series of entry] *

Each entry consists of a name, that appears as such in the dialogue box, and of a type for the field. Types can be : message, text, string, int, real, file, enum.

message type consists of a string that is displayed on the form and permits to put text in it. text permits to display the content of a text file, in a scrollable sub-window.

The others type of field have two other entries which give the name of the associated variable and its default value. These types correspond to editable fields that the user has to fill-up. string, int, real correspond to string, real values or integer values respectively; file corresponds to a file-name entry, and presents a small additional button in the dialogue box, which permits to pop-up a standard Motif file selection box.

The last type : enum realises a pop-up menu, for an enumerated choice. It needs an additional entry which described the list of choice.

The special entries separator and noreturn are meant for formatting the dialogbox. separator draw a thin horizontal line in the box, noreturn indicates that the previous and the following field will be on the same line.

Example given :

Dialogbox "my first dialogue" \

"Enter below the file name to work on" message \

"Enter file name" file var_file $name \

separator \

"Action to apply" enum "Read,Write" var_act % \

*

$var_act $var_file

This macro will build a dialogue box with 2 editable entries : (filename and action) and will apply the action to the selected file if the user clicks on Ok :

Note :

FORMBOX is the static version of DIALOGBOX. It builds a form that will remain after the completion of the command (as BUTTONBOX does) and will survive as long as the user does not explicitly closes it. FORMBOX need an additional field (the callback) which describes the Gifa command to be executed when the user clicks on the Ok or Apply buttons. Another difference is that FORMBOX can accept an additionnal field type : action which takes its following argument as a Gifa command, and binds it to a new button.

Apart from this, the definition of FORMBOX is strictly equivalent to that of DIALOGBOX. If not global, a variable associated to a field in a FORMBOX is local to the FORMBOX, and cannot be accessed in any other macros but the in callback line. Example given :

Formbox "my first Form" \

"print ('today it is';$the_wet;', but I am';$myself) " \

"Enter informations below" message \

"The weather today :" \

enum "Sunny,Rainy,Cold,Stormy,Terrible" the_wet % \

noreturn \

"Check weather" action "if ($the_wet s! 'Sunny') print 'BAD !'" \

"I am myself :" string myself "fine" \

*

Which builds the following form :

Cliking on Check weather produces : BAD !

Clicking on Apply or Ok, produces : today it is Cold , but I am fine

Note :

Some time you want to close a formbox from within a macro executing within the formbox! The CLOSEWIDGET command is here for you. From within a from, the id of the form can be accessed with the $WIDGET context. It is then used as argument by CLOSEWIDGET to close the form.

Example given :

; $nct is global variable holding some value

; this text is in a file called do_count

formbox counter \

DO_NOTHING \ ; this is a dummy macro

('Current value is'; $nct) message \

'Increment' action 'set nct := (%+1) closewidget $widget do_count' \

noreturn \

'Decrement' action 'set nct := (%-1) closewidget $widget do_count' \

*

Then this macro builds a form like this :

Clicking on Increment increments the global variable, and closes the old form and creates a new one with the updated value.


Prev Next Title Contents