1 | ; PRO testwid_event, event |
---|
2 | ; ; help, event, /STRUCT |
---|
3 | ; SliderBarId = widget_info(event.top,find_by_uname = 'c''est lui') |
---|
4 | ; widget_control, event.id, get_uvalue=uval |
---|
5 | ; if n_elements(uval) EQ 0 then return |
---|
6 | ; case uval of |
---|
7 | ; 'done':widget_control, event.top, /destroy |
---|
8 | ; 'slider_min':BEGIN |
---|
9 | ; widget_control, event.id, get_value = value |
---|
10 | ; widget_control, SliderBarId, set_value = {slider_min:value} |
---|
11 | ; END |
---|
12 | ; 'slider_max':BEGIN |
---|
13 | ; widget_control, event.id, get_value = value |
---|
14 | ; widget_control, SliderBarId, set_value = {slider_max:value} |
---|
15 | ; END |
---|
16 | ; 'slider_value':BEGIN |
---|
17 | ; widget_control, event.id, get_value = value |
---|
18 | ; widget_control, SliderBarId, set_value = value |
---|
19 | ; END |
---|
20 | ; 'get':BEGIN |
---|
21 | ; widget_control, SliderBarId, get_value = value |
---|
22 | ; help, value, /struct |
---|
23 | ; print, value.slider_min_max |
---|
24 | ; END |
---|
25 | ; ELSE: |
---|
26 | ; endcase |
---|
27 | ; return |
---|
28 | ; end |
---|
29 | ; PRO testwid, _extra = ex |
---|
30 | ; base=widget_base(/COLUMN) |
---|
31 | ; print, 'base=', base |
---|
32 | ; nothing = widget_label(base, value = 'beginning of the test') |
---|
33 | ; ; |
---|
34 | ; nothing = cw_slider_pm(base, _extra = ex, uname = 'c''est lui', uvalue = 'c''est lui') |
---|
35 | ; print, 'cw_slider_pm ID =', nothing |
---|
36 | ; ; |
---|
37 | ; nothing = widget_label(base, value = 'end of the test') |
---|
38 | ; nothing = widget_text(base, value = '0', uvalue = 'slider_min', /editable) |
---|
39 | ; nothing = widget_text(base, value = '10', uvalue = 'slider_max', /editable) |
---|
40 | ; nothing = widget_text(base, value = '5', uvalue = 'slider_value', /editable) |
---|
41 | ; nothing = widget_button(base, value = 'get', uvalue = 'get') |
---|
42 | ; nothing = widget_button(base, value = 'done', uvalue = 'done') |
---|
43 | ; widget_control, base, /REALIZE |
---|
44 | ; xmanager,'testwid', base |
---|
45 | ; return |
---|
46 | ; end |
---|
47 | ;---------------------------------------------------------------------- |
---|
48 | FUNCTION decvalue, value |
---|
49 | ; |
---|
50 | compile_opt idl2, strictarrsubs |
---|
51 | ; |
---|
52 | a = float(value[0]) |
---|
53 | return, strtrim(string(floor(a) + 0.1*indgen(10), format = '(f15.1)'), 2) |
---|
54 | end |
---|
55 | ;---------------------------------------------------------------------- |
---|
56 | FUNCTION decind, value |
---|
57 | ; |
---|
58 | compile_opt idl2, strictarrsubs |
---|
59 | ; |
---|
60 | a = float(value[0]) |
---|
61 | return, round(10*(a - floor(a))) ; !! computation accuracy |
---|
62 | end |
---|
63 | ;---------------------------------------------------------------------- |
---|
64 | PRO cw_slider_pm_set_value, id, value |
---|
65 | ; |
---|
66 | compile_opt idl2, strictarrsubs |
---|
67 | ; |
---|
68 | sbid = widget_info(id, find_by_uname = 'SliderBar') |
---|
69 | dcid = widget_info(id, find_by_uname = 'decimal') |
---|
70 | minmax = widget_info(sbid, /SLIDER_MIN_MAX) |
---|
71 | if size(value, /type) eq 8 then BEGIN ; this is a structure |
---|
72 | tagnames = tag_names(value) |
---|
73 | for tag = 0, n_tags(value)-1 do begin |
---|
74 | case strtrim(strlowcase(tagnames[tag]), 2) of |
---|
75 | 'slider_min':BEGIN |
---|
76 | ; IF float(value.slider_min[0]) LT minmax[1] THEN BEGIN |
---|
77 | minmax[0] = value.slider_min[0] |
---|
78 | widget_control, sbid, set_slider_min = floor(float(value.slider_min[0])) |
---|
79 | valuedc = float(widget_info(dcid, /combobox_gettext)) |
---|
80 | IF valuedc LT value.slider_min THEN BEGIN |
---|
81 | widget_control, sbid, set_value = floor(float(value.slider_min[0])) |
---|
82 | widget_control, dcid, set_value = decvalue(value.slider_min) |
---|
83 | widget_control, dcid, set_combobox_select = decind(value.slider_min) |
---|
84 | ENDIF |
---|
85 | ; ENDIF |
---|
86 | end |
---|
87 | 'slider_max':BEGIN |
---|
88 | ; IF float(value.slider_max[0]) GT minmax[0] THEN BEGIN |
---|
89 | minmax[1] = value.slider_max[0] |
---|
90 | widget_control, sbid, set_slider_max = ceil(float(value.slider_max[0])) |
---|
91 | valuedc = float(widget_info(dcid, /combobox_gettext)) |
---|
92 | IF valuedc GT value.slider_max THEN BEGIN |
---|
93 | widget_control, sbid, set_value = ceil(float(value.slider_max[0])) |
---|
94 | widget_control, dcid, set_value = decvalue(value.slider_max) |
---|
95 | widget_control, dcid, set_combobox_select = decind(value.slider_max) |
---|
96 | ENDIF |
---|
97 | ; ENDIF |
---|
98 | end |
---|
99 | 'value':IF float(value.value[0]) GE minmax[0] $ |
---|
100 | AND float(value.value[0]) LE minmax[1] THEN value2 = float(value.value[0]) |
---|
101 | ELSE:ras = report('wrong tag name in argument "value" of cw_slider_pm_set_value') |
---|
102 | endcase |
---|
103 | endfor |
---|
104 | ENDIF ELSE BEGIN |
---|
105 | IF float(value[0]) GE minmax[0] $ |
---|
106 | AND float(value[0]) LE minmax[1] THEN value2 = float(value[0]) |
---|
107 | ENDELSE |
---|
108 | IF n_elements(value2) NE 0 THEN BEGIN |
---|
109 | widget_control, sbid, set_value = fix(value2) |
---|
110 | widget_control, dcid, set_value = decvalue(value2) |
---|
111 | widget_control, dcid, set_combobox_select = decind(value2) |
---|
112 | ENDIF |
---|
113 | return |
---|
114 | end |
---|
115 | ;---------------------------------------------------------------------- |
---|
116 | FUNCTION cw_slider_pm_get_value, id |
---|
117 | ; |
---|
118 | compile_opt idl2, strictarrsubs |
---|
119 | ; |
---|
120 | sbid = widget_info(id, find_by_uname = 'SliderBar') |
---|
121 | dcid = widget_info(id, find_by_uname = 'decimal') |
---|
122 | minmax = widget_info(sbid, /SLIDER_MIN_MAX) |
---|
123 | value = float(widget_info(dcid, /combobox_gettext)) |
---|
124 | return, {value:value, slider_min_max:minmax} |
---|
125 | end |
---|
126 | ;---------------------------------------------------------------------- |
---|
127 | FUNCTION cw_slider_pm_event, event |
---|
128 | ; |
---|
129 | compile_opt idl2, strictarrsubs |
---|
130 | ; |
---|
131 | widget_control, event.id, get_uvalue = uval |
---|
132 | ; |
---|
133 | sbid = widget_info(event.handler, find_by_uname = 'SliderBar') |
---|
134 | dcid = widget_info(event.handler, find_by_uname = 'decimal') |
---|
135 | minmax = widget_info(sbid, /SLIDER_MIN_MAX) |
---|
136 | IF uval EQ 'decimal' THEN value = float(event.str) $ |
---|
137 | ELSE value = float(widget_info(dcid, /combobox_gettext)) |
---|
138 | out = 0 ; defaut case |
---|
139 | case uval OF |
---|
140 | 'plus': if (value + 1) LE minmax[1] then value2 = value + 1 ELSE out = 1 |
---|
141 | 'minus':if (value - 1) GE minmax[0] then value2 = value - 1 ELSE out = -1 |
---|
142 | 'SliderBar':if (event.value + value - floor(value)) LE minmax[1] THEN value2 = event.value + value - floor(value) |
---|
143 | 'decimal':BEGIN |
---|
144 | CASE 1 OF |
---|
145 | value GT minmax[1]: value2 = minmax[1] |
---|
146 | value LT minmax[0]: value2 = minmax[0] |
---|
147 | ELSE: |
---|
148 | ENDCASE |
---|
149 | END |
---|
150 | ELSE: |
---|
151 | ENDCASE |
---|
152 | IF n_elements(value2) NE 0 THEN BEGIN |
---|
153 | value = value2 |
---|
154 | widget_control, sbid, set_value = floor(value) |
---|
155 | widget_control, dcid, set_value = decvalue(value) |
---|
156 | widget_control, dcid, set_combobox_select = decind(value) |
---|
157 | ENDIF |
---|
158 | return, {CW_SLIDER_PM, ID:event.handler, TOP:event.top, HANDLER:0L $ |
---|
159 | , VALUE:value, OUT:OUT} |
---|
160 | end |
---|
161 | ;---------------------------------------------------------------------- |
---|
162 | ;------------------------------------------------------------ |
---|
163 | ;------------------------------------------------------------ |
---|
164 | ;------------------------------------------------------------ |
---|
165 | ;+ |
---|
166 | ; |
---|
167 | ; @file_comments |
---|
168 | ; Like WIDGET_SLIDER but here, their are 2 buttons + and - to move the widget from +/- 1 |
---|
169 | ; |
---|
170 | ; @categories |
---|
171 | ; compound widget |
---|
172 | ; |
---|
173 | ; @param PARENT {in}{required} |
---|
174 | ; The widget ID of the parent widget. |
---|
175 | ; |
---|
176 | ; @keyword UVALUE |
---|
177 | ; The user value to be associated with the widget. |
---|
178 | ; |
---|
179 | ; @keyword UNAME |
---|
180 | ; The user name to be associated with the widget. |
---|
181 | ; |
---|
182 | ; @keyword VALUE |
---|
183 | ; |
---|
184 | ; |
---|
185 | ; @keyword MAXIMUM |
---|
186 | ; |
---|
187 | ; |
---|
188 | ; @keyword MINIMUM |
---|
189 | ; |
---|
190 | ; |
---|
191 | ; @keyword STRMINLEN |
---|
192 | ; |
---|
193 | ; |
---|
194 | ; @keyword _EXTRA |
---|
195 | ; Used to pass your keywords |
---|
196 | ; |
---|
197 | ; @returns |
---|
198 | ; The returned value of this function is the widget ID of the |
---|
199 | ; newly-created animation widget. |
---|
200 | ; |
---|
201 | ; @restrictions |
---|
202 | ; |
---|
203 | ; Widget Events Returned by the CW_SLIDER_PM Widget |
---|
204 | ; |
---|
205 | ; Slider widgets generate events when the mouse is used to change |
---|
206 | ; their value. The event structure returned by the WIDGET_EVENT |
---|
207 | ; function is defined by the following statement: |
---|
208 | ; |
---|
209 | ; {CW_SLIDER_PM, ID:0L, TOP:0L, HANDLER:0L, VALUE:0L, DRAG:0, OUT:0} |
---|
210 | ; |
---|
211 | ; ID is the widget ID of the button generating the event. TOP is the |
---|
212 | ; widget ID of the top level widget containing ID. |
---|
213 | ; HANDLER contains the widget ID of the widget associated with the |
---|
214 | ; handler routine. |
---|
215 | ; VALUE returns the new value of the slider. |
---|
216 | ; DRAG returns integer 1 if the slider event was generated as part of |
---|
217 | ; a drag operation, or zero if the event was generated when the user |
---|
218 | ; had finished positioning the slider. Note that the slider widget |
---|
219 | ; only generates events during the drag operation if the DRAG keyword |
---|
220 | ; is set, and if the application is running under Motif. When the |
---|
221 | ; DRAG keyword is set, the DRAG field can be used to avoid |
---|
222 | ; computationally expensive operations until the user releases the |
---|
223 | ; slider. |
---|
224 | ; OUT:It is an integer which can take 3 values: |
---|
225 | ; 1 : If we press + when the index is already at the max |
---|
226 | ; Comment: In this case, the index stay at the max |
---|
227 | ; -1: If we press - when the index is already at the min |
---|
228 | ; Comment: In this case, the index stay at the min |
---|
229 | ; 0 : In other cases |
---|
230 | ; |
---|
231 | ; Keywords to WIDGET_CONTROL |
---|
232 | ; |
---|
233 | ; A number of keywords to the WIDGET_CONTROL procedure affect the |
---|
234 | ; behavior of cw_slider_pm widget: GET_VALUE and SET_VALUE. |
---|
235 | ; 1) GET_VALUE |
---|
236 | ; widget_control,wid_id,get_value=resultat |
---|
237 | ; retourne ds la variable resultat une structure de 2 elements dont |
---|
238 | ; les noms sont inspires des mots cles que l''on peut passer a |
---|
239 | ; widget_control qd on utilise WIDGET_SLIDER: |
---|
240 | ; VALUE:the value setting of the widget |
---|
241 | ; SLIDER_MIN_MAX: a 2 elements array: The minimum and the |
---|
242 | ; maximum value of the range encompassed by the slider |
---|
243 | ; 2) SET_VALUE |
---|
244 | ; widget_control,wid_id,set_value=impose |
---|
245 | ; Allows to modify the state of the combobox like we can do it for |
---|
246 | ; WIDGET_COMBOBOX. May impose: |
---|
247 | ; a) un entier: donne la nouvelle position of the slider. |
---|
248 | ; b) A structure which can have for elements (from 1 to 3): |
---|
249 | ; VALUE: an integer which give the new position of the slider |
---|
250 | ; SLIDER_MIN:Set to a new minimum value for the specified |
---|
251 | ; slider widget. |
---|
252 | ; SLIDER_MAX:Set to a new minimum value for the specified |
---|
253 | ; slider widget. |
---|
254 | ; |
---|
255 | ; |
---|
256 | ; @examples |
---|
257 | ; See the program provided above (testwid and the associated procedure, testwid_event). |
---|
258 | ; |
---|
259 | ; @history |
---|
260 | ; Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
261 | ; 5/9/1999 |
---|
262 | ; |
---|
263 | ; @version |
---|
264 | ; $Id$ |
---|
265 | ; |
---|
266 | ; @todo |
---|
267 | ; seb: documenter |
---|
268 | ; |
---|
269 | ;- |
---|
270 | ;------------------------------------------------------------ |
---|
271 | ;------------------------------------------------------------ |
---|
272 | ;------------------------------------------------------------ |
---|
273 | FUNCTION cw_slider_pm, parent, MAXIMUM = maximum, MINIMUM = minimum $ |
---|
274 | , STRMINLEN = strminlen, VALUE = value, UVALUE = uvalue $ |
---|
275 | , UNAME = uname, title = title, _extra = ex |
---|
276 | ; |
---|
277 | compile_opt idl2, strictarrsubs |
---|
278 | ; |
---|
279 | |
---|
280 | IF (N_PARAMS() NE 1) THEN MESSAGE, 'Incorrect number of arguments' |
---|
281 | ON_ERROR, 2 ;return to caller |
---|
282 | ; |
---|
283 | if n_elements(minimum) NE 0 then minimum = floor(minimum) ELSE minimum = 0 |
---|
284 | if n_elements(maximum) NE 0 then maximum = ceil(maximum) ELSE maximum = 100 |
---|
285 | if NOT keyword_set(title) then title = ' ' |
---|
286 | ; |
---|
287 | ; cheking exclusive keywords |
---|
288 | column = (keyword_set(column)*(1-keyword_set(row))+keyword_set(vertical)) < 1 |
---|
289 | row = keyword_set(row)*(1-keyword_set(column)) +(keyword_set(row) EQ column) |
---|
290 | if NOT keyword_set(uvalue) then uvalue = '' |
---|
291 | if NOT keyword_set(uname) then uname = '' |
---|
292 | base = widget_base(parent $ |
---|
293 | , EVENT_FUNC = 'cw_slider_pm_event' $ |
---|
294 | , FUNC_GET_VALUE = 'cw_slider_pm_get_value' $ |
---|
295 | , PRO_SET_VALUE = 'cw_slider_pm_set_value' $ |
---|
296 | , space = 0, UVALUE = uvalue, UNAME = uname, _extra = ex) |
---|
297 | ; |
---|
298 | mlen = (widget_info(base, string_size = 'm'))[0] |
---|
299 | |
---|
300 | xsize = mlen*strlen(title) |
---|
301 | dummyid = widget_label(base, value = title, xsize = xsize) |
---|
302 | dummyid = widget_button(base, value = '-', uvalue = 'minus' $ |
---|
303 | , yoffset = 15, xsize = 15, ysize = 15) |
---|
304 | dummyid = widget_button(base, value = '+', uvalue = 'plus' $ |
---|
305 | , xoffset = 15, yoffset = 15, xsize = 15, ysize = 15) |
---|
306 | xoff = 30 > xsize |
---|
307 | lenstr = max(strlen(strtrim([minimum, maximum], 1))) |
---|
308 | if keyword_set(strminlen) then lenstr = strminlen > lenstr |
---|
309 | ; xsize = 35 + mlen*(lenstr+1)+3*(lenstr lt 4) |
---|
310 | xsize = 35 + mlen*(lenstr+2) |
---|
311 | dummyid = widget_combobox(base, value = decvalue(minimum) $ |
---|
312 | , UVALUE = 'decimal', UNAME = 'decimal' $ |
---|
313 | , xoffset = xoff, yoffset = 2, xsize = xsize) |
---|
314 | |
---|
315 | dummyid = widget_slider(base, MAXIMUM = maximum, MINIMUM = minimum, UVALUE = 'SliderBar' $ |
---|
316 | , UNAME = 'SliderBar', /suppress_value, /drag $ |
---|
317 | , yoffset = 30, xsize = xoff + xsize) |
---|
318 | ; |
---|
319 | if keyword_set(value) then cw_slider_pm_set_value, base, value |
---|
320 | ; |
---|
321 | return, base |
---|
322 | end |
---|