next up previous contents index
Next: Dialogs Up: Graphical Interface Tools Previous: Graphical Interface Tools

Menus

As an illustration I will outline how to construct a menu for sending some simple messages to a regression model. I will make the convention that there is a current regression model, the value of the symbol *current-model*. 

Menus are created by sending the :new message to the menu prototype, menu-proto. The method for this message takes a single argument, the menu title. We can use this message to set up our menu:

> (setf model-menu (send menu-proto :new "Model"))
#<Object: 4055334, prototype = MENU-PROTO>
Macintosh menus can be installed in and removed from the menu bar by sending them the :install and :remove messages:
> (send model-menu :install)
NIL
> (send model-menu :remove)
NIL
On other systems menus are popped up; this can be accomplished by sending the :popup message to a menu. This message requires two arguments, the x and y pixel coordinates of the left top corner of the menu, measured from the left top corner of the screen.

Initially the menu has no items in it. Items are created using the menu-item-proto prototype. The initialization method requires one argument, the item's title, and takes several keyword arguments, including

Analogous messages are available for changing these values in existing menu items.

Suppose we would like to be able to use our menu to print a summary of the current model or obtain a residual plot. We can construct two menu items:

> (setf summary (send menu-item-proto :new "Summary" :action
                   #'(lambda () (send *current-model* :display))))
#<Object: 4034406, prototype = MENU-ITEM-PROTO>
> (setf plot (send menu-item-proto :new "Plot Residuals" :action 
                   #'(lambda () (send *current-model* :plot-residuals))))
#<Object: 3868686, prototype = MENU-ITEM-PROTO>
Suppose we have assigned the bikes2 model of Section 7 to *current-model*. You can force an item's action to be invoked by sending it the :do-action message from the listener:
> (send summary :do-action)

Least Squares Estimates:

Constant               -16.41924   (7.848271)
Variable 0              2.432667   (0.9719628)
Variable 1           -0.05339121   (0.02922567)

R Squared:             0.9477923
Sigma hat:             0.5120859
Number of cases:              10
Degrees of freedom:            7

NIL
Ordinarily you will not send this message this way: the system sends this message to the menu item when you select the item from a menu.

To add these items to the menu use the :append-items message:

> (send model-menu :append-items summary plot)
NIL
You can also use the :append-items message to add items to a plot menu. The menu associated with a plot can be obtained by sending the plot the :menu message with no arguments.

You can enable and disable a menu item with the :enabled message:

> (send summary :enabled)
T
> (send summary :enabled nil)
NIL
> (send summary :enabled t)
T



next up previous contents index
Next: Dialogs Up: Graphical Interface Tools Previous: Graphical Interface Tools



Luke Tierney
Tue Jan 21 15:04:48 CST 1997