source: trunk/SRC/ToBeReviewed/WIDGET/COMPOUND_WIDGET/cw_slider_pm.pro @ 163

Last change on this file since 163 was 163, checked in by navarro, 18 years ago

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.3 KB
Line 
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;+
49; @file_comments
50;
51;
52; @categories
53; Compound widget
54;
55; @param VALUE
56; It is the default tick mark value (a floating-point number).
57;
58; @returns
59;
60;
61; @uses
62;
63;
64; @restrictions
65;
66;
67; @examples
68;
69;
70; @history
71;
72;
73; @version
74; $Id$
75;-
76FUNCTION decvalue, value
77;
78  compile_opt idl2, strictarrsubs
79;
80  a = float(value[0])
81  return, strtrim(string(floor(a) + 0.1*indgen(10), format = '(f15.1)'), 2)
82end
83;----------------------------------------------------------------------
84;+
85; @file_comments
86;
87;
88; @categories
89; Compound widget
90;
91; @param VALUE
92; It is the default tick mark value (a floating-point number).
93;
94; @returns
95;
96;
97; @uses
98;
99;
100; @restrictions
101;
102;
103; @examples
104;
105;
106; @history
107;
108;
109; @version
110; $Id$
111;-
112FUNCTION decind, value
113;
114  compile_opt idl2, strictarrsubs
115;
116  a = float(value[0])
117  return, round(10*(a - floor(a))) ; !! computation accuracy
118end
119;----------------------------------------------------------------------
120;+
121; @file_comments
122;
123;
124; @categories
125; Compound widget
126;
127; @param ID
128;
129;
130; @param VALUE
131; It is the default tick mark value (a floating-point number).
132;
133; @returns
134;
135;
136; @uses
137;
138;
139; @restrictions
140;
141;
142; @examples
143;
144;
145; @history
146;
147;
148; @version
149; $Id$
150;-
151PRO cw_slider_pm_set_value, id, value
152;
153  compile_opt idl2, strictarrsubs
154;
155  sbid = widget_info(id, find_by_uname = 'SliderBar')
156  dcid = widget_info(id, find_by_uname = 'decimal')
157  minmax = widget_info(sbid, /SLIDER_MIN_MAX)
158  if size(value, /type) eq 8 then BEGIN ; this is a structure
159    tagnames = tag_names(value)
160    for tag = 0, n_tags(value)-1 do begin
161      case strtrim(strlowcase(tagnames[tag]), 2) of
162        'slider_min':BEGIN
163;          IF float(value.slider_min[0]) LT minmax[1] THEN BEGIN
164            minmax[0] = value.slider_min[0]
165            widget_control, sbid, set_slider_min = floor(float(value.slider_min[0]))
166            valuedc = float(widget_info(dcid, /combobox_gettext))
167            IF valuedc LT value.slider_min THEN BEGIN
168              widget_control, sbid, set_value = floor(float(value.slider_min[0]))
169              widget_control, dcid, set_value = decvalue(value.slider_min)
170              widget_control, dcid, set_combobox_select = decind(value.slider_min)
171            ENDIF
172;          ENDIF
173        end
174        'slider_max':BEGIN
175;          IF float(value.slider_max[0]) GT minmax[0] THEN BEGIN
176            minmax[1] = value.slider_max[0]
177            widget_control, sbid, set_slider_max = ceil(float(value.slider_max[0]))
178            valuedc = float(widget_info(dcid, /combobox_gettext))
179            IF valuedc GT value.slider_max THEN BEGIN
180              widget_control, sbid, set_value = ceil(float(value.slider_max[0]))
181              widget_control, dcid, set_value = decvalue(value.slider_max)
182              widget_control, dcid, set_combobox_select = decind(value.slider_max)
183            ENDIF
184;          ENDIF
185        end
186        'value':IF float(value.value[0]) GE minmax[0] $
187          AND float(value.value[0]) LE minmax[1] THEN value2 = float(value.value[0])
188        ELSE:ras = report('wrong tag name in argument "value" of cw_slider_pm_set_value')
189      endcase
190    endfor
191  ENDIF ELSE BEGIN
192    IF float(value[0]) GE minmax[0] $
193      AND float(value[0]) LE minmax[1] THEN value2 = float(value[0])
194  ENDELSE
195  IF n_elements(value2) NE 0 THEN BEGIN
196    widget_control, sbid, set_value = fix(value2)
197    widget_control, dcid, set_value = decvalue(value2)
198    widget_control, dcid, set_combobox_select = decind(value2)
199  ENDIF
200  return
201end
202;----------------------------------------------------------------------
203;+
204; @file_comments
205;
206;
207; @categories
208; Compound widget
209;
210; @param ID
211;
212;
213; @returns
214;
215;
216; @uses
217;
218;
219; @restrictions
220;
221;
222; @examples
223;
224;
225; @history
226;
227;
228; @version
229; $Id$
230;-
231FUNCTION cw_slider_pm_get_value, id
232;
233  compile_opt idl2, strictarrsubs
234;
235  sbid = widget_info(id, find_by_uname = 'SliderBar')
236  dcid = widget_info(id, find_by_uname = 'decimal')
237  minmax = widget_info(sbid, /SLIDER_MIN_MAX)
238  value = float(widget_info(dcid, /combobox_gettext))
239   return, {value:value, slider_min_max:minmax}
240end
241;----------------------------------------------------------------------
242;+
243; @file_comments
244;
245;
246; @categories
247; Compound widget
248;
249; @param EVENT
250;
251;
252; @returns
253;
254;
255; @uses
256;
257;
258; @restrictions
259;
260;
261; @examples
262;
263;
264; @history
265;
266;
267; @version
268; $Id$
269;-
270FUNCTION cw_slider_pm_event, event
271;
272  compile_opt idl2, strictarrsubs
273;
274  widget_control, event.id, get_uvalue = uval
275;
276  sbid = widget_info(event.handler, find_by_uname = 'SliderBar')
277  dcid = widget_info(event.handler, find_by_uname = 'decimal')
278  minmax = widget_info(sbid, /SLIDER_MIN_MAX)
279  IF uval EQ 'decimal' THEN value = float(event.str) $
280  ELSE value = float(widget_info(dcid, /combobox_gettext))
281  out = 0 ; defaut case
282  case uval OF
283    'plus': if (value + 1) LE minmax[1] then value2 = value + 1 ELSE out = 1
284    'minus':if (value - 1) GE minmax[0] then value2 = value - 1 ELSE out = -1
285    'SliderBar':if (event.value + value - floor(value)) LE minmax[1] THEN value2 = event.value + value - floor(value)
286    'decimal':BEGIN
287      CASE 1 OF
288        value GT minmax[1]: value2 = minmax[1]
289        value LT minmax[0]: value2 = minmax[0]
290        ELSE:
291      ENDCASE
292    END
293    ELSE:
294  ENDCASE
295  IF n_elements(value2) NE 0  THEN BEGIN
296    value = value2
297    widget_control, sbid, set_value = floor(value)
298    widget_control, dcid, set_value = decvalue(value)
299    widget_control, dcid, set_combobox_select = decind(value)
300  ENDIF
301  return, {CW_SLIDER_PM, ID:event.handler, TOP:event.top, HANDLER:0L $
302           , VALUE:value, OUT:OUT}
303end
304;----------------------------------------------------------------------
305;------------------------------------------------------------
306;------------------------------------------------------------
307;------------------------------------------------------------
308;+
309;
310; @file_comments
311; Like WIDGET_SLIDER but here, their are 2 buttons + and - to move the widget from +/- 1
312;
313; @categories
314; Compound widget
315;
316; @param PARENT {in}{required}
317; The widget ID of the parent widget.
318;
319; @keyword UVALUE
320; The user value to be associated with the widget.
321;
322; @keyword UNAME
323; The user name to be associated with the widget.
324;
325; @keyword VALUE
326;
327;
328; @keyword MAXIMUM
329;
330;
331; @keyword MINIMUM
332;
333;
334; @keyword STRMINLEN
335;
336;
337; @keyword _EXTRA
338; Used to pass your keywords
339;
340; @returns
341; The returned value of this function is the widget ID of the
342; newly-created animation widget.
343;
344; @restrictions
345;
346;  Widget Events Returned by the CW_SLIDER_PM Widget
347;
348;  Slider widgets generate events when the mouse is used to change
349;  their value. The event structure returned by the WIDGET_EVENT
350;  function is defined by the following statement:
351;
352;  {CW_SLIDER_PM, ID:0L, TOP:0L, HANDLER:0L, VALUE:0L, DRAG:0, OUT:0}
353;
354;  ID is the widget ID of the button generating the event. TOP is the
355;  widget ID of the top level widget containing ID.
356;  HANDLER contains the widget ID of the widget associated with the
357;  handler routine.
358;  VALUE returns the new value of the slider.
359;  DRAG returns integer 1 if the slider event was generated as part of
360;  a drag operation, or zero if the event was generated when the user
361;  had finished positioning the slider. Note that the slider widget
362;  only generates events during the drag operation if the DRAG keyword
363;  is set, and if the application is running under Motif. When the
364;  DRAG keyword is set, the DRAG field can be used to avoid
365;  computationally expensive operations until the user releases the
366;  slider.
367;  OUT:It is an integer which can take 3 values:
368;       1 : If we press + when the index is already at the max
369;       Comment: In this case, the index stay at the max
370;       -1: If we press - when the index is already at the min
371;       Comment: In this case, the index stay at the min
372;       0 : In other cases
373;
374;   Keywords to WIDGET_CONTROL
375;
376;   A number of keywords to the WIDGET_CONTROL procedure affect the
377;   behavior of cw_slider_pm widget: GET_VALUE and SET_VALUE.
378;       1) GET_VALUE
379;   widget_control,wid_id,get_value=resultat
380;   Send back in the result variable a structure of 2 elements whose name
381;   are inspired from keywords we can pass at
382;   widget_control when we use WIDGET_SLIDER:
383;            VALUE:the value setting of the widget
384;            SLIDER_MIN_MAX: a 2 elements array: The minimum and the
385;            maximum value of the range encompassed by the slider
386;       2) SET_VALUE
387;   widget_control,wid_id,set_value=impose
388;   Allows to modify the state of the combobox like we can do it for
389;   WIDGET_COMBOBOX. May impose: 
390;       a) a integer: give the new position of the slider.
391;       b) A structure which can have for elements (from 1 to 3):
392;            VALUE: an integer which give the new position of the slider
393;            SLIDER_MIN:Set to a new minimum value for the specified
394;            slider widget.
395;            SLIDER_MAX:Set to a new minimum value for the specified
396;            slider widget.
397;
398;
399; @examples
400; See the program provided above (testwid and the associated procedure, testwid_event).
401;
402; @history
403; Sebastien Masson (smasson\@lodyc.jussieu.fr)
404;                      5/9/1999
405;
406; @version
407; $Id$
408;
409; @todo
410; seb: documenter
411;
412;-
413;------------------------------------------------------------
414;------------------------------------------------------------
415;------------------------------------------------------------
416FUNCTION cw_slider_pm, parent, MAXIMUM = maximum, MINIMUM = minimum $
417                       , STRMINLEN = strminlen, VALUE = value, UVALUE = uvalue $
418                       , UNAME = uname, title = title, _extra = ex
419;
420  compile_opt idl2, strictarrsubs
421;
422
423  IF (N_PARAMS() NE 1) THEN MESSAGE, 'Incorrect number of arguments'
424  ON_ERROR, 2                   ;return to caller
425;
426  if n_elements(minimum) NE 0 then minimum = floor(minimum) ELSE minimum = 0
427  if n_elements(maximum) NE 0 then maximum = ceil(maximum) ELSE maximum = 100
428  if NOT keyword_set(title) then title = '    '
429;
430; cheking exclusive keywords
431  column = (keyword_set(column)*(1-keyword_set(row))+keyword_set(vertical)) < 1
432  row = keyword_set(row)*(1-keyword_set(column)) +(keyword_set(row) EQ column)
433  if NOT keyword_set(uvalue) then uvalue = ''
434  if NOT keyword_set(uname) then uname = ''
435  base = widget_base(parent $
436                     , EVENT_FUNC = 'cw_slider_pm_event' $
437                     , FUNC_GET_VALUE = 'cw_slider_pm_get_value' $
438                     , PRO_SET_VALUE = 'cw_slider_pm_set_value' $
439                     , space = 0, UVALUE = uvalue, UNAME = uname, _extra = ex)   
440;
441  mlen = (widget_info(base, string_size = 'm'))[0]
442
443  xsize = mlen*strlen(title)
444  dummyid = widget_label(base, value = title, xsize = xsize)
445  dummyid = widget_button(base, value = '-', uvalue = 'minus' $
446                          , yoffset = 15, xsize = 15, ysize = 15)
447  dummyid = widget_button(base, value = '+', uvalue = 'plus' $
448                          , xoffset = 15, yoffset = 15, xsize = 15, ysize = 15)
449  xoff = 30 > xsize
450  lenstr = max(strlen(strtrim([minimum, maximum], 1)))
451  if keyword_set(strminlen) then lenstr = strminlen > lenstr
452;  xsize = 35 + mlen*(lenstr+1)+3*(lenstr lt 4)
453  xsize = 35 + mlen*(lenstr+2)
454  dummyid = widget_combobox(base, value = decvalue(minimum) $
455                            , UVALUE = 'decimal', UNAME = 'decimal' $
456                            , xoffset = xoff, yoffset = 2, xsize = xsize)
457
458  dummyid = widget_slider(base, MAXIMUM = maximum, MINIMUM = minimum, UVALUE = 'SliderBar' $
459                          , UNAME = 'SliderBar', /suppress_value, /drag $
460                          , yoffset = 30, xsize = xoff + xsize)
461;
462  if keyword_set(value) then cw_slider_pm_set_value, base, value
463;
464  return, base
465end
Note: See TracBrowser for help on using the repository browser.