[2] | 1 | ; IDL> testwid,julday(1,1,1980)+lindgen(100)*5 |
---|
| 2 | ; |
---|
| 3 | PRO testwid_event, event |
---|
| 4 | DroplistId = 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, DroplistId, set_value = value |
---|
| 12 | END |
---|
| 13 | 'get':BEGIN |
---|
| 14 | widget_control, DroplistId, 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 | PRO cw_calendar_set_value, id, value |
---|
| 41 | possiblecase = ['day', 'month', 'year', 'century'] |
---|
| 42 | name = 0 |
---|
| 43 | repeat begin |
---|
| 44 | wid_id = widget_info(id,find_by_uname = possiblecase[name]) |
---|
| 45 | name = name+1 |
---|
| 46 | endrep until wid_id NE 0 |
---|
| 47 | widget_control,wid_id, get_uvalue=wid_uvalue |
---|
| 48 | value = long(value[0]) |
---|
| 49 | year = value/10000l & month = (value-year*10000l)/100L & day = value-year*10000l-month*100L |
---|
| 50 | if year EQ 0 then year = -1 & if month EQ 0 then month = 6 & if day EQ 0 then day = 15 |
---|
| 51 | julianvalue = julday(month, day, year) |
---|
| 52 | if (where(wid_uvalue.calendar EQ julianvalue))[0] EQ - 1 then return |
---|
| 53 | for name = 3, 0, -1 do BEGIN |
---|
| 54 | if widget_info(id,find_by_uname = possiblecase[name]) NE 0 then $ |
---|
| 55 | set_droplist, {handler:id, out:2}, possiblecase[name], value |
---|
| 56 | endfor |
---|
| 57 | return |
---|
| 58 | end |
---|
| 59 | ;---------------------------------------------------------------------- |
---|
| 60 | FUNCTION cw_calendar_get_value, id |
---|
| 61 | possiblecase = ['day', 'month', 'year', 'century'] |
---|
| 62 | name = 0 |
---|
| 63 | repeat begin |
---|
| 64 | wid_id = widget_info(id,find_by_uname = possiblecase[name]) |
---|
| 65 | name = name+1 |
---|
| 66 | endrep until wid_id NE 0 |
---|
| 67 | widget_control,wid_id, get_uvalue=wid_uvalue |
---|
| 68 | caldat, wid_uvalue.calendar,monthcal,daycal,yearcal |
---|
| 69 | centurycal = yearcal/100L |
---|
| 70 | if n_elements(centurycal[uniq(centurycal, sort(centurycal))]) NE 1 then $ |
---|
| 71 | yearcal = yearcal-centurycal*100 |
---|
| 72 | droplistname = ['day','month','year','century'] |
---|
| 73 | for name = 0, n_elements(droplistname)-1 do begin |
---|
| 74 | nothing = execute('wid_id = widget_info(id,find_by_uname = '''+droplistname[name]+''')') |
---|
| 75 | if wid_id NE 0 then begin |
---|
| 76 | widget_control,wid_id, get_value=wid_value |
---|
| 77 | widget_control,wid_id, get_uvalue=wid_uvalue |
---|
| 78 | nothing = execute('array = '+droplistname[name]+'cal[wid_uvalue.index]') |
---|
| 79 | nothing = execute(droplistname[name]+' = array[wid_value.droplist_select]') |
---|
| 80 | ENDIF ELSE nothing = execute(droplistname[name]+'= 0') |
---|
| 81 | ENDFOR |
---|
| 82 | return, 10000L*(year+100L*century)+100L*month+day |
---|
| 83 | end |
---|
| 84 | ;---------------------------------------------------------------------- |
---|
| 85 | PRO set_droplist, event, casename, date0 |
---|
| 86 | ; casename: quel est le widget que l''on veut bouger: 'day', 'month', |
---|
| 87 | ; 'year', 'century' ??? |
---|
| 88 | wid_id = widget_info(event.handler,find_by_uname = casename) |
---|
| 89 | possiblecase = ['day', 'month', 'year', 'century'] |
---|
| 90 | whichcase = (where(possiblecase EQ casename))[0] |
---|
| 91 | ; on recupere la uvalue attache au widget et qui nous donne ques sont |
---|
| 92 | ; les 'day', 'month', 'year', 'century' en train d''etre traites et le |
---|
| 93 | ; calendrier |
---|
| 94 | ; on recuper ici le calendrier |
---|
| 95 | widget_control,wid_id, get_uvalue=wid_uvalue |
---|
| 96 | caldat, wid_uvalue.calendar,monthcal,daycal,yearcal |
---|
| 97 | centurycal = yearcal/100 |
---|
| 98 | ; et la date courrante |
---|
| 99 | if n_elements(date0) EQ 0 then date0 = cw_calendar_get_value(event.handler) |
---|
| 100 | year0 = date0/10000l |
---|
| 101 | century0 = year0/100 |
---|
| 102 | month0 = (date0-year0*10000l)/100L |
---|
| 103 | day0 = date0-year0*10000l-month0*100L |
---|
| 104 | if n_elements(centurycal[uniq(centurycal, sort(centurycal))]) NE 1 then BEGIN |
---|
| 105 | yearcal = yearcal-centurycal*100 |
---|
| 106 | year0 = year0 -centurycal*100 |
---|
| 107 | ENDIF |
---|
| 108 | ; index: 'day', 'month', 'year', 'century' possibles pour la date donnee |
---|
| 109 | case casename of |
---|
| 110 | 'day':index = where(monthcal EQ month0 AND yearcal EQ year0 AND centurycal EQ century0) |
---|
| 111 | 'month':index = where(yearcal EQ year0 AND centurycal EQ century0) |
---|
| 112 | 'year':index = where(centurycal EQ century0) |
---|
| 113 | 'century':index = uniq(centurycal, sort(long(centurycal))) |
---|
| 114 | ENDCASE |
---|
| 115 | ; current: liste des mois possibles par ex |
---|
| 116 | nothing = execute('current = '+possiblecase[whichcase]+'cal[index]') |
---|
| 117 | ; supprime les boublons |
---|
| 118 | indexbis = uniq(current, sort(current)) |
---|
| 119 | index = index[indexbis]; |
---|
| 120 | ; nouvelle liste des possibilites offertes par la droplist (par ex |
---|
| 121 | ; liste des mois possibles) |
---|
| 122 | current = current[indexbis] |
---|
| 123 | ; on accualise la uvalue du widget (par ex on met la nouvelle liste de |
---|
| 124 | ; mois possibles) |
---|
| 125 | widget_control, wid_id, set_uvalue = {name:wid_uvalue.name, calendar:wid_uvalue.calendar, index:index} |
---|
| 126 | ;on met en place la nouvelle liste possible |
---|
| 127 | widget_control, wid_id, get_value = oldselect |
---|
| 128 | if casename EQ 'month' then begin |
---|
| 129 | widget_control, wid_id, set_value = string(format='(C(CMoA))',31*(current-1)) |
---|
| 130 | ENDIF ELSE BEGIN |
---|
| 131 | widget_control, wid_id, set_value = strtrim(current, 1) |
---|
| 132 | ENDELSE |
---|
| 133 | ; quel est l''index qu'il faut selectionner parmis la nouvelle liste! |
---|
| 134 | widget_control, wid_id, get_value = droplist |
---|
| 135 | if event.out EQ 2 then BEGIN |
---|
| 136 | nothing = execute('widget_control, wid_id, set_value = {droplist_select:(where(current EQ '+casename+'0))[0]}') |
---|
| 137 | ENDIF ELSE widget_control, wid_id, set_value $ |
---|
| 138 | = {droplist_select:((droplist.droplist_number-1)*(event.out EQ -1)+oldselect.droplist_select*(event.out EQ 0)) < (droplist.droplist_number-1)} |
---|
| 139 | return |
---|
| 140 | end |
---|
| 141 | ;---------------------------------------------------------------------- |
---|
| 142 | PRO move, event, casename |
---|
| 143 | possiblecase = ['day', 'month', 'year', 'century', 'impossiblecase'] |
---|
| 144 | whichcase = (where(possiblecase EQ casename))[0] |
---|
| 145 | id = widget_info(event.handler,find_by_uname = casename) |
---|
| 146 | widget_control, id, get_value=wvalue |
---|
| 147 | if wvalue.droplist_select EQ (wvalue.droplist_number-1)*(event.out EQ 1) THEN BEGIN |
---|
| 148 | if casename EQ 'century' $ |
---|
| 149 | OR widget_info(event.handler,find_by_uname = possiblecase[whichcase+1]) EQ 0 then begin |
---|
| 150 | widget_control, id, get_value=widvalue |
---|
| 151 | widget_control, id, set_value={droplist_select:(widvalue.droplist_number-1)*(event.out EQ -1)} |
---|
| 152 | ENDIF ELSE nothing = execute('move, event,'''+possiblecase[whichcase+1]+'''') |
---|
| 153 | ENDIF ELSE widget_control, id, set_value={droplist_select:wvalue.droplist_select+event.out} |
---|
| 154 | nothing = execute('set_droplist, event,'''+possiblecase[whichcase-1]+'''') |
---|
| 155 | return |
---|
| 156 | end |
---|
| 157 | ;---------------------------------------------------------------------- |
---|
| 158 | FUNCTION cw_calendar_event, event |
---|
| 159 | ;help, /struct, event |
---|
| 160 | widget_control, event.id, get_uvalue=uval |
---|
| 161 | possiblecase = ['day', 'month', 'year', 'century', 'impossiblecase'] |
---|
| 162 | whichcase = (where(possiblecase EQ uval.name))[0] |
---|
| 163 | if event.out NE 0 then BEGIN ; we use the +/- button and we want to go out of the droplist: |
---|
| 164 | ; to index -1 (event.out=-1) or to index droplist_number (event.out=1) |
---|
| 165 | ; we try to move the droplist just right named possiblecase[whichcase+1] |
---|
| 166 | if widget_info(event.handler,find_by_uname = possiblecase[whichcase+1]) EQ 0 then BEGIN |
---|
| 167 | ; this widget do not exist we set cyclicly the current widget to the |
---|
| 168 | ; value 0 if event.out=1 or droplist_number-1 if event.out=-1 |
---|
| 169 | widget_control, event.id, get_value=widvalue |
---|
| 170 | widget_control, event.id, set_value={droplist_select:(widvalue.droplist_number-1)*(event.out EQ -1)} |
---|
| 171 | ENDIF ELSE move, event, possiblecase[whichcase+1] |
---|
| 172 | ENDIF |
---|
| 173 | if uval.name NE 'day' then begin |
---|
| 174 | event.out = 0 |
---|
| 175 | for name = whichcase-1, 0, -1 do begin |
---|
| 176 | if widget_info(event.handler,find_by_uname = possiblecase[name]) NE 0 then $ |
---|
| 177 | set_droplist, event, possiblecase[name] |
---|
| 178 | endfor |
---|
| 179 | endif |
---|
| 180 | return, {CW_CALENDAR, ID:event.handler, TOP:event.top, HANDLER:0L $ |
---|
| 181 | , VALUE:cw_calendar_get_value(event.handler)} |
---|
| 182 | end |
---|
| 183 | ;---------------------------------------------------------------------- |
---|
| 184 | FUNCTION cw_calendar, parent, calendar, date0, UVALUE = uvalue, UNAME = uname, ROW = row, COLUMN = column, _extra = ex |
---|
| 185 | ; cheking for row and column keywords |
---|
| 186 | column = keyword_set(column)*(1-keyword_set(row)) |
---|
| 187 | row = keyword_set(row)*(1-keyword_set(column)) +(keyword_set(row) EQ column) |
---|
| 188 | ; liste des mois, jours annee disponibles ds le calendrier |
---|
| 189 | caldat, calendar,monthcal,daycal,yearcal |
---|
| 190 | centurycal = yearcal/100 |
---|
| 191 | ; date de depart |
---|
| 192 | if n_elements(date0) EQ 0 then date0 = calendar[0] |
---|
| 193 | if (where(calendar EQ date0))[0] EQ -1 then date0 = calendar[0] |
---|
| 194 | caldat, date0,month0,day0,year0 |
---|
| 195 | century0 = year0/100 |
---|
| 196 | ; test du type de calendrier |
---|
| 197 | if n_elements(calendar) GT 1 then begin |
---|
| 198 | if total(daycal eq 15) EQ n_elements(calendar) then monthly = 1 |
---|
| 199 | if total(monthcal EQ 6) EQ n_elements(calendar) then BEGIN & monthly = 1 & yearly = 1 & endif |
---|
| 200 | if total(yearcal EQ 50) EQ n_elements(calendar) then BEGIN & monthly = 1 & yearly = 1 & centuryly = 1 & ENDIF |
---|
| 201 | endif |
---|
| 202 | ;--------------------------------------------------------------------------------------- |
---|
| 203 | if NOT keyword_set(uvalue) then uvalue = '' |
---|
| 204 | if NOT keyword_set(uname) then uname = '' |
---|
| 205 | base = widget_base(parent, ROW = row, COLUMN = column $ |
---|
| 206 | , EVENT_FUNC = 'cw_calendar_event' $ |
---|
| 207 | , FUNC_GET_VALUE='cw_calendar_get_value' $ |
---|
| 208 | , PRO_SET_VALUE='cw_calendar_set_value' $ |
---|
| 209 | , UVALUE = uvalue, UNAME = uname, _extra = ex) |
---|
| 210 | ;-------------day---------------- |
---|
| 211 | if NOT keyword_set(monthly) then begin |
---|
| 212 | dayindex = where(monthcal EQ month0 AND yearcal EQ year0 AND centurycal EQ century0) |
---|
| 213 | currentday = daycal[dayindex] |
---|
| 214 | currentday = string(currentday) |
---|
| 215 | for i = 0, n_elements(currentday)-1 do currentday[i] = strtrim(currentday[i], 1) |
---|
| 216 | rien = cw_droplist_pm(base,UVALUE = {name:'day', calendar:calendar, index:dayindex}, UNAME = 'day', value = currentday) |
---|
| 217 | widget_control, rien, set_value = {droplist_select:(where(long(currentday) EQ day0))[0]} |
---|
| 218 | endif |
---|
| 219 | ;-------------month---------------- |
---|
| 220 | if NOT keyword_set(yearly) then BEGIN |
---|
| 221 | ; les mois du siecle en cours et de l''anne en cours |
---|
| 222 | monthindex = where(yearcal EQ year0 AND centurycal EQ century0) |
---|
| 223 | currentmonth = long(monthcal[monthindex]) |
---|
| 224 | ; on supprime les elements repetes |
---|
| 225 | monthindexbis = uniq(currentmonth, sort(currentmonth)) |
---|
| 226 | monthindex = monthindex[monthindexbis] |
---|
| 227 | currentmonth = currentmonth[monthindexbis] |
---|
| 228 | ; on cree une droplist avec comme valeur tous les mois possibles de |
---|
| 229 | ; l''annee courrante (year0) |
---|
| 230 | ; rien = cw_droplist_pm(base,UVALUE = {name:'month', calendar:calendar, index:monthindex}, UNAME = 'month', value = string(format='(C(CMoA))',31*indgen(12))) |
---|
| 231 | rien = cw_droplist_pm(base,UVALUE = {name:'month', calendar:calendar, index:monthindex}, UNAME = 'month', value = string(format='(C(CMoA))',31*(currentmonth-1))) |
---|
| 232 | ; on possitionne le mois courrant sur le bon mois parmis les mois |
---|
| 233 | ; possibles de l''annee courrante |
---|
| 234 | widget_control, rien, set_value = {droplist_select:(where(long(currentmonth) EQ month0))[0]} |
---|
| 235 | endif |
---|
| 236 | ;-------------year---------------- |
---|
| 237 | if NOT keyword_set(centuryly) then begin |
---|
| 238 | if n_elements(centurycal[uniq(centurycal, sort(centurycal))]) NE 1 then BEGIN |
---|
| 239 | yearcal = yearcal-centurycal*100 |
---|
| 240 | year0 = year0-centurycal*100 |
---|
| 241 | endif |
---|
| 242 | yearindex = where(centurycal EQ century0) |
---|
| 243 | currentyear = yearcal[yearindex] |
---|
| 244 | yearindexbis = uniq(currentyear, sort(long(currentyear))) |
---|
| 245 | yearindex = yearindex[yearindexbis] |
---|
| 246 | currentyear = currentyear[yearindexbis] |
---|
| 247 | currentyear = string(currentyear) |
---|
| 248 | for i = 0, n_elements(currentyear)-1 do currentyear[i] = strtrim(currentyear[i], 1) |
---|
| 249 | rien = cw_droplist_pm(base,UVALUE = {name:'year', calendar:calendar, index:yearindex}, UNAME = 'year', value = currentyear) |
---|
| 250 | widget_control, rien, set_value = {droplist_select:(where(long(currentyear) EQ year0))[0]} |
---|
| 251 | endif |
---|
| 252 | ;-------------century---------------- |
---|
| 253 | centuryindex = uniq(centurycal, sort(long(centurycal))) |
---|
| 254 | currentcentury = centurycal[centuryindex] |
---|
| 255 | currentcentury = string(currentcentury) |
---|
| 256 | for i = 0, n_elements(currentcentury)-1 do currentcentury[i] = strtrim(currentcentury[i], 1) |
---|
| 257 | if n_elements(uniq(centurycal, sort(centurycal))) NE 1 then BEGIN |
---|
| 258 | rien = cw_droplist_pm(base,UVALUE = {name:'century', calendar:calendar, index:centuryindex}, UNAME = 'century', value = currentcentury) |
---|
| 259 | widget_control, rien, set_value = {droplist_select:(where(long(currentcentury) EQ century0))[0]} |
---|
| 260 | endif |
---|
| 261 | ;----------------------------- |
---|
| 262 | ; |
---|
| 263 | ; |
---|
| 264 | return, base |
---|
| 265 | end |
---|