Hallo Martin,
On Thu, Dec 17, 2009 at 8:23 PM, Martin Kielhorn kielhorn.martin@googlemail.com wrote:
Hi, the scale of the program in the bottom doesn't work as I want. I want the :command lambda to be called whenever the scale changes.
That is what the command parameter is for...
;; test program (not working as expected): (require :asdf) (require :ltk)
(defpackage :mk (:use :cl :ltk)) (in-package :mk) (with-ltk () (let* ((f (make-instance 'frame)) (s (make-instance 'scale :orientation :horizontal :master f :command (lambda () (format t "SCALE NOW ~d~%" (value s)))
^^ you cannot refer to s here...
;; why can't i write command here )) (b (make-instance 'button :text "get" :master f :command (lambda () (format t "SCALE IS ~d~%" (value s)))))) (pack f) (pack (list s b))))
So your program was almost right, but you cannot access s at that position, because the variable isn't defined yet. Fortunately, you don't have to, because the callback conveniently is passed the new value which you can just use. So your code should look like that:
(defun test () (with-ltk () (let* ((f (make-instance 'frame)) (s (make-instance 'scale :orientation :horizontal :master f :to 100.0 ;; setting a to value makes it behave nicer :command (lambda (val) (format t "SCALE NOW ~d~%" val) (finish-output)) ;; if you want to see the output immediately... )) (b (make-instance 'button :text "get" :master f :command (lambda () (format t "SCALE IS ~d~%" (value s)) (finish-output))))) (pack f) (pack (list s b)))))
However: this also uncovered a bug in the scale widget, it was not passing the value correctly. If you download http://ltk.rplay.net/svn/branches/ltk/repl/ltk.lisp you will get a fixes ltk. One caveat: this Ltk version expects a Tk version 8.5 or above, so if the program "wish" on your system is not 8.5, you either need to set *wish-pathname* to the name of your 8.5 executable (e.g. "wish8.5" on my system) or, you need to push :tk84 on the *features* before compiling LTk, so that an Tk 8.4 compatible LTk is being compiled.
Regards, Peter