[mcclim-devel] mcclim-devel Digest, Vol 39, Issue 6

Andy Hefner ahefner at gmail.com
Fri Dec 5 19:26:53 UTC 2008


This program's display function recurses infinitely (display-function
-> redisplay-frame-panes -> ... -> display-function), and control is
never returned to the event loop. I'm surprised it worked in the past.

The only reliable technique I know to achieve animation in mcclim is
to use a separate thread which loops calling sleep and sends an event
to the application frame periodically. I've attached a version of your
program using this technique.


(defpackage :mini
  (:use :clim :clim-extensions :clim-lisp))
(in-package :mini)

(let ((colors (list +red+ +green+)))
  (setf colors (nconc colors colors))
  (defun display-function (frame pane)
    (draw-circle* pane 10 10 10 :ink (pop colors))))

(defun quit ()
  (frame-exit *application-frame*))

(define-application-frame mini ()
  ()
  (:panes
   (display :application
	    :display-function 'display-function
	    :incremental-redisplay t)
   (quit
    :push-button
    :label "Quit"
    :activate-callback (lambda (x)
			 (declare (ignore x))
			 (quit))))
  (:layouts
   (defaults (vertically () display quit))))

(defun run-test (name)
  (run-frame-top-level (make-application-frame name)))

(defun start ()
  (run-test 'mini)
  0)

(defclass interrupt-event (climi::standard-event)
  ((fn :initarg :fn :reader fn-of))
  (:default-initargs :sheet nil))

(defmethod handle-event (sheet (event interrupt-event))
  (funcall (fn-of event)))

(defmethod run-frame-top-level :around ((mini mini) &key)
  (let ((running t))
    (clim-sys:make-process
     (lambda ()
       (loop while running do
             (sleep 0.50)
             (climi::event-queue-append
              (climi::frame-event-queue mini)
              (make-instance 'interrupt-event
                             :fn (lambda () (redisplay-frame-panes mini)))))))
    (unwind-protect (call-next-method)
      (setf running nil))))




More information about the mcclim-devel mailing list