2

我一直在尝试学习 McCLIM,鉴于文档的简洁性,这非常困难。阅读手册后,我无法弄清楚如何将单击关联到窗格并运行命令。我知道我可以定义以下命令:

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

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

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

4

1 回答 1

4

至少有两种方法可以做到这一点。第一个将使用presentationsand presentation-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)

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

如需帮助,最好使用 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)
于 2021-06-04T18:20:40.800 回答