#lang racket<br>#|Hello all, I&#39;m  PMah. |#<br>(require racket/gui/base)<br><br>#|Problem: I have a message% control called x-pos parented by a frame% called parent1. I have a canvas% called canvas parented under frame% parent2. I would like x-pos to always show the current x coordinate of the mouse position over canvas, and for this to be kept up to date as the mouse moves. Ultimately I&#39;d love to move to a reactive semantics. |#<br>
 <br><br>#|Setting up the first frame and parent. I&#39;m also going to grab the eventspace for this frame while I&#39;m at it.|#<br>(define parent1 (new frame% <br>                              [label &quot;Parent1&quot;]<br>
                              [width 200]<br>                              [height 200]<br>                              [enabled #t]))<br><br>(define x-pos (new message% <br>                   [parent parent1]<br>                   [label &quot;No x-pos yet.&quot;]))<br>
<br>(send parent1 show #t)<br><br>(define eventspace1 (send parent1 get-eventspace))<br><br><br>#|The second eventspace*frame*pos combo-|#<br>(define parent2 (new frame% <br>                              [label &quot;Parent2&quot;]<br>
                              [width 200]<br>                              [height 200]<br>                              [enabled #t]))<br><br><br>#|Here comes the canvas subclass-I&#39;m looking to override on-event method to grab the x-component of the mouse pos, and I want to have that constantly updating the x-pos message%. I really want reactive behavior, but I ran into some issues with the frtime-namely, differences in bindings due to the mzscheme bindings. the require spec (prefix-in ..) doesn&#39;t appear to be in the language. I&#39;m probably doing something wrong. |#<br>
(define y-pos (class canvas%<br>    <br>    (inherit get-dc)<br>#|My notion of scope in objects is not precise. With those defines within the scope of the on-event bindings, do the defines recalculate each time on-event receives a message? lo, I wish I had some sort of channel protocol to pass messages between threads, along with control. <br>
The mushrooms kick in now.<br>PFFFT MIND<br>|#<br>    (define/override (on-event mouse-event)<br>      (define min-x (dc:min-x (get-dc)))<br>      (define max-x (dc:max-x (get-dc)))<br>      (define min-y (dc:min-y (get-dc)))<br>
      (define max-y (dc:max-y (get-dc)))<br>      (define x-pos (send mouse-event get-x))<br>      (define y-pos (send mouse-event get-y))<br>      (call-in-other-eventspace (make-eventspace) (draw-diagnostics max-x max-y x-pos y-pos)))<br>
    <br>    (super-new)))<br><br>(define <br>(send parent2 show #t)<br><br>  <br>#|I have tried some of the examples on <a href="http://groups.google.com/group/plt-scheme/browse_thread/thread/28af25a01200bc3c/7937bb0314cc231e?lnk=raot">http://groups.google.com/group/plt-scheme/browse_thread/thread/28af25a01200bc3c/7937bb0314cc231e?lnk=raot</a>   <br>
Basically, one using a channel, probably incorrectly and the second without. Now what I believe I&#39;ve done is to add the thunk to the queue in the frame% parent1&#39;s eventspace, but I haven&#39;t transferred control. The other eventspace&#39;s thread still has control. Kind of?<br>
|#<br>(define (call-in-other-eventspace e thunk)<br>   (let ([ch (make-channel)])<br>     (parameterize ([current-eventspace e])<br>       (queue-callback (lambda ()<br>                         (channel-put ch (thunk)))))<br>
     (channel-get ch))) <br>  #|This blocks both frames updating in some way-im not able to transfer control smoothly to the thread in the message% message1 workspace, and so the x-pos label updates only sporadically when the other eventspace thread yields? |#<br>
(define (call-in-other-eventspace e thunk)<br>   (parameterize ([current-eventspace e])<br>       (queue-callback thunk))) <br>  <br>  <br>#|How can I get x-pos to update automatically on each on-event send here? (draw-diagnostics max-x max-y x-pos y-pos) appears to terminate here in all cases. Part 2: how can I apply frtime to make the update relationship I want between canvas mouse position and message text  (or other racket reactive work if it exists.). I really would like to understand this idiom and get it in my toolchest for gui programming. Thanks all! Racket is an impressive contribution to computer science. |#<br>
  <br>  <br><br>