All Manuals > CLIM 2.0 User Guide > 9 Defining Application Frames

9.7 Examples of CLIM Application Frames

This section contains examples of how to use CLIM application frames.

9.7.1 Defining a CLIM Application Frame

Here is an example of an application frame. This frame has three slots: pathname, integer, and member. It has two panes, an :accept-values pane named avv and an :application pane named display. It uses a command table named dingus, which will automatically be defined for it (see define-command-table) and which inherits from the accept-values-pane command table so that the accept-values pane will function properly.

(clim:define-application-frame dingus () 
  ((pathname :initform #p"foo") 
   (integer :initform 10) 
   (member :initform :one)) 
  (:panes 
   (avv :accept-values 
        :display-function '(clim:accept-values-pane-displayer 
                            :displayer display-avv)) 
   (display :application :display-function 'draw-display 
            :display-after-commands :no-clear))
  (:command-table (dingus :inherit-from (clim:accept-values-pane))))

The following is the display function for the display pane of the "dingus" application. It just prints out the values of the three slots defined for the application.

(defmethod draw-display ((frame dingus) stream) 
  (with-slots (pathname integer member) frame 
              (fresh-line stream) 
              (clim:present pathname 'pathname :stream stream) 
              (write-string ", " stream) 
              (clim:present integer 'integer :stream stream) 
              (write-string ", " stream)
              (clim:present member '(member :one :two :three) 
                            :stream stream)
              (write-string "." stream)))  

The following is the display function for the avv pane. It invokes accept for each of the application's slots so that the user can alter their values in the avv pane.

(defmethod display-avv ((frame dingus) stream) 
  (with-slots (pathname integer member) frame
              (fresh-line stream) 
              (setq pathname
                    (clim:accept 'pathname :prompt "A pathname" 
                                 :default pathname :stream stream)) 
              (fresh-line stream) 
              (setq integer
                    (clim:accept 'integer :prompt "An integer" 
                                 :default integer :stream stream)) 
              (fresh-line stream) 
              (setq member 
                    (clim:accept '(member :one :two :three) 
                                 :prompt "One, Two, or Three" 
                                 :default member :stream stream)) 
              (fresh-line stream) 
              (clim:accept-values-command-button 
               (stream :documentation "You wolf")
               (write-string "Wolf whistle" stream)
               (beep))))

The following function will start up a new "dingus" application.

(defun run-dingus (root) 
  (let ((dingus (clim:make-application-frame 
                 'dingus :width 400 :height 400))) 
    (clim:run-frame-top-level dingus)))

All this application does is allow the user to alter the values of the three application slots, pathname, integer, and member, using the avv pane. The new values will automatically be reflected in the display pane.

9.7.2 Constructing a Function as Part of Running an Application

You can supply an alternate top level (which initializes some things and then calls the regular top level) to construct a function as part of running the application. Note that when you use this technique, you can close the function over other pieces of the Lisp state that might not exist until application run time.

(clim:define-application-frame
 different-prompts ()
 ((prompt-state ...) ...) 
 (:top-level (different-prompts-top-level)) ...)
 
(defmethod different-prompts-top-level
  ((frame different-prompts) &rest options)
  (flet ((prompt (stream frame)
                 (with-slots (prompt-state) frame 
                             (apply
                              #'clim:default-frame-top-level frame
                              :prompt #'prompt options)))
         ...)))

CLIM 2.0 User Guide - 01 Dec 2021 19:38:58