McCLIM 点击监听器是否存在?

Does a McCLIM Click Listener exist?

我一直在努力学习 McCLIM,考虑到文档的简洁性,学习起来非常困难。阅读 the manual 后,我无法弄清楚如何将单击与窗格和 运行 相关联。我知道我可以定义如下命令:

(define-app-command (com-say :name t) ()
  (format t "Hello world!"))

然后在命令框中键入 Say 以使其执行某些操作。我想单击一个窗格并让它在单击时输出这个 hello world 字符串。

我需要设置什么才能在给定窗格上启用点击侦听器?

至少有两种方法可以做到这一点。第一个是使用 presentationspresentation-to-command-translator,第二个是使用像 push-button 这样的小工具(又名小部件)。我想您还没有了解 presentations,所以我将向您展示如何使用小工具进行学习。

下面的示例将有一个窗格和一个按钮。当你点击按钮时,你会看到“Hello World!”输出到窗格。

;;;; First Load McCLIM, then save this in a file and load it.

(in-package #:clim-user)

(define-application-frame example ()
  ()
  (:panes
   (app :application
        :scroll-bars :vertical
        :width 400
        :height 400)
   (button :push-button
          :label "Greetings"
          :activate-callback
          (lambda (pane &rest args)
            (declare (ignore pane args))
            ;; In McCLIM, `t` or *standard-output is bound to the first pane of
            ;; type :application, in this case `app` pane.
            (format t "Hello World!~%" ))))
  (:layouts
   (default (vertically () app button))))

(defun run ()
  (run-frame-top-level (make-application-frame 'example)))

(clim-user::run)

P.S. 学习如何在 McCLIM 中做某事的一种方法是 运行 并查看 clim-demos。一旦您发现一些有趣的东西并想知道它是如何完成的,请在 McCLIM 源的 Examples 目录中查看它的源代码。

对于帮助,最好使用 IRC 聊天(libera.chat 上的#clim),多个 McCLIM 开发人员在那里闲逛。


编辑: 第二个示例 presentation-to-command-translator,单击窗格中的任意位置将输出“Hello World!”在窗格中。

(in-package #:clim-user)

(define-application-frame example ()
  ()
  (:pane :application
   :width 400
   :display-time nil))

;; Note the `:display-time nil` option above, without it default McCLIM command-loop
;; will clear the pane after each time the command is run. It wasn't needed in previous
;; example because there were no commands involved.

(define-example-command (com-say :name t)
    ()
  (format t "Hello World!~%"))

(define-presentation-to-command-translator say-hello
    (blank-area com-say example :gesture :select)
    (obj)
  nil)

(defun run ()
  (run-frame-top-level (make-application-frame 'example)))

(clim-user::run)