source: trunk/SRC/ToBeReviewed/WIDGET/COMPOUND_WIDGET/cw_calendar.pro @ 271

Last change on this file since 271 was 271, checked in by smasson, 17 years ago

bugfix for interpolation from ORCA2 without mask

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 15.4 KB
Line 
1; IDL> testwid,julday(1,1,1980)+lindgen(100)*5
2;
3; PRO testwid_event, event
4;     ComboboxId = widget_info(event.top,find_by_uname = 'c''est lui')
5;    widget_control, event.id, get_uvalue=uval
6;    if n_elements(uval) EQ 0 then return
7;    case uval of
8;       'done':widget_control, event.top, /destroy
9;       'set':BEGIN
10;          widget_control, event.id, get_value = value
11;          widget_control, ComboboxId, set_value = value
12;       END
13;       'get':BEGIN
14;          widget_control, ComboboxId, get_value = value
15;          help,  value, /struct
16;       END
17;       ELSE:
18;    endcase
19;    return
20; end
21; PRO testwid, calendar, date0, _extra = ex
22;    base=widget_base(/COLUMN)
23; print, 'base=', base
24;    nothing = widget_label(base, value = 'beginning of the test')
25; ;
26;    nothing = cw_calendar(base,calendar, date0, _extra = ex, uname = 'c''est lui', uvalue = 'c''est lui' )
27; print, 'cw_calendar ID =', nothing
28; ;
29;    nothing = widget_label(base, value = 'end of the test')
30;     nothing = widget_text(base, value = string(calendar[0]), uvalue = 'set', /editable)
31;     nothing = widget_button(base, value = 'get', uvalue = 'get')
32;     nothing = widget_button(base, value = 'done', uvalue = 'done')
33;    widget_control, base, /REALIZE
34;    xmanager,'testwid', base
35;    return
36; END
37;
38;
39;+
40;
41; @file_comments
42;
43; @categories
44; Compound widget
45;
46; @param ID
47;
48; @param VALUE
49; It is the default tick mark value (a floating-point number).
50;
51; @returns
52;
53; @uses
54;
55; @restrictions
56;
57; @examples
58;
59; @history
60;
61; @version
62; $Id$
63;-
64;
65PRO cw_calendar_set_value, id, value
66;
67  compile_opt strictarr, strictarrsubs
68;
69@cm_4cal
70
71; get back the calendar and its related informations
72  winfo_id = widget_info(id, find_by_uname = 'infocal')
73  widget_control, winfo_id, get_uvalue = infowid
74  key_caltype = infowid.caltype
75
76; high freqeuncy calendar
77  IF keyword_set(infowid.fakecal) THEN BEGIN
78    value2 = date2jul(long(value)) - infowid.fakecal
79    IF value2 LT n_elements(infowid.calendar) AND value2 GE 0 THEN BEGIN
80      stepid = widget_info(id, find_by_uname = 'step')
81      widget_control, stepid, set_value = {combobox_select:value2}
82      infowid.date = jul2date(value2 + infowid.fakecal)
83      widget_control, winfo_id, set_uvalue = infowid
84    ENDIF
85  ENDIF ELSE BEGIN
86;
87    value = long(value[0])
88; make sure the value correspond
89    value = jul2date(date2jul(value))
90; define year month day
91    year = value/10000l
92    month = (value MOD 10000L)/100L
93    day = value MOD 100L
94; check that the date exists in the calendar
95  if (where(abs(infowid.calendar - julday(month, day, year)) LT 1./86400.))[0] EQ - 1 then return
96; update the value of infocal
97    infowid.date = value
98    widget_control, winfo_id, set_uvalue = infowid
99; update the combobox if needed...
100    possiblecase = ['day', 'month', 'year']
101    for name = 2, 0, -1 do BEGIN
102; call set_cal_combobox with out = 2 to specify that the call is coming
103; from cw_calendar_set_value
104      if widget_info(id, find_by_uname = possiblecase[name]) NE 0 then $
105         set_cal_combobox, {handler:id, out:2}, possiblecase[name], value
106    ENDFOR
107  ENDELSE
108;
109  return
110end
111;----------------------------------------------------------------------
112;+
113; @file_comments
114;
115;
116; @categories
117; Compound widget
118;
119; @param ID
120;
121;
122; @returns
123;
124; @uses
125;
126; @restrictions
127;
128; @examples
129;
130; @history
131;
132; @version
133; $Id$
134;-
135;
136FUNCTION cw_calendar_get_value, id
137;
138  compile_opt strictarr, strictarrsubs
139;
140  winfo_id = widget_info(id, find_by_uname = 'infocal')
141  widget_control, winfo_id, get_uvalue = infowid
142  return, infowid.date
143END
144;----------------------------------------------------------------------
145;+
146; @file_comments
147;
148;
149; @categories
150; Compound widget
151;
152; @param ID
153;
154;
155; @param WINFOID
156;
157;
158; @returns
159;
160; @uses
161;
162; @restrictions
163;
164; @examples
165;
166; @history
167;
168; @version
169; $Id$
170;-
171;
172FUNCTION get_cal_value, id, winfoid
173;
174  compile_opt strictarr, strictarrsubs
175;
176  winfo_id = widget_info(id, find_by_uname = 'infocal')
177  widget_control, winfo_id, get_uvalue = infowid
178  oldate = infowid.date
179;-------------day-----------------
180  wid_id = widget_info(id, find_by_uname = 'day')
181  if wid_id NE 0 then BEGIN
182    widget_control, wid_id, get_value = wid_value
183    date = long(wid_value.combobox_gettext)
184  ENDIF ELSE date = oldate MOD 100L
185;-------------month---------------
186  wid_id = widget_info(id, find_by_uname = 'month')
187  if wid_id NE 0 then BEGIN
188    widget_control, wid_id, get_value = wid_value
189    allmonths = string(format = '(C(CMoA))', 31*(indgen(12)))
190    month = (where(allmonths EQ wid_value.combobox_gettext))[0] + 1
191    date = date + 100L * long(month)
192  ENDIF ELSE date = date + (oldate MOD 10000L)/100L*100L
193;-------------year----------------
194  wid_id = widget_info(id, find_by_uname = 'year')
195  widget_control, wid_id, get_value = wid_value
196  date = date + 10000L * long(wid_value.combobox_gettext)
197;
198  IF arg_present(winfoid) NE 0 THEN BEGIN
199    winfoid = winfo_id
200    infowid.date = date
201    return, infowid
202  ENDIF ELSE return, date
203end
204;----------------------------------------------------------------------
205; redefine the value and index position of the combobox
206;+
207; @file_comments
208;
209;
210; @categories
211; Compound widget
212;
213; @param EVENT
214;
215;
216; @param CASENAME
217;
218;
219; @param DATE0
220;
221;
222; @returns
223;
224; @uses
225;
226; @restrictions
227;
228; @examples
229;
230; @history
231;
232; @version
233; $Id$
234;-
235PRO set_cal_combobox, event, casename, date0
236;
237  compile_opt strictarr, strictarrsubs
238;
239; casename: Which widget shall we move: 'day', 'month' or 'year' ?
240  wid_id = widget_info(event.handler, find_by_uname = casename)
241; we get back the calendar...
242  winfo_id = widget_info(event.handler, find_by_uname = 'infocal')
243  widget_control, winfo_id, get_uvalue = infowid
244  caldat, infowid.calendar, monthcal, daycal, yearcal
245; ... and the current date
246  IF n_elements(date0) EQ 0 then date0 = get_cal_value(event.handler)
247  year0 = date0/10000L
248  month0 = (date0 MOD 10000L)/100L
249  day0 = date0 MOD 100L
250; index of days/months/years according to date0
251  case casename of
252    'day':BEGIN
253; list of days corresponding to month0 and year0
254      index = where(monthcal EQ month0 AND yearcal EQ year0)
255      current = daycal[index]
256    END
257    'month':BEGIN
258; list of months corresponding to year0
259      index = where(yearcal EQ year0)
260      current = monthcal[index]
261; keep only the uniq values
262      indexbis = uniq(current)
263      index = index[indexbis]
264      current = current[indexbis]
265    END
266    'year':BEGIN
267; keep only the uniq years
268      index = uniq(yearcal)
269      current = yearcal[index]
270    END
271  ENDCASE
272; we update the uvalue of the widget
273  widget_control, wid_id, set_uvalue = {name:casename}
274; for event.out = 0, we store the previous position of the combobox to use
275; it as the default position.
276  IF event.out EQ 0 THEN widget_control, wid_id, get_value = oldselect
277; we redefine the new list
278  if casename EQ 'month' then begin
279    widget_control, wid_id, set_value = string(format = '(C(CMoA))', 31*(current-1))
280  ENDIF ELSE BEGIN
281    widget_control, wid_id, set_value = strtrim(current, 1)
282  ENDELSE
283; specify the index position within the new list of values.
284  widget_control, wid_id, get_value = combobox
285  CASE event.out OF
286; -1: we put to the biggest position
287    -1:selected = combobox.combobox_number - 1
288; 0: same as the previous position is the best choice...
289    0:selected = oldselect.combobox_index < (combobox.combobox_number - 1)
290; 1: we put to the smallest position
291    1:selected = 0
292; 2: a new date has been specified...
293    2:BEGIN
294      case casename of
295        'day':selected = (where(current EQ day0))[0]
296        'month':selected = (where(current EQ month0))[0]
297        'year':selected = (where(current EQ year0))[0]
298      ENDCASE
299    END
300  ENDCASE
301  widget_control, wid_id, set_value = {combobox_select:selected}
302; update the date...
303  infowid.date = get_cal_value(event.handler)
304  widget_control, winfo_id, set_uvalue = infowid
305  return
306end
307;----------------------------------------------------------------------
308; move cyclically the calendar to the
309; value 0 if event.out=1 or combobox_number-1 if event.out=-1
310;+
311; @file_comments
312;
313;
314; @categories
315; Compound widget
316;
317; @param EVENT
318;
319;
320; @param CASENAME
321;
322;
323; @returns
324;
325; @uses
326;
327; @restrictions
328;
329; @examples
330;
331; @history
332;
333; @version
334; $Id$
335;-
336PRO move, event, casename
337;
338  compile_opt strictarr, strictarrsubs
339;
340   possiblecase = ['day', 'month', 'year', 'impossiblecase']
341   id = widget_info(event.handler, find_by_uname = casename)
342   widget_control, id, get_value = wvalue
343; we try to move but we are already at the beginning/end of the combobox
344; wvalue.combobox_index EQ (wvalue.combobox_number-1) and event.out EQ 1
345; wvalue.combobox_index EQ 0 and event.out EQ -1 (move is not called when out eq 0)
346   whichcase = (where(possiblecase EQ casename))[0]
347   if wvalue.combobox_index EQ (wvalue.combobox_number-1)*(event.out EQ 1) THEN BEGIN
348      if widget_info(event.handler, find_by_uname = possiblecase[whichcase+1]) EQ 0 then begin
349; it is impossible to move the "next" combobox...
350         widget_control, id, get_value = widvalue
351; we set to "widvalue.combobox_number-1" when event.out EQ -1
352; and to 0 when event.out EQ 1
353         selected = (widvalue.combobox_number-1)*(event.out EQ -1)
354         widget_control, id, set_value = {combobox_select:selected}
355; we call move for the next combobox
356      ENDIF ELSE move, event, possiblecase[whichcase+1]
357; it is possible to move from +/- 1
358   ENDIF ELSE widget_control, id, set_value = {combobox_select:wvalue.combobox_index+event.out}
359   set_cal_combobox, event, possiblecase[whichcase-1]
360   return
361end
362;----------------------------------------------------------------------
363;+
364; @file_comments
365;
366;
367; @categories
368; Compound widget
369;
370; @param EVENT
371;
372;
373; @returns
374;
375; @uses
376;
377; @restrictions
378;
379; @examples
380;
381; @history
382;
383; @version
384; $Id$
385;-
386FUNCTION cw_calendar_event, event
387;
388@cm_4cal
389  compile_opt strictarr, strictarrsubs
390;
391  winfo_id = widget_info(event.handler, find_by_uname = 'infocal')
392  widget_control, winfo_id, get_uvalue = infowid
393  key_caltype = infowid.caltype
394;
395  widget_control, event.id, get_uvalue = uval
396; high frequency calendar
397  IF uval.name EQ 'step' THEN BEGIN
398    infowid.date = jul2date(event.index + infowid.fakecal)
399  ENDIF ELSE BEGIN
400;
401    possiblecase = ['day', 'month', 'year', 'impossiblecase']
402    whichcase = (where(possiblecase EQ uval.name))[0]
403    if event.out NE 0 then BEGIN ; we use the +/- button and we want to go out of the combobox:
404; to index = -1 (event.out=-1) or to index = combobox_number (event.out=1)
405; we try to move the combobox just right, with name: possiblecase[whichcase+1]
406      if widget_info(event.handler, find_by_uname = possiblecase[whichcase+1]) EQ 0 then BEGIN
407; this widget do not exist we set cyclically the current widget to the
408; value 0 if event.out=1 or combobox_number-1 if event.out=-1
409        widget_control, event.id, get_value = widvalue
410        selected = (widvalue.combobox_number-1)*(event.out EQ -1)
411        widget_control, event.id, set_value = {combobox_select:selected}
412      ENDIF ELSE move, event, possiblecase[whichcase+1]
413    ENDIF
414; if we changed month(year), we need to update the day (and month) list
415    if uval.name NE 'day' then begin
416      event.out = 0
417      for name = whichcase-1, 0, -1 do BEGIN
418        if widget_info(event.handler, find_by_uname = possiblecase[name]) NE 0 then $
419           set_cal_combobox, event, possiblecase[name]
420      endfor
421    ENDIF
422; we update the date
423    infowid = get_cal_value(event.handler, winfo_id)
424  ENDELSE
425;
426  widget_control, winfo_id, set_uvalue = infowid
427  return, {CW_CALENDAR, ID:event.handler, TOP:event.top, HANDLER:0L $
428           , VALUE:infowid.date, FAKECAL: infowid.fakecal}
429end
430;----------------------------------------------------------------------
431;----------------------------------------------------------------------
432;+
433; @file_comments
434;
435;
436; @categories
437; Compound widget
438;
439; @param PARENT {in}{required}
440; The widget ID of the parent widget.
441;
442; @param CALENDAR
443;
444;
445; @param JDATE0
446;
447; @keyword CALTYPE
448;
449; @keyword FAKECAL
450;
451;
452; @keyword UVALUE
453;
454; @keyword UNAME
455;
456;
457; @keyword _EXTRA
458; Used to pass keywords
459;
460; @returns
461;
462; @uses
463;
464; @restrictions
465;
466; @examples
467;
468; @history
469;
470; @version
471; $Id$
472;
473; @todo
474; seb
475;
476;-
477;
478FUNCTION cw_calendar, parent, calendar, jdate0, CALTYPE = CALTYPE, FAKECAL = fakecal, UVALUE = uvalue, UNAME = uname, _EXTRA = ex
479;
480@cm_4cal
481;
482  compile_opt strictarr, strictarrsubs
483;
484  if keyword_set(caltype) then key_caltype = caltype
485; months days years found in the calendar
486  caldat, calendar, monthcal, daycal, yearcal, hourcal, mincal, scdcal
487; starting date
488  if n_elements(jdate0) EQ 0 then jdate0 = calendar[0]
489  if (where(calendar EQ jdate0))[0] EQ -1 then jdate0 = calendar[0]
490;
491  caldat, jdate0, month0, day0, year0
492; test the type of calendar
493  if n_elements(calendar) GT 1 then BEGIN
494; each day have the same value
495    if n_elements(uniq(daycal, sort(daycal))) EQ 1 then monthly = 1
496; each month and each day have the same value
497    if keyword_set(monthly) AND n_elements(uniq(monthcal, sort(monthcal))) EQ 1 then yearly = 1
498  endif
499;---------------------------------------------------------------------------------------
500  if NOT keyword_set(uvalue) then uvalue = {dummy:''}
501  if NOT keyword_set(uname) then uname = ''
502  base0 = widget_base(parent, /ROW $
503                      , EVENT_FUNC = 'cw_calendar_event' $
504                      , FUNC_GET_VALUE = 'cw_calendar_get_value' $
505                      , PRO_SET_VALUE = 'cw_calendar_set_value' $
506                      , UVALUE = uvalue, UNAME = uname, space = 0, _extra = ex)
507;
508
509  if n_elements(fakecal) eq 0 then fakecal = 0
510  base = widget_base(base0, space = 0, uname = 'infocal' $
511                     , uvalue = {calendar:calendar, date:jul2date(jdate0), fakecal:fakecal, caltype: key_caltype})
512;
513  IF keyword_set(fakecal) THEN BEGIN
514    cmbbid = cw_combobox_pm(base, UVALUE = {name:'step'}, UNAME = 'step' $
515                            , value = strtrim(indgen(n_elements(calendar)), 1))
516    widget_control, cmbbid, set_value = {combobox_select:(where(calendar EQ jdate0))[0]}
517  ENDIF ELSE BEGIN
518;
519    vallen = widget_info(base, string_size = 'm')
520;-------------day-----------------
521    if NOT keyword_set(monthly)  then begin
522      dayindex = where(monthcal EQ month0 AND yearcal EQ year0)
523      currentday = daycal[dayindex]
524      currentday = strtrim(currentday, 1)
525      cmbbid = cw_combobox_pm(base, UVALUE = {name:'day'}, UNAME = 'day', value = currentday)
526      widget_control, cmbbid, set_value = {combobox_select:(where(long(currentday) EQ day0))[0]}
527    endif
528;-------------month---------------
529    if NOT keyword_set(yearly)  then BEGIN
530      monthindex = where(yearcal EQ year0)
531      currentmonth = long(monthcal[monthindex])
532; we suppress the repeted months
533      monthindexbis = uniq(currentmonth, sort(currentmonth))
534      monthindex = monthindex[monthindexbis]
535      currentmonth = currentmonth[monthindexbis]
536      xoff = (34 + 2*vallen[0])*(1-keyword_set(monthly))
537      cmbbid = cw_combobox_pm(base, UVALUE = {name:'month'}, UNAME = 'month', value = string(format = '(C(CMoA))', 31*(currentmonth-1)), xoffset = xoff)
538      widget_control, cmbbid, set_value = {combobox_select:(where(long(currentmonth) EQ month0))[0]}
539    endif
540;-------------year----------------
541    yearindex = uniq(yearcal, sort(yearcal))
542    currentyear = strtrim(yearcal[yearindex], 1)
543    xoff = (34 + 2*vallen[0])*(1-keyword_set(monthly)) + (33 + 3*vallen[0])*(1-keyword_set(yearly))
544    cmbbid = cw_combobox_pm(base, UVALUE = {name:'year'}, UNAME = 'year', value = currentyear, xoffset = xoff)
545    widget_control, cmbbid, set_value = {combobox_select:(where(long(currentyear) EQ year0))[0]}
546;-----------------------------
547  ENDELSE
548;
549  return, base
550end
Note: See TracBrowser for help on using the repository browser.