[plt-scheme] Re: Continuous update sliders ...
When I run from a Terminal window (and when I insert newlines to flush
the output), then I do see the output from the callback (and the timer)
as I move the slider control.
Are you running the program inside DrScheme? In that case, the output
must be printed by a Scheme thread that is different from the
eventspace of the slider, and so that's why it gets stuck. More
generally, printing output can involve synchronization with other
threads --- so, unfortunately, you have to avoid printouts if you want
to do something interactive with the slider.
Also, I note that timers are not completely normal while a slider
control is grabbed. If you grab the slider control and don't move it,
then everything freezes until you do move it. This, again, is part of
the mismatch in threading models.
Matthew
At Mon, 07 Jul 2008 19:46:31 +0800, kumar wrote:
> The sample program below shows the behaviour I described.
> When you run it, you get a slider window and the console will
> show "timer 1 timer 2 timer 3 ..." as the timer ticks on. When you
> twiddle the slider, the timer outputs will freeze. When you release
> the slider, a whole bunch of "value N value N ..." messages
> will get printed, and the timer will continue from where it left off
> at mouse-down. What I expect is for the timer to continue ticking
> as I twiddle the slider and every time the slider value changes,
> I expect a " value N" on the console.
>
> Thanks for your help on this.
> -Kumar
>
> ;-----------------
> (require (lib "mred.ss" "mred")
> (lib "class.ss"))
>
>
> (define frame-with-slider%
> (class frame% ; The base class is frame%
>
> (super-instantiate ()
> (label "Frame with slider")
> (width 500))
>
> (new slider%
> (label "Twiddle me")
> (min-value 0)
> (max-value 100)
> (init-value 0)
> (parent this)
> (callback (lambda (s e)
> (display " value ") (display (send s get-
> value)))))
>
> (define count 1)
>
> (define (tick)
> (display " timer ")
> (display count)
> (set! count (+ count 1)))
>
> (define timer
> (new timer%
> (interval 500)
> (notify-callback (lambda () (tick)))))
>
> (send this show #t)))
>
>
> (new frame-with-slider%)
> ;-----------------
>
>
>
> On 06 Jul 2008, at 9:05 PM, Matthew Flatt wrote:
>
> > There are some constraints on concurrency during slider movement, at
> > least under Windows and Mac OS X. Other Scheme threads do not run, and
> > it's possible for a slider callback to be suspended (and further
> > slider
> > callbacks and other events to be delayed) if the callback synchronizes
> > with another thread. Those constraints are related to a slight
> > mismatch
> > between PLT Scheme's threading and eventspace model and the underlying
> > GUI toolbox's model.
> >
> > Does your program involve extra threads somehow? Can you create a
> > small
> > example where slider callbacks get stuck?
> >
> > Matthew
> >
> > At Sun, 06 Jul 2008 09:59:16 +0800, kumar wrote:
> >>
> >> I do have the callback function, but here is what happens -
> >>
> >> - Between mouse-down and mouse-up the callback doesn't get invoked
> >> and the main event processing seems to pause.
> >>
> >> - Upon mouse-up, the callback is invoked as many times as, I think,
> >> the value of the slider changed between mouse-down and mouse-up
> >> in one go.
> >>
> >> - Timer events that should have been generated between the mouse-down
> >> and mouse-up don't fire at all. That's how I came to conclude that
> >> the
> >> main event loop is paused.
> >>
> >> Regards
> >> -Kumar
> >>
> >> On 04 Jul 2008, at 8:19 PM, Matthew Flatt wrote:
> >>
> >>> At Fri, 04 Jul 2008 11:23:45 +0800, kumar_lista at mac.com wrote:
> >>>> Hi,
> >>>>
> >>>> I need some help with the slider% class. Much appreciate any tips.
> >>>>
> >>>> The slider% class behaves modally as it stands - i.e. between
> >>>> mouse-down
> >>>> and mouse-up on the slider control, the main event loop does not
> >>>> get
> >>>> to run.
> >>>> How do I configure slider% such that I can twiddle it without
> >>>> pausing
> >>>> the
> >>>> main event loop between mouse-down and mouse-up?
> >>>
> >>> Provide a `callback' argument when creating a `slider%'.
> >>>
> >>> The following example illustrates updating a message field
> >>> interactively based on the value of the slider:
> >>>
> >>> #lang scheme/gui
> >>>
> >>> (define f (new frame% [label "Hi"]))
> >>> (define m (new message% [parent f] [label ""]
> >>> [stretchable-width #t]))
> >>> (new slider%
> >>> [label #f] [min-value 0] [max-value 100]
> >>> [parent f]
> >>> [callback (lambda (s e)
> >>> (send m set-label
> >>> (format "Value is ~s" (send s get-
> >>> value))))])
> >>> (send f show #t)
> >>>
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme