Jason Miller jason@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:
- 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> (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)) #<PACKAGE "LTK-TEST">
CL-USER> (in-package :ltk-test) #<PACKAGE "LTK-TEST">
LTK-TEST> (defparameter *canvas* nil) *CANVAS*
LTK-TEST> (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)) LTK-TEST
LTK-TEST> (ltk-test) ; the Tk window appears on the screen NIL
LTK-TEST> (create-line *canvas* '(10 10 20 20)) ; a line appears on the canvas 1
LTK-TEST> (setf *exit-mainloop* t) ; the Tk window doesn't disappear from the screen T
LTK-TEST> (exit-wish) ; the Tk window disappears from the screen, but: attempt to THROW to a tag that does not exist: #S(LTK::LTK-CONNECTION :STREAM NIL :CALLBACKS #<HASH-TABLE :TEST EQUAL :COUNT 0 {10068F9063}> :AFTER-IDS #<HASH-TABLE :TEST EQUAL :COUNT 0 {10068F9103}> :COUNTER 5 :AFTER-COUNTER 1 :EVENT-QUEUE NIL :CALL-WITH-CONDITION-HANDLERS-FUNCTION #<FUNCTION FUNCALL> :INPUT-HANDLER NIL :REMOTEP NIL :OUTPUT-BUFFER NIL :VARIABLES #<HASH-TABLE :TEST EQUAL :COUNT 0 {10068F91A3}>) [Condition of type SB-INT:SIMPLE-CONTROL-ERROR]
Backtrace: 0: ("no debug information for frame") 1: (EXIT-WISH) [tl,external] 2: (SB-INT:SIMPLE-EVAL-IN-LEXENV (EXIT-WISH) #<NULL-LEXENV>) 3: (EVAL (EXIT-WISH))
-------------------------- 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]
Backtrace: 0: (LTK::LTK-ERROR "There is already an inferior wish.") 1: (START-WISH) 2: (LTK-TEST) 3: (SB-INT:SIMPLE-EVAL-IN-LEXENV (LTK-TEST) #<NULL-LEXENV>) 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