[plt-scheme] Re: Continuous update sliders ...

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Jul 8 09:53:55 EDT 2008

At Tue, 08 Jul 2008 11:58:42 +0800, kumar wrote:
> My original code doesn't do any display, but behaves in the
> same way the display behaves under DrScheme. (Yes I do
> run it under DrScheme/MrEd). I have an animation going
> in a window that runs on a timer callback. This animation
> freezes during the slider twiddling .. and its not like
> timer callbacks are accumulating in a buffer - no timer
> callbacks get queued up during this period.

I see the problem, now. I'm using Mac OS X, but --- as you said ---
you're running Windows. (Somehow, I thought we were both using Mac OS
X, but I mused have confused this thread with another one.)

You're right that the callback is delayed and timers are disabled while
a slider is moved under Windows. It's possible that this can be
improved, and I'll look into it.

> Can you please describe to me how you run it so I
> can try the same?

The main difference was that I was using Mac OS X. For completeness,
though, I ran your program by

 * adding `(newline)' after each pair of `display' calls;

 * saving the code as "/tmp/f2.ss";

 * changing the first two lines to `#lang scheme/gui' (since I'm using
   v4) and running as `mred /tmp/f2.ss" in a Terminal window.

Alternately, using v3xx, leave the first two lines alone and run as
`mred -r /tmp/f2.ss'.

Below is the other program I tried --- an extension of the one I sent
before. It has a canvas that shows the slider value and a value
incremented by a timer, and the canvas is refreshed when either
changes. When you drag the slider, the timer gets stuck when the slider
isn't being moved. But under Mac OS X, both the slider value and the
timer update as the slider is moved. Under Windows, everything is stuck
while dragging the slider.



  #lang scheme/gui

  (define val 0)
  (define cnt 0)
  (define f (new frame% 
                 [label "Hi"]
                 [width 100]
                 [height 100]))
  (define c (new canvas% 
                 [parent f]
                 [stretchable-width #t]
                 [stretchable-height #t]
                  (lambda (c dc)
                    (send dc draw-text
                          (format "~a ~a" val cnt)
                          0 0))]))
  (new slider% 
       [label #f] [min-value 0] [max-value 100]
       [parent f]
       [callback (lambda (s e)
                   (set! val (send s get-value))
                   (send c refresh))])
  (new timer%
       [notify-callback (lambda args
                          (set! cnt (add1 cnt))
                          (send c refresh))]
       [interval 100]
       [just-once? #f])
  (send f show #t)

Posted on the users mailing list.