[ltk-user] How is ":serve-event t" meant to be used?

edgar edgar-rft at web.de
Thu Oct 17 19:00:47 UTC 2013

Jason Miller <jason at milr.com> wrote:

> On 18:26 Wed 16 Oct     , edgar wrote:
>> Hi all on the LTK list,
>> I'm trying to open a scrolled-canvas widget in the Tk main window
>> and then interactively drawing a line on the canvas (details in the
>> REPL transcripts below), but LTK is throwing nothing but errors at
>> me.
>> The questions are:
>> 1. Am I doing something fundamentally wrong in the examples below?  

> Yes

>> LTK-TEST> (defun ltk-test ()
>>             (with-ltk (:serve-event t)
>>               (let ((sc (make-instance 'scrolled-canvas)))
>>                     (pack sc :expand 1 :fill :both)
>>                     (setf *canvas* (canvas sc)))))
>> LTK-TEST> (ltk-test)
>> ; the Tk window appears on the screen
>> NIL
>> LTK-TEST> (create-line *canvas* '(10 10 20 20))  

> with-ltk is designed for all the ltk-calls to go within it.  It
> dynamically binds ltk::*wish* only for its dynamic extent.  I have no
> idea how the serve-event interactis with dynamic bindings, as I don't
> use it.  But in any event, *wish* will not be bound at your call to
> create-line, so it will fail.
> I would suggest that you not use with-ltk here, but instead run it
> manually: http://www.peter-herth.de/ltk/ltkdoc/node8.html
> you can pass serve-event to mainloop as well to still get that
> functionality.
> so instead your code should look something like:
> (defun ltk-test ()
>  (start-wish)
>  (let ((sc (make-instance 'scrolled-canvas)))
>   (pack sc :expand 1 :fill :both)
>   (setf *canvas* (canvas sc)))
>  (mainloop :serve-event t))

Thank you very much, but:

a) your code is 99% the same code that I alredy wrote in the second
   example of my original mail

b) your code produces _exactly_ the same errors that I got with the
   code from the second example of my original mail

Please don't get me wrong: I'm really thankful for your help, but it
seems as if you haven't read the full text.

Here's the second example again now with your code and the errors:

------------------------- Start of REPL Transcript ---------------------

CL-USER> (defpackage :ltk-test (:use :cl :ltk))

CL-USER> (in-package :ltk-test)

LTK-TEST> (defparameter *canvas* nil)

LTK-TEST> (defun ltk-test ()
            (let ((sc (make-instance 'scrolled-canvas)))
              (pack sc :expand 1 :fill :both)
              (setf *canvas* (canvas sc)))
            (mainloop :serve-event t))

LTK-TEST> (ltk-test)
; the Tk window appears on the screen

LTK-TEST> (create-line *canvas* '(10 10 20 20))
; a line appears on the canvas

LTK-TEST> (setf *exit-mainloop* t)
; the Tk window doesn't disappear from the screen

LTK-TEST> (exit-wish)
; the Tk window disappears from the screen, but:
attempt to THROW to a tag that does not exist:
    :COUNTER 5
    :TEST EQUAL :COUNT 0 {10068F91A3}>)
   [Condition of type SB-INT:SIMPLE-CONTROL-ERROR]

  0: ("no debug information for frame")
  1: (EXIT-WISH) [tl,external]

-------------------------- End of REPL Transcript ----------------------

After (exit-wish) I can restart wish by calling (ltk-test) and it works,
except that I can't close the window from the REPL without getting the
error above, but if I close the Tk window by the window's "close" button
and then call (ltk-test) again, I get the following error:

------------------------- Start of REPL Transcript ---------------------

LTK-TEST> (ltk-test)

There is already an inferior wish.
   [Condition of type LTK::LTK-ERROR]

  0: (LTK::LTK-ERROR "There is already an inferior wish.")
  2: (LTK-TEST)
  4: (EVAL (LTK-TEST))

-------------------------- End of REPL Transcript ----------------------

But there is definitely no wish process in my machine anymore:

bash$ ps ax | grep wish
 6033 pts/0    S+     0:00 grep wish

How can I stop and restart wish with ":serve-event t" from the REPL
without getting errors?

Thank you,

- edgar

More information about the ltk-user mailing list