McCLIM, How to catch a keystroke?

163 views Asked by At

I'm currently learning McCLIM. Trying to figure out how to define a command, that will react to keystroke. For a app named superapp I have a function

(defun show (text)
  (lambda (gadget)
    (declare (ignore gadget))
 (with-slots (text-field) *application-frame*
(setf (gadget-value text-field)
   text))))

which show some text on it's screen pane. It works fine for pane-buttons in activate-callback. However, this

(define-superapp-command (com-greet :name t :keystroke (#\g :control)) ()
 (show "Hey"))

doesn't work. I know that I defined it right, since it works well with (frame-exit *application-frame*). So I just don't understand something else.

EDIT: SO, this is the working variant

(define-application-frame superapp ()
 ()
 (:panes
  (tf1
   :push-button
       :label "Left"
       :activate-callback (show "HI"))
  (app :application
   :display-time nil
   :height 400
   :width 600)
  (screen :text-field))
 (:layouts
  (default
   (with-slots (text-field) *application-frame*
               (vertically ()
                screen
                (tabling (:grid t)
                 (list tf1 app)))))))

(defun show (text)
 (lambda (gadget)
   (declare (ignore gadget))
  (setf (gadget-value (find-pane-named *application-frame* 'screen)) 
    text)))

(define-superapp-command (com-greet :name t :keystroke (#\g)) ()
 (setf (gadget-value (find-pane-named *application-frame* 'screen)) 
 "text"))
1

There are 1 answers

3
Rainer Joswig On BEST ANSWER
(defun show (text)
   (setf (gadget-value (slot-value *application-frame* 'text-field))
         text))

In above function you try to get a gadget from a slot. This is not the way to do. Use FIND-PANE-NAMED instead. Give it a frame and the name of the pane. It will return that PANE.

(define-application-frame superapp ()
 ((text-field :initform nil))
 (:panes
  (tf1
   :push-button
       :label "Left"
       :activate-callback (show "HI"))

Again, you now use SHOW in a totally different context. Now it SHOULD return a LAMBDA, which gets the gadget as an argument.

  (app :application
   :display-time nil
   :height 400
   :width 600)
  (screen :text-field))
 (:layouts
  (default
   (with-slots (text-field) *application-frame*
               (vertically ()
                (setf text-field screen)
                (tabling (:grid t)
                 (list tf1 app)))))))

Now the code in :layouts looks wrong. You should not set the slot text-field in there. Actually you should not have a slot TEXT-FIELD at all. Just use in your call back the function FIND-PANE-NAMED. Here you just define a layout.