; IDL> testwid,julday(1,1,1980)+lindgen(100)*5 ; PRO testwid_event, event DroplistId = widget_info(event.top,find_by_uname = 'c''est lui') widget_control, event.id, get_uvalue=uval if n_elements(uval) EQ 0 then return case uval of 'done':widget_control, event.top, /destroy 'set':BEGIN widget_control, event.id, get_value = value widget_control, DroplistId, set_value = value END 'get':BEGIN widget_control, DroplistId, get_value = value help, value, /struct END ELSE: endcase return end PRO testwid, calendar, date0, _extra = ex base=widget_base(/COLUMN) print, 'base=', base nothing = widget_label(base, value = 'beginning of the test') ; nothing = cw_calendar(base,calendar, date0, _extra = ex, uname = 'c''est lui', uvalue = 'c''est lui' ) print, 'cw_calendar ID =', nothing ; nothing = widget_label(base, value = 'end of the test') nothing = widget_text(base, value = string(calendar[0]), uvalue = 'set', /editable) nothing = widget_button(base, value = 'get', uvalue = 'get') nothing = widget_button(base, value = 'done', uvalue = 'done') widget_control, base, /REALIZE xmanager,'testwid', base return END ; ; ; PRO cw_calendar_set_value, id, value possiblecase = ['day', 'month', 'year', 'century'] name = 0 repeat begin wid_id = widget_info(id,find_by_uname = possiblecase[name]) name = name+1 endrep until wid_id NE 0 widget_control,wid_id, get_uvalue=wid_uvalue value = long(value[0]) year = value/10000l & month = (value-year*10000l)/100L & day = value-year*10000l-month*100L if year EQ 0 then year = -1 & if month EQ 0 then month = 6 & if day EQ 0 then day = 15 julianvalue = julday(month, day, year) if (where(wid_uvalue.calendar EQ julianvalue))[0] EQ - 1 then return for name = 3, 0, -1 do BEGIN if widget_info(id,find_by_uname = possiblecase[name]) NE 0 then $ set_droplist, {handler:id, out:2}, possiblecase[name], value endfor return end ;---------------------------------------------------------------------- FUNCTION cw_calendar_get_value, id possiblecase = ['day', 'month', 'year', 'century'] name = 0 repeat begin wid_id = widget_info(id,find_by_uname = possiblecase[name]) name = name+1 endrep until wid_id NE 0 widget_control,wid_id, get_uvalue=wid_uvalue caldat, wid_uvalue.calendar,monthcal,daycal,yearcal centurycal = yearcal/100L if n_elements(centurycal[uniq(centurycal, sort(centurycal))]) NE 1 then $ yearcal = yearcal-centurycal*100 droplistname = ['day','month','year','century'] for name = 0, n_elements(droplistname)-1 do begin nothing = execute('wid_id = widget_info(id,find_by_uname = '''+droplistname[name]+''')') if wid_id NE 0 then begin widget_control,wid_id, get_value=wid_value widget_control,wid_id, get_uvalue=wid_uvalue nothing = execute('array = '+droplistname[name]+'cal[wid_uvalue.index]') nothing = execute(droplistname[name]+' = array[wid_value.droplist_select]') ENDIF ELSE nothing = execute(droplistname[name]+'= 0') ENDFOR return, 10000L*(year+100L*century)+100L*month+day end ;---------------------------------------------------------------------- PRO set_droplist, event, casename, date0 ; casename: quel est le widget que l''on veut bouger: 'day', 'month', ; 'year', 'century' ??? wid_id = widget_info(event.handler,find_by_uname = casename) possiblecase = ['day', 'month', 'year', 'century'] whichcase = (where(possiblecase EQ casename))[0] ; on recupere la uvalue attache au widget et qui nous donne ques sont ; les 'day', 'month', 'year', 'century' en train d''etre traites et le ; calendrier ; on recuper ici le calendrier widget_control,wid_id, get_uvalue=wid_uvalue caldat, wid_uvalue.calendar,monthcal,daycal,yearcal centurycal = yearcal/100 ; et la date courrante if n_elements(date0) EQ 0 then date0 = cw_calendar_get_value(event.handler) year0 = date0/10000l century0 = year0/100 month0 = (date0-year0*10000l)/100L day0 = date0-year0*10000l-month0*100L if n_elements(centurycal[uniq(centurycal, sort(centurycal))]) NE 1 then BEGIN yearcal = yearcal-centurycal*100 year0 = year0 -centurycal*100 ENDIF ; index: 'day', 'month', 'year', 'century' possibles pour la date donnee case casename of 'day':index = where(monthcal EQ month0 AND yearcal EQ year0 AND centurycal EQ century0) 'month':index = where(yearcal EQ year0 AND centurycal EQ century0) 'year':index = where(centurycal EQ century0) 'century':index = uniq(centurycal, sort(long(centurycal))) ENDCASE ; current: liste des mois possibles par ex nothing = execute('current = '+possiblecase[whichcase]+'cal[index]') ; supprime les boublons indexbis = uniq(current, sort(current)) index = index[indexbis]; ; nouvelle liste des possibilites offertes par la droplist (par ex ; liste des mois possibles) current = current[indexbis] ; on accualise la uvalue du widget (par ex on met la nouvelle liste de ; mois possibles) widget_control, wid_id, set_uvalue = {name:wid_uvalue.name, calendar:wid_uvalue.calendar, index:index} ;on met en place la nouvelle liste possible widget_control, wid_id, get_value = oldselect if casename EQ 'month' then begin widget_control, wid_id, set_value = string(format='(C(CMoA))',31*(current-1)) ENDIF ELSE BEGIN widget_control, wid_id, set_value = strtrim(current, 1) ENDELSE ; quel est l''index qu'il faut selectionner parmis la nouvelle liste! widget_control, wid_id, get_value = droplist if event.out EQ 2 then BEGIN nothing = execute('widget_control, wid_id, set_value = {droplist_select:(where(current EQ '+casename+'0))[0]}') ENDIF ELSE widget_control, wid_id, set_value $ = {droplist_select:((droplist.droplist_number-1)*(event.out EQ -1)+oldselect.droplist_select*(event.out EQ 0)) < (droplist.droplist_number-1)} return end ;---------------------------------------------------------------------- PRO move, event, casename possiblecase = ['day', 'month', 'year', 'century', 'impossiblecase'] whichcase = (where(possiblecase EQ casename))[0] id = widget_info(event.handler,find_by_uname = casename) widget_control, id, get_value=wvalue if wvalue.droplist_select EQ (wvalue.droplist_number-1)*(event.out EQ 1) THEN BEGIN if casename EQ 'century' $ OR widget_info(event.handler,find_by_uname = possiblecase[whichcase+1]) EQ 0 then begin widget_control, id, get_value=widvalue widget_control, id, set_value={droplist_select:(widvalue.droplist_number-1)*(event.out EQ -1)} ENDIF ELSE nothing = execute('move, event,'''+possiblecase[whichcase+1]+'''') ENDIF ELSE widget_control, id, set_value={droplist_select:wvalue.droplist_select+event.out} nothing = execute('set_droplist, event,'''+possiblecase[whichcase-1]+'''') return end ;---------------------------------------------------------------------- FUNCTION cw_calendar_event, event ;help, /struct, event widget_control, event.id, get_uvalue=uval possiblecase = ['day', 'month', 'year', 'century', 'impossiblecase'] whichcase = (where(possiblecase EQ uval.name))[0] if event.out NE 0 then BEGIN ; we use the +/- button and we want to go out of the droplist: ; to index -1 (event.out=-1) or to index droplist_number (event.out=1) ; we try to move the droplist just right named possiblecase[whichcase+1] if widget_info(event.handler,find_by_uname = possiblecase[whichcase+1]) EQ 0 then BEGIN ; this widget do not exist we set cyclicly the current widget to the ; value 0 if event.out=1 or droplist_number-1 if event.out=-1 widget_control, event.id, get_value=widvalue widget_control, event.id, set_value={droplist_select:(widvalue.droplist_number-1)*(event.out EQ -1)} ENDIF ELSE move, event, possiblecase[whichcase+1] ENDIF if uval.name NE 'day' then begin event.out = 0 for name = whichcase-1, 0, -1 do begin if widget_info(event.handler,find_by_uname = possiblecase[name]) NE 0 then $ set_droplist, event, possiblecase[name] endfor endif return, {CW_CALENDAR, ID:event.handler, TOP:event.top, HANDLER:0L $ , VALUE:cw_calendar_get_value(event.handler)} end ;---------------------------------------------------------------------- FUNCTION cw_calendar, parent, calendar, date0, UVALUE = uvalue, UNAME = uname, ROW = row, COLUMN = column, _extra = ex ; cheking for row and column keywords column = keyword_set(column)*(1-keyword_set(row)) row = keyword_set(row)*(1-keyword_set(column)) +(keyword_set(row) EQ column) ; liste des mois, jours annee disponibles ds le calendrier caldat, calendar,monthcal,daycal,yearcal centurycal = yearcal/100 ; date de depart if n_elements(date0) EQ 0 then date0 = calendar[0] if (where(calendar EQ date0))[0] EQ -1 then date0 = calendar[0] caldat, date0,month0,day0,year0 century0 = year0/100 ; test du type de calendrier if n_elements(calendar) GT 1 then begin if total(daycal eq 15) EQ n_elements(calendar) then monthly = 1 if total(monthcal EQ 6) EQ n_elements(calendar) then BEGIN & monthly = 1 & yearly = 1 & endif if total(yearcal EQ 50) EQ n_elements(calendar) then BEGIN & monthly = 1 & yearly = 1 & centuryly = 1 & ENDIF endif ;--------------------------------------------------------------------------------------- if NOT keyword_set(uvalue) then uvalue = '' if NOT keyword_set(uname) then uname = '' base = widget_base(parent, ROW = row, COLUMN = column $ , EVENT_FUNC = 'cw_calendar_event' $ , FUNC_GET_VALUE='cw_calendar_get_value' $ , PRO_SET_VALUE='cw_calendar_set_value' $ , UVALUE = uvalue, UNAME = uname, _extra = ex) ;-------------day---------------- if NOT keyword_set(monthly) then begin dayindex = where(monthcal EQ month0 AND yearcal EQ year0 AND centurycal EQ century0) currentday = daycal[dayindex] currentday = string(currentday) for i = 0, n_elements(currentday)-1 do currentday[i] = strtrim(currentday[i], 1) rien = cw_droplist_pm(base,UVALUE = {name:'day', calendar:calendar, index:dayindex}, UNAME = 'day', value = currentday) widget_control, rien, set_value = {droplist_select:(where(long(currentday) EQ day0))[0]} endif ;-------------month---------------- if NOT keyword_set(yearly) then BEGIN ; les mois du siecle en cours et de l''anne en cours monthindex = where(yearcal EQ year0 AND centurycal EQ century0) currentmonth = long(monthcal[monthindex]) ; on supprime les elements repetes monthindexbis = uniq(currentmonth, sort(currentmonth)) monthindex = monthindex[monthindexbis] currentmonth = currentmonth[monthindexbis] ; on cree une droplist avec comme valeur tous les mois possibles de ; l''annee courrante (year0) ; rien = cw_droplist_pm(base,UVALUE = {name:'month', calendar:calendar, index:monthindex}, UNAME = 'month', value = string(format='(C(CMoA))',31*indgen(12))) rien = cw_droplist_pm(base,UVALUE = {name:'month', calendar:calendar, index:monthindex}, UNAME = 'month', value = string(format='(C(CMoA))',31*(currentmonth-1))) ; on possitionne le mois courrant sur le bon mois parmis les mois ; possibles de l''annee courrante widget_control, rien, set_value = {droplist_select:(where(long(currentmonth) EQ month0))[0]} endif ;-------------year---------------- if NOT keyword_set(centuryly) then begin if n_elements(centurycal[uniq(centurycal, sort(centurycal))]) NE 1 then BEGIN yearcal = yearcal-centurycal*100 year0 = year0-centurycal*100 endif yearindex = where(centurycal EQ century0) currentyear = yearcal[yearindex] yearindexbis = uniq(currentyear, sort(long(currentyear))) yearindex = yearindex[yearindexbis] currentyear = currentyear[yearindexbis] currentyear = string(currentyear) for i = 0, n_elements(currentyear)-1 do currentyear[i] = strtrim(currentyear[i], 1) rien = cw_droplist_pm(base,UVALUE = {name:'year', calendar:calendar, index:yearindex}, UNAME = 'year', value = currentyear) widget_control, rien, set_value = {droplist_select:(where(long(currentyear) EQ year0))[0]} endif ;-------------century---------------- centuryindex = uniq(centurycal, sort(long(centurycal))) currentcentury = centurycal[centuryindex] currentcentury = string(currentcentury) for i = 0, n_elements(currentcentury)-1 do currentcentury[i] = strtrim(currentcentury[i], 1) if n_elements(uniq(centurycal, sort(centurycal))) NE 1 then BEGIN rien = cw_droplist_pm(base,UVALUE = {name:'century', calendar:calendar, index:centuryindex}, UNAME = 'century', value = currentcentury) widget_control, rien, set_value = {droplist_select:(where(long(currentcentury) EQ century0))[0]} endif ;----------------------------- ; ; return, base end