Hi all,<br><br>In the GUI, if the call-chain of on-subwindow-event method calls does not complete without requiring another thread to run, the mouse-event% will not get delivered to the target. And then the target widget of the mouse-event% will not operate the way it should, e.g. a slider% will not slide, a list-box% will not select, etc..<br>
<br>Since printf requires another thread to run, adding calls to printf in on-subwindow-event, or anything on-subwindow-event calls directly, will cause a GUI to break.<br><br>I find printf's invaluable for sanity checks during debugging and so have developed a little wrapper around printf based on a conditional printf trick I saw in the MrEd Designer source. Basically the idea is to put the printf in a thunk that will be executed at a later time, maybe by another thread, and allow the caller (e.g. on-subwindow-event) to complete without requiring another thread.<br>
<br>My questions are these: Is this a safe and practicable approach to use? Am I reinventing something that already exists? Does this need to be generalized in some way to use a different eventspace or something?<br><br>Cheers,<br>
<br>Kieron<br><br>****<br><br>#lang racket/base<br><br>(require racket/gui)<br><br>(define (queued-printf . msg)<br> (let {[print-msg msg]}<br> (queue-callback<br> (lambda () (apply printf print-msg))<br> #t)))<br>
<br>(define f <br> (new<br> (class frame%<br> (super-new)<br> (define/override (on-subwindow-event r e)<br>; (printf "on-subwindow-event: ~a ~a ~n" r (send e get-event-type)) ; un-comment to "break" the GUI<br>
(queued-printf "on-subwindow-event: ~a ~a ~n" r (send e get-event-type))<br>
#f))<br> [label "test queued-printf"]<br> [min-width 400]<br> [min-height 200]<br> ))<br><br>(define lb<br> (new list-box%<br> [parent f]<br> [label "list-box%"]<br> [choices (list "alpha" "bravo" "charlie")]<br>
))<br><br>(send f show #t)<br><br>