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
RevLine 
[2]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
[226]8;       'slider_min':BEGIN
[2]9;          widget_control, event.id, get_value = value
10;          widget_control, SliderBarId, set_value = {slider_min:value}
11;       END
[226]12;       'slider_max':BEGIN
[2]13;          widget_control, event.id, get_value = value
14;          widget_control, SliderBarId, set_value = {slider_max:value}
15;       END
[226]16;       'slider_value':BEGIN
[2]17;          widget_control, event.id, get_value = value
18;          widget_control, SliderBarId, set_value = value
19;       END
[226]20;       'get':BEGIN
[2]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;----------------------------------------------------------------------
[157]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
[226]59;
[157]60; @uses
[226]61;
[157]62; @restrictions
[226]63;
[157]64; @examples
[226]65;
[157]66; @history
[226]67;
68; @version
[157]69; $Id$
70;-
[69]71FUNCTION decvalue, value
[114]72;
73  compile_opt idl2, strictarrsubs
74;
[69]75  a = float(value[0])
76  return, strtrim(string(floor(a) + 0.1*indgen(10), format = '(f15.1)'), 2)
77end
78;----------------------------------------------------------------------
[157]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
[226]90;
[157]91; @uses
[226]92;
[157]93; @restrictions
[226]94;
[157]95; @examples
[226]96;
[157]97; @history
[226]98;
99; @version
[157]100; $Id$
101;-
[69]102FUNCTION decind, value
[114]103;
104  compile_opt idl2, strictarrsubs
105;
[69]106  a = float(value[0])
107  return, round(10*(a - floor(a))) ; !! computation accuracy
108end
109;----------------------------------------------------------------------
[157]110;+
111; @file_comments
112;
113;
114; @categories
115; Compound widget
[226]116;
[157]117; @param ID
118;
119; @param VALUE
120; It is the default tick mark value (a floating-point number).
121;
122; @returns
[226]123;
[157]124; @uses
[226]125;
[157]126; @restrictions
[226]127;
[157]128; @examples
[226]129;
[157]130; @history
[226]131;
132; @version
[157]133; $Id$
134;-
[2]135PRO cw_slider_pm_set_value, id, value
[114]136;
137  compile_opt idl2, strictarrsubs
138;
[69]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
[226]147;          IF float(value.slider_min[0]) LT minmax[1] THEN BEGIN
[69]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)
[226]155            ENDIF
156;          ENDIF
[69]157        end
158        'slider_max':BEGIN
[226]159;          IF float(value.slider_max[0]) GT minmax[0] THEN BEGIN
[69]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)
[226]167            ENDIF
168;          ENDIF
[69]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
[226]175  ENDIF ELSE BEGIN
[69]176    IF float(value[0]) GE minmax[0] $
177      AND float(value[0]) LE minmax[1] THEN value2 = float(value[0])
178  ENDELSE
[226]179  IF n_elements(value2) NE 0 THEN BEGIN
[69]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)
[226]183  ENDIF
[69]184  return
[2]185end
186;----------------------------------------------------------------------
[157]187;+
188; @file_comments
189;
190;
191; @categories
[226]192; Compound widget
193;
[157]194; @param ID
195;
[226]196; @returns
[157]197;
198; @uses
[226]199;
[157]200; @restrictions
[226]201;
[157]202; @examples
[226]203;
[157]204; @history
[226]205;
206; @version
[157]207; $Id$
208;-
[2]209FUNCTION cw_slider_pm_get_value, id
[114]210;
211  compile_opt idl2, strictarrsubs
212;
[69]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}
[2]218end
219;----------------------------------------------------------------------
[157]220;+
221; @file_comments
222;
223;
224; @categories
225; Compound widget
[226]226;
[157]227; @param EVENT
228;
229; @returns
[226]230;
[157]231; @uses
[226]232;
[157]233; @restrictions
[226]234;
[157]235; @examples
[226]236;
[157]237; @history
[226]238;
239; @version
[157]240; $Id$
241;-
[2]242FUNCTION cw_slider_pm_event, event
[114]243;
244  compile_opt idl2, strictarrsubs
245;
[69]246  widget_control, event.id, get_uvalue = uval
[2]247;
[69]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)
[226]258    'decimal':BEGIN
[69]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}
[2]275end
276;----------------------------------------------------------------------
[150]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
[157]286; Compound widget
[226]287;
[150]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.
[226]293;
[150]294; @keyword UNAME
295; The user name to be associated with the widget.
[226]296;
[150]297; @keyword VALUE
298;
[226]299; @keyword MAXIMUM
[150]300;
301; @keyword MINIMUM
302;
[226]303;
[150]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.
[226]337;  OUT:It is an integer which can take 3 values:
[150]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
[226]350;   Send back in the result variable a structure of 2 elements whose name
351;   are inspired from keywords we can pass at
[163]352;   widget_control when we use WIDGET_SLIDER:
[150]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
[226]358;   Allows to modify the state of the combobox like we can do it for
359;   WIDGET_COMBOBOX. May impose:
[163]360;       a) a integer: give the new position of the slider.
[226]361;       b) A structure which can have for elements (from 1 to 3):
[150]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
[157]373; Sebastien Masson (smasson\@lodyc.jussieu.fr)
[150]374;                      5/9/1999
375;
376; @version
377; $Id$
378;
379; @todo
380; seb: documenter
381;
382;-
383;------------------------------------------------------------
384;------------------------------------------------------------
385;------------------------------------------------------------
[69]386FUNCTION cw_slider_pm, parent, MAXIMUM = maximum, MINIMUM = minimum $
387                       , STRMINLEN = strminlen, VALUE = value, UVALUE = uvalue $
388                       , UNAME = uname, title = title, _extra = ex
[114]389;
390  compile_opt idl2, strictarrsubs
391;
[2]392
[69]393  IF (N_PARAMS() NE 1) THEN MESSAGE, 'Incorrect number of arguments'
394  ON_ERROR, 2                   ;return to caller
[2]395;
[69]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;
[226]400; checking exclusive keywords
[69]401  column = (keyword_set(column)*(1-keyword_set(row))+keyword_set(vertical)) < 1
[226]402  row = keyword_set(row)*(1-keyword_set(column)) +(keyword_set(row) EQ column)
[69]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' $
[226]409                     , space = 0, UVALUE = uvalue, UNAME = uname, _extra = ex)
[2]410;
[69]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)
[2]431;
[69]432  if keyword_set(value) then cw_slider_pm_set_value, base, value
[2]433;
[69]434  return, base
[2]435end
Note: See TracBrowser for help on using the repository browser.