1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
| #######################################
# The main script
#######################################
_y,_m,_d = time.date
_prev_firstweekday = _firstweekday
my_font = "Sans bold 15"
my_col = "#000000" #black
dow_font = "Sans bold 10"
dow_col = "#000000" #black
main_font = "Sans bold 10"
task_font = "Sans 10"
main_font_col = "#000000" #black
task_col = "#000000" #black
cal_date_col = "#000000" #black
day_font = "Sans 10"
today_col = "#FF0000" #red
ev_col = "#0000FF" #blue
sc_behavior = "double"
date_format = "%d/%m"
ev_desc = ""
ev_st_tm_h = 12
ev_st_tm_m = 00
ev_en_tm_h = 12
ev_en_tm_m = 00
ev_yr = _y
ev_mon = `_m`
ev_day = _d
add_ev_button = False
del_ev_button = False
show_ev_listings = True
ev_list = []
del_ev = ""
ev_day_list_this_month = get_config("WeeklyCalendar_ev_day_list", [])
if ev_day_list_this_month == []:
ev_day_list_this_month = [ False for a in range(Dsp.cal_array.length) ]
num_evs = 0
# This is for traversing through months
# so it doesn't take 5 minutes each push =)
next_month_mx = []
prev_month_mx = []
# This gets called every date change (and once upon initialization)
def do_date(value):
global ev_list, num_evs, ev_yr, ev_mon, ev_day
new_ev_list = []
y, m, d = value
#print "In do_date %s/%s/%s" % (d, m, y)
ev_yr = y
ev_mon = `m`
ev_day = d
ev_list = get_config("WeeklyCalendar_event_list", [])
num_evs = get_config("WeeklyCalendar_num_evs", 0)
prefs_update_side_label("date_format", date_format)
for element in ev_list:
(st_yr, st_mon, st_dy, st_h, st_m, st_s), (en_yr, en_mon, en_dy, en_h, en_m, en_s), summary, rrule = element
if en_yr < y or en_mon < m or (en_mon == m and en_dy < d):
#print "--Deleting %s--" % summary
num_evs -= 1
else:
new_ev_list.append(element)
ev_list = new_ev_list
set_config("WeeklyCalendar_num_evs", num_evs)
set_config("WeeklyCalendar_event_list", ev_list)
update_ev_day_list(value)
update_display(d, cal.day, m, y)
update_tasks()
#print "Done with do_date"
# This function updates the calendar and names/dates of days
# on the event list
def update_display(dt, dy, m, y):
#debut fonction horaire
global nbjour
tabhoraire = ['SB77','SB77','Rep','NB47','NB47','NH','NB77',
'Rep','Rep','SB77','SB77','SB77','Rep','Rep',
'MH','MH','MH','MH','MH','Rep','Rep',
'SH', 'SH','SH','SH', 'Rep','Rep','NB47',
'NB47','NB47','NB47','Rep','Rep','Rep','Rep',
'MB77','MB77','MB77','MB','M1', 'Rep','Rep',
'SB47','SB47','SB47', 'Rep','Rep','MH','MH',
'MH','Rep','MB47','MB47','MB47','Rep','Rep',
'NB77','NB77','NB77','NB77','NB77','Rep','Rep',
'Rep','SB','SB','SB47','SB47','Rep','Rep',
'MB47','MB47','Rep','Rep','SH', 'SH','SH',
'Rep','MB','MB','MB77','MB77','Rep','Rep']
#timeHere = time.localtime() #'NoneType' object is not callable
#temp=time.strftime('%d/%m/%y %H:%M',time.localtime()) # 'NoneType' object is not callable
#y,m,d,h,m,s,wd,yd,x=time.localtime # 'NoneType' object is not iterable
#nbjour=datetime.date(y,m,dt) - datetime.date(2008,3,3) #global name 'datetime' is not defined
#print "In update_display()\n"
dt = int(dt)
m = int(m)
draw_cal()
# Dsp.task_day[0].value = ''.join( [day_i18n(next_day(0, dy)), ' ', `dt`] ) ################################ ligne originale
Dsp.task_day[0].value = ''.join( [day_i18n(weekday(y,m,dt)), ' ', `dt`," ",tabhoraire[0]] ) #ligne modifie suite bug
Dsp.task_day[1].value = ''.join( [day_i18n(weekday(y,m,dt+1)), ' ', `dt+1`," ",tabhoraire[1]] ) #ligne modifie suite bug
Dsp.task_day[2].value = ''.join( [day_i18n(weekday(y,m,dt+2)), ' ', `dt+2`," ",tabhoraire[2]] ) #ligne modifie suite bug
Dsp.task_day[3].value = ''.join( [day_i18n(weekday(y,m,dt+3)), ' ', `dt+3`," ",tabhoraire[3]] ) #ligne modifie suite bug
Dsp.task_day[4].value = ''.join( [day_i18n(weekday(y,m,dt+4)), ' ', `dt+4`," ",tabhoraire[4]] ) #ligne modifie suite bug
Dsp.task_day[5].value = ''.join( [day_i18n(weekday(y,m,dt+5)), ' ', `dt+5`," ",tabhoraire[5]] ) #ligne modifie suite bug
#Dsp.task_day[6].value = time.strftime("%d%b%Y", time.localtime()) # 'NoneType' object is not callable
Dsp.task_day[6].value = ''.join( [day_i18n(weekday(y,m,dt+6)), ' ', `dt+6`," ",tabhoraire[6]] ) #ligne modifie suite bug
# for i in range(1, Dsp.task_array.length):
# Dsp.task_day[i].value = ''.join( [day_i18n(next_day(i, weekday(y,m,dt))), ' ', `next_date(i, y, m, dt)`] )
# Dsp.task_day[i].value = ''.join( [day_i18n(next_day(i, dy)), ' ', `next_date(i, y, m, dt)`] ) #############ligne originale
# This updates the display with the next 7 days' tasks
def update_tasks():
global ev_list
#print "In update_tasks()\n"
y,m,d = time.date
ev_list = get_config("WeeklyCalendar_event_list", [])
num_evs = get_config("WeeklyCalendar_num_evs", 0)
#print "get_config: %s" % ev_list
Dsp.task[0].value = import_tasks()
Dsp.task[1].value = import_tasks(next_date(1, y, m, d))
Dsp.task[2].value = import_tasks(next_date(2, y, m, d))
Dsp.task[3].value = import_tasks(next_date(3, y, m, d))
Dsp.task[4].value = import_tasks(next_date(4, y, m, d))
Dsp.task[5].value = import_tasks(next_date(5, y, m, d))
Dsp.task[6].value = import_tasks(next_date(6, y, m, d))
update_delete_enum()
change_day_color()
#print "End update_tasks()"
# Draws the top calendar
def draw_cal(yr=0, mon=0, month_matrix=[]):
y,m,d = time.date
this_month = True
if (yr != 0 or mon != 0) and (yr != y or mon != m):
this_month = False
if yr != 0 and mon != 0:
y = yr
m = mon
elif yr == 0 and mon != 0:
m = mon
elif yr != 0 and mon == 0:
y = yr
Dsp.month.value = month_i18n(m)
Dsp.year.value = y
#print " drawing %i/%i" % (m,y)
day1, ndays = monthrange(y, m)
month_matrix = monthcalendar(y, m)
if _firstweekday == `MONDAY`:
Dsp.cal_dayname1.value = day_abbr_i18n(0)
Dsp.cal_dayname2.value = day_abbr_i18n(1)
Dsp.cal_dayname3.value = day_abbr_i18n(2)
Dsp.cal_dayname4.value = day_abbr_i18n(3)
Dsp.cal_dayname5.value = day_abbr_i18n(4)
Dsp.cal_dayname6.value = day_abbr_i18n(5)
Dsp.cal_dayname7.value = day_abbr_i18n(6)
else:
Dsp.cal_dayname1.value = day_abbr_i18n(6)
Dsp.cal_dayname2.value = day_abbr_i18n(0)
Dsp.cal_dayname3.value = day_abbr_i18n(1)
Dsp.cal_dayname4.value = day_abbr_i18n(2)
Dsp.cal_dayname5.value = day_abbr_i18n(3)
Dsp.cal_dayname6.value = day_abbr_i18n(4)
Dsp.cal_dayname7.value = day_abbr_i18n(5)
# Try to find a better way to determine the total
# number of rows
# If last element in 5th row == ndays or 0,
# matrix ends there
if month_matrix[4][6] == ndays or month_matrix[4][6] == 0:
rows = 5
else:
rows = 6
# Clear the last row
for w in range(7): Dsp.cal[35+w].visible = False
for r in range(rows):
for c in range(7):
day = month_matrix[r][c]
i = (r * 7) + c
Dsp.cal[i].value = day
if day == 0 or day == "":
# This is necessary to clear the days
# already #printed when changing the first
# day of the week
Dsp.cal[i].visible = False
else:
Dsp.cal[i].visible = True
if this_month:
change_day_color()
else:
for i in range(Dsp.cal_array.length):
Dsp.cal_border[i].color = "#00000000"
Dsp.cal[i].color = cal_date_col
#print "Out of draw_cal"
def set_surrounding_months(year, month):
prev_month_mx = monthcalendar(year-1, month-1) # since _y and _m are still current
next_month_mx = monthcalendar(year+1, month+1)
# Callback for changing a color on the month's calendar
def change_day_color(key="", value=""):
#print "Updating the calendar colors (%s, %s)" % (key, value)
global today_col, ev_col, cal_date_col
y,m,d = time.date
#if key == "today_col": today_col = value
#elif key == "ev_col": ev_col = value
#elif key == "cal_date_col": cal_date_col = value
for i in range(Dsp.cal_array.length):
Dsp.cal_border[i].color = "#00000000"
date_at_i = Dsp.cal[i].value
if date_at_i == d:
Dsp.cal[i].color = today_col
if drawborder: Dsp.cal_border[i].color = today_col
else:
try:
if ev_day_list_this_month[date_at_i]:
Dsp.cal[i].color = ev_col
else:
Dsp.cal[i].color = cal_date_col
except:
Dsp.cal[i].color = cal_date_col
# Gets and formats the tasks for a given day (or, by default, today)
# Returns a formatted string like:
# Start:Time - End:Time - Event Description 1\n
def import_tasks(dy=0):
global ev_list
evs = []
ev = ""
y,m,d = time.date
h,min,s = time.time
if dy != 0 and dy < d:
if m==12:
# must be next year
m = 1
y += 1
else:
# must be next month
m += 1
if dy != 0: d = dy
#print "Importing tasks for %i/%i/%i" % (m,d,y)
for element in ev_list:
(st_yr, st_mon, st_dy, st_h, st_m, st_s), (en_yr, en_mon, en_dy, en_h, en_m, en_s), summary, rrule = element
if st_yr == y and st_mon == m and st_dy == d:
if st_h != en_h or st_m != en_m or st_s != en_s:
ev = ''.join([ev, `st_h`, ":", str("%02d" % st_m), " - ", `en_h`, ":", str("%02d" % en_m), ": ", summary, "\n"])
else:
ev = ''.join([ev, `st_h`, ":", str("%02d" % st_m), ": ", summary, "\n"])
return ev
#######################################
# For moving through months
#######################################
# _m and _y will be the counter variables when
# progressing through months
def scroll_months(dir):
if dir == 0: cal_prev()
else: cal_next()
def cal_prev():
y,m,d = time.date
global _m
global _y
#draw_cal(_y, _m, prev_month_mx)
if _m != 1:
_m -= 1
else:
_m = 12
_y -= 1
draw_cal(_y, _m)
set_surrounding_months(_y, _m)
def cal_cur():
y,m,d = time.date
global _m, _y
_m = m
_y = y
draw_cal()
set_surrounding_months(_y, _m)
def cal_next():
y,m,d = time.date
global _m, _y
#draw_cal(_y, _m, next_month_mx)
if _m != 12:
_m += 1
else:
_y += 1
_m = 1
draw_cal(_y, _m)
set_surrounding_months(_y, _m)
#######################################
# Things to do upon initialization
####################################### # Layout the calendar
x = 0
y = 0
for i in range(Dsp.cal_array.length):
Dsp.cal_border[i].x = Unit(x * 0.65, CM)
Dsp.cal_border[i].y = Unit(y * 0.40, CM)
x += 1
if (x == 7):
x = 0
y += 1
# Layout the task list
for i in range(Dsp.task_array.length):
Dsp.task_day[i].y = Unit( i * 15, PERCENT)
Dsp.task[i].y = Unit( (i * 15) + 3, PERCENT)
# Layout the navigation buttons
Dsp.navigate.x = Unit( (5.6 / 2) - 1, CM )
# Set up the previous and next month matrices
#set_surrounding_months(_y, _m)
# watch date and time
cal.time = time
time.bind("date", do_date)
do_date(time.date)
]]>
</script>
</display> |
Partager