(choose-item-dialog "Kernel:" (list "Box" "Triangular" "Biweight" "Epanechinokov"))
Figure 1: Default Choose-Item-Dialog box
This default is composed of several different pieces; the list of kernel choices, a button for ``OK'' and a button for ``Cancel''. xlisp-stat provides primitives (prototypes) for each of these pieces, providing more control than is available for the defaults. In our current example, we want to eliminate the need for an ``OK'' choice by incorporating an action into the selection of the button. We can send a :new message to the choice-item-proto, telling it to create a choice-item (a set of buttons where exactly one is on and the others are off), with an action associated with the choice. In this case, we wish to change the value of the variable ktype each time a different button is selected.
(def choices (send choice-item-proto :new (list "Box" "Triangular" "Biweight" "Epanechinokov") :action #'(lambda () (def ktype (send choices :value)))))In the default ( choose-item-dialog), there was no action associated with the choice-item itself; the action was tied to the ``OK'' button. Since we've modified this behavior, we no longer need an ``OK'' button, but we do need a ``Cancel'' button. We can create this button with the send-button-proto in a fashion similar to the above example:
(def close (send button-item-proto :new "Cancel" :action #'(lambda () (send kernel-chooser :close))))Finally, by creating a list containing the different pieces, we can create the kernel-chooser dialog refered to above:
(def kernel-chooser (send modal-dialog-proto :new (list "Kernel:" (list choices) (list close))))The resulting dialog box is shown in Figure 2.
Figure 2: Customized Choose-Item Dialog Box
Notice that the argument to the :new method of modal-dialog-proto consists of a list, containing either text (like "Kernel", or lists containing objects created by previous calls to the prototyping functions. Thus, this technique can be used to build very complex dialog boxes! The following is a list of functions available for creating dialogs:
dialog-proto | dialog with built-in ``Close'' button. |
modal-dialog-proto | dialog with just the items you define |
toggle-item-proto | ``on/off'' checkbox item |
text-item-proto | static text |
edit-text-item-proto | editable text |
button-item-proto | button with associated action |
modal-button-proto | button with default ``Close'' behavior |
choice-item-proto | radio buttons allowing exactly one choice |
Suppose we wish to create a dialog box that not only allows us to select the kernel, but also a filename to open for data reading. First, we construct each item separately using the prototypes as in the previous example. We can create a text entry field for a filename with the edit-text-item-proto:
(def file (send edit-text-item-proto :new "" :text-length 20))The file object can now be incorporated into the kernel chooser using the following code; the result is shown in Figure 3.
(def kernel-chooser (send modal-dialog-proto :new (list (list "Kernel:" (list choices)) (list "Filename" (list file)) (list close))))
To retrieve the name of the file entered into the dialog box, send the :text message to the file object.