我一直在努力学习McCLIM,考虑到文档的简洁性,这是相当困难的。在阅读了手册之后,我还没有弄清楚如何将单击关联到窗格并运行命令。我知道我可以定义如下命令:
(define-app-command (com-say :name t) ()
(format t "Hello world!"))然后在命令框中键入Say,让它做一些事情。我想点击一个窗格并让它在点击时输出这个hello world字符串。
要在给定窗格上启用单击侦听器,需要设置什么?
发布于 2021-06-04 18:20:40
至少有两种方法可以做到这一点。第一个将使用presentations和presentation-to-command-translator,第二个将使用小工具(又名小工具)。(小部件)如push-button。我想您还没有了解presentations,所以我将向您展示如何使用小工具来实现它。
下面的示例将有一个窗格和一个按钮。当你点击这个按钮时,你会看到“你好世界!”输出到窗格。
;;;; 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)学习如何在McCLIM中做一些事情的一种方法是运行并查看clim-demos。一旦您发现一些有趣的内容,并想知道它是如何完成的,请查看McCLIM源代码的McCLIM目录中的源代码。
为了获得帮助,最好使用IRC聊天(libera.chat上的#clim),让多个McCLIM开发人员挂起。
编辑:第二个presentation-to-command-translator示例,单击窗格中的任何位置都会输出"Hello!“在窗格里。
(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)https://stackoverflow.com/questions/67830759
复制相似问题