Re: widget_slider with odd integers [message #31515] |
Mon, 22 July 2002 12:41 |
Daniel Peduzzi
Messages: 29 Registered: June 1999
|
Junior Member |
|
|
Thierry Savin wrote in message <3D3C4643.1080709@mit.edu>...
> Hi all,
>
>
> Does anyone know how I could create a slider widget that produces only
> odd integers ?
>
If you are on a UNIX system, you could create a slider like this:
sliderID = widget_slider(base, value=some_odd_value, /drag, event_pro='slider_event')
which will cause the "slider_event" callback to be invoked whenever the
slider is dragged.
Then in your callback:
pro slider_event, event
my_odd_value= event.value / 2 * 2 + 1
widget_control, event.id, set_value=my_odd_value
return
end
This doesn't work *quite* as nicely under Windows, since drag events are
not generated...but the value will still jump to an odd value when the
thumbnail is "dropped."
Note: be careful of the maximum slider value (for example, trying to set
a slider with a max of 100 to the value 101 will result in a value of 100.)
Dan
---------------------------------------
Daniel C. Peduzzi
peduzzi@attbi.com
---------------------------------------
|
|
|
Re: widget_slider with odd integers [message #31517 is a reply to message #31515] |
Mon, 22 July 2002 11:46  |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Mon, 22 Jul 2002 10:52:03 -0700, Thierry Savin wrote:
> Hi all,
>
>
> Does anyone know how I could create a slider widget that produces only
> odd integers ?
>
Use /SUPPRESS_VALUE, and compute in your event callback:
my_odd_value=2*ev.value+1
for use as the real value for display in a suitably located widget_label,
and for whatever data context you intend. You can of course extend this
same method to do all manner of interesting things, like create floating
sliders (though many already exist in libraries), or non-linear sliders.
Good luck,
JD
|
|
|