Does a McCLIM Click Listener exist?

247 views Asked by At

I have been trying to learn McCLIM and it has been quite difficult given the terseness of the documentation. After reading the manual I haven't been able to figure out how to associate a click to a pane and run a command. I am aware I can define commands such as:

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

And type Say into the command box to get it to do something. I would like to click a pane and have it output this hello world string when clicked.

What do I need to set up in order to enable click listeners on a given pane?

1

There are 1 answers

2
Nisar Ahmad On BEST ANSWER

There are at least two ways you can do that. The first would be using presentations and presentation-to-command-translator and second would use gadgets (aka. widgets) like push-button. I guess you haven't learned about presentations yet, so I would show you how to do it with gadgets.

The below example would have a pane and a push button. when you click the button, you would see "Hello World!" output to the pane.

;;;; 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. One way to learn how to do something in McCLIM is to run and look at clim-demos. Once you find something interesting and want to know how it is done, look at its source in Examples directory of McCLIM source.

For Help, it is much better to use IRC chat (#clim on libera.chat) where multiple McCLIM devs hang out.


EDIT: Second example with presentation-to-command-translator, clicking anywhere in the pane would output "Hello World!" in the pane.

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