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