首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否存在McCLIM单击侦听器?

是否存在McCLIM单击侦听器?
EN

Stack Overflow用户
提问于 2021-06-04 02:28:20
回答 1查看 136关注 0票数 2

我一直在努力学习McCLIM,考虑到文档的简洁性,这是相当困难的。在阅读了手册之后,我还没有弄清楚如何将单击关联到窗格并运行命令。我知道我可以定义如下命令:

代码语言:javascript
复制
(define-app-command (com-say :name t) ()
  (format t "Hello world!"))

然后在命令框中键入Say,让它做一些事情。我想点击一个窗格并让它在点击时输出这个hello world字符串。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-04 18:20:40

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

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

代码语言:javascript
复制
;;;; 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!“在窗格里。

代码语言:javascript
复制
(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)
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67830759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档