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

Last change on this file since 232 was 232, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

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