NextPrevUpTopContentsIndex

12.4.3 Using : resynchronize-every-pass in accepting-values

It often happens that the programmer wants to present a dialog where the individual fields of the dialog depend on one another. For example, consider a spreadsheet with seven columns representing the days of a week. Each column is headed with that day's date. If the user inputs the date of any single day, the other dates can be computed from that single piece of input.

If you build CLIM dialogs using accepting-values , you can achieve this effect by using the :resynchronize-every-pass argument to accepting-values in conjunction with the :default argument to accept . There are three points to remember:

The entire body of the accepting-values runs each time the user modifies any field. The body can be made to run an extra time by specifying :resynchronize-every-pass t . Code in the body may be used to enforce constraints among values.

If the :default argument to accept is used, then every time that call to accept is run, it will pick up the new value of the default.

Inside accepting-values , accept returns a third value, a boolean that indicates whether the returned value is the result of new input by the user or is just the previously supplied default.

In this example we show a dialog that accepts two real numbers, delimiting an interval on the real line. The two values are labelled Min and Max , but we wish to allow the user to supply a Min that is greater than the Max , and automatically exchange the values rather than signalling an error.

(defun accepting-interval (&key (min -1.0) (max 1.0) 
                                (stream *query-io*)) 
  (clim:accepting-values (stream :resynchronize-every-pass t) 
                         (fresh-line stream) 
                         (setq min
                               (clim:accept
                                'clim:real :default min
                                :prompt "Min" :stream stream)) 
                         (fresh-line stream)
                         (setq max
                               (clim:accept
                                'clim:real :default max
                                :prompt "Max" :stream stream)) 
                         (when (< max min) 
                           (rotatef min max)))
  (values min max)) 

(You may want to try this example after dropping the :resynchronize-every-pass and see the behavior. Without :resynchronize-every-pass , the constraint is still enforced, but the display lags behind the values and doesn't reflect the updated values immediately.)


Common Lisp Interface Manager 2.0 User's Guide - 27 Feb 2008

NextPrevUpTopContentsIndex