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

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

corrections of some misspellings in some *.pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.2 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; @uses
61;
62; @restrictions
63;
64; @examples
65;
66; @history
67;
68; @version
69; $Id$
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; @file_comments
81;
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;-
102FUNCTION decind, value
103;
104  compile_opt idl2, strictarrsubs
105;
106  a = float(value[0])
107  return, round(10*(a - floor(a))) ; !! computation accuracy
108end
109;----------------------------------------------------------------------
110;+
111; @file_comments
112;
113;
114; @categories
115; Compound widget
116;
117; @param ID
118;
119; @param VALUE
120; It is the default tick mark value (a floating-point number).
121;
122; @returns
123;
124; @uses
125;
126; @restrictions
127;
128; @examples
129;
130; @history
131;
132; @version
133; $Id$
134;-
135PRO cw_slider_pm_set_value, id, value
136;
137  compile_opt idl2, strictarrsubs
138;
139  sbid = widget_info(id, find_by_uname = 'SliderBar')
140  dcid = widget_info(id, find_by_uname = 'decimal')
141  minmax = widget_info(sbid, /SLIDER_MIN_MAX)
142  if size(value, /type) eq 8 then BEGIN ; this is a structure
143    tagnames = tag_names(value)
144    for tag = 0, n_tags(value)-1 do begin
145      case strtrim(strlowcase(tagnames[tag]), 2) of
146        'slider_min':BEGIN
147;          IF float(value.slider_min[0]) LT minmax[1] THEN BEGIN
148            minmax[0] = value.slider_min[0]
149            widget_control, sbid, set_slider_min = floor(float(value.slider_min[0]))
150            valuedc = float(widget_info(dcid, /combobox_gettext))
151            IF valuedc LT value.slider_min THEN BEGIN
152              widget_control, sbid, set_value = floor(float(value.slider_min[0]))
153              widget_control, dcid, set_value = decvalue(value.slider_min)
154              widget_control, dcid, set_combobox_select = decind(value.slider_min)
155            ENDIF
156;          ENDIF
157        end
158        'slider_max':BEGIN
159;          IF float(value.slider_max[0]) GT minmax[0] THEN BEGIN
160            minmax[1] = value.slider_max[0]
161            widget_control, sbid, set_slider_max = ceil(float(value.slider_max[0]))
162            valuedc = float(widget_info(dcid, /combobox_gettext))
163            IF valuedc GT value.slider_max THEN BEGIN
164              widget_control, sbid, set_value = ceil(float(value.slider_max[0]))
165              widget_control, dcid, set_value = decvalue(value.slider_max)
166              widget_control, dcid, set_combobox_select = decind(value.slider_max)
167            ENDIF
168;          ENDIF
169        end
170        'value':IF float(value.value[0]) GE minmax[0] $
171          AND float(value.value[0]) LE minmax[1] THEN value2 = float(value.value[0])
172        ELSE:ras = report('wrong tag name in argument "value" of cw_slider_pm_set_value')
173      endcase
174    endfor
175  ENDIF ELSE BEGIN
176    IF float(value[0]) GE minmax[0] $
177      AND float(value[0]) LE minmax[1] THEN value2 = float(value[0])
178  ENDELSE
179  IF n_elements(value2) NE 0 THEN BEGIN
180    widget_control, sbid, set_value = fix(value2)
181    widget_control, dcid, set_value = decvalue(value2)
182    widget_control, dcid, set_combobox_select = decind(value2)
183  ENDIF
184  return
185end
186;----------------------------------------------------------------------
187;+
188; @file_comments
189;
190;
191; @categories
192; Compound widget
193;
194; @param ID
195;
196; @returns
197;
198; @uses
199;
200; @restrictions
201;
202; @examples
203;
204; @history
205;
206; @version
207; $Id$
208;-
209FUNCTION cw_slider_pm_get_value, id
210;
211  compile_opt idl2, strictarrsubs
212;
213  sbid = widget_info(id, find_by_uname = 'SliderBar')
214  dcid = widget_info(id, find_by_uname = 'decimal')
215  minmax = widget_info(sbid, /SLIDER_MIN_MAX)
216  value = float(widget_info(dcid, /combobox_gettext))
217   return, {value:value, slider_min_max:minmax}
218end
219;----------------------------------------------------------------------
220;+
221; @file_comments
222;
223;
224; @categories
225; Compound widget
226;
227; @param EVENT
228;
229; @returns
230;
231; @uses
232;
233; @restrictions
234;
235; @examples
236;
237; @history
238;
239; @version
240; $Id$
241;-
242FUNCTION cw_slider_pm_event, event
243;
244  compile_opt idl2, strictarrsubs
245;
246  widget_control, event.id, get_uvalue = uval
247;
248  sbid = widget_info(event.handler, find_by_uname = 'SliderBar')
249  dcid = widget_info(event.handler, find_by_uname = 'decimal')
250  minmax = widget_info(sbid, /SLIDER_MIN_MAX)
251  IF uval EQ 'decimal' THEN value = float(event.str) $
252  ELSE value = float(widget_info(dcid, /combobox_gettext))
253  out = 0 ; defaut case
254  case uval OF
255    'plus': if (value + 1) LE minmax[1] then value2 = value + 1 ELSE out = 1
256    'minus':if (value - 1) GE minmax[0] then value2 = value - 1 ELSE out = -1
257    'SliderBar':if (event.value + value - floor(value)) LE minmax[1] THEN value2 = event.value + value - floor(value)
258    'decimal':BEGIN
259      CASE 1 OF
260        value GT minmax[1]: value2 = minmax[1]
261        value LT minmax[0]: value2 = minmax[0]
262        ELSE:
263      ENDCASE
264    END
265    ELSE:
266  ENDCASE
267  IF n_elements(value2) NE 0  THEN BEGIN
268    value = value2
269    widget_control, sbid, set_value = floor(value)
270    widget_control, dcid, set_value = decvalue(value)
271    widget_control, dcid, set_combobox_select = decind(value)
272  ENDIF
273  return, {CW_SLIDER_PM, ID:event.handler, TOP:event.top, HANDLER:0L $
274           , VALUE:value, OUT:OUT}
275end
276;----------------------------------------------------------------------
277;------------------------------------------------------------
278;------------------------------------------------------------
279;------------------------------------------------------------
280;+
281;
282; @file_comments
283; Like WIDGET_SLIDER but here, their are 2 buttons + and - to move the widget from +/- 1
284;
285; @categories
286; Compound widget
287;
288; @param PARENT {in}{required}
289; The widget ID of the parent widget.
290;
291; @keyword UVALUE
292; The user value to be associated with the widget.
293;
294; @keyword UNAME
295; The user name to be associated with the widget.
296;
297; @keyword VALUE
298;
299; @keyword MAXIMUM
300;
301; @keyword MINIMUM
302;
303;
304; @keyword STRMINLEN
305;
306;
307; @keyword _EXTRA
308; Used to pass your 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;------------------------------------------------------------
384;------------------------------------------------------------
385;------------------------------------------------------------
386FUNCTION cw_slider_pm, parent, MAXIMUM = maximum, MINIMUM = minimum $
387                       , STRMINLEN = strminlen, VALUE = value, UVALUE = uvalue $
388                       , UNAME = uname, title = title, _extra = ex
389;
390  compile_opt idl2, strictarrsubs
391;
392
393  IF (N_PARAMS() NE 1) THEN MESSAGE, 'Incorrect number of arguments'
394  ON_ERROR, 2                   ;return to caller
395;
396  if n_elements(minimum) NE 0 then minimum = floor(minimum) ELSE minimum = 0
397  if n_elements(maximum) NE 0 then maximum = ceil(maximum) ELSE maximum = 100
398  if NOT keyword_set(title) then title = '    '
399;
400; checking exclusive keywords
401  column = (keyword_set(column)*(1-keyword_set(row))+keyword_set(vertical)) < 1
402  row = keyword_set(row)*(1-keyword_set(column)) +(keyword_set(row) EQ column)
403  if NOT keyword_set(uvalue) then uvalue = ''
404  if NOT keyword_set(uname) then uname = ''
405  base = widget_base(parent $
406                     , EVENT_FUNC = 'cw_slider_pm_event' $
407                     , FUNC_GET_VALUE = 'cw_slider_pm_get_value' $
408                     , PRO_SET_VALUE = 'cw_slider_pm_set_value' $
409                     , space = 0, UVALUE = uvalue, UNAME = uname, _extra = ex)
410;
411  mlen = (widget_info(base, string_size = 'm'))[0]
412
413  xsize = mlen*strlen(title)
414  dummyid = widget_label(base, value = title, xsize = xsize)
415  dummyid = widget_button(base, value = '-', uvalue = 'minus' $
416                          , yoffset = 15, xsize = 15, ysize = 15)
417  dummyid = widget_button(base, value = '+', uvalue = 'plus' $
418                          , xoffset = 15, yoffset = 15, xsize = 15, ysize = 15)
419  xoff = 30 > xsize
420  lenstr = max(strlen(strtrim([minimum, maximum], 1)))
421  if keyword_set(strminlen) then lenstr = strminlen > lenstr
422;  xsize = 35 + mlen*(lenstr+1)+3*(lenstr lt 4)
423  xsize = 35 + mlen*(lenstr+2)
424  dummyid = widget_combobox(base, value = decvalue(minimum) $
425                            , UVALUE = 'decimal', UNAME = 'decimal' $
426                            , xoffset = xoff, yoffset = 2, xsize = xsize)
427
428  dummyid = widget_slider(base, MAXIMUM = maximum, MINIMUM = minimum, UVALUE = 'SliderBar' $
429                          , UNAME = 'SliderBar', /suppress_value, /drag $
430                          , yoffset = 30, xsize = xoff + xsize)
431;
432  if keyword_set(value) then cw_slider_pm_set_value, base, value
433;
434  return, base
435end
Note: See TracBrowser for help on using the repository browser.