1

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"))
4

1 回答 1

2
(defun show (text)
   (setf (gadget-value (slot-value *application-frame* 'text-field))
         text))

在上述函数中,您尝试从插槽中获取小工具。这不是办法。请改用 FIND-PANE-NAMED。给它一个框架和窗格的名称。它将返回该窗格。

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

同样,您现在在完全不同的上下文中使用 SHOW。现在它应该返回一个 LAMBDA,它将小工具作为参数。

  (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)))))))

现在代码:layouts看起来不对。您不应该在其中设置插槽文本字段。实际上,您根本不应该有插槽 TEXT-FIELD。只需在您的回调中使用 FIND-PANE-NAMED 函数。在这里,您只需定义一个布局。

于 2018-11-05T21:14:39.563 回答