]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wxPython/lib/calendar.py
virtual function hiding problem
[wxWidgets.git] / wxPython / wxPython / lib / calendar.py
CommitLineData
944930d5 1#----------------------------------------------------------------------------
e0473f5f 2# Name: calendar.py
944930d5
RD
3# Purpose: Calendar display control
4#
49875c53 5# Author: Lorne White (email: lorne.white@telusplanet.net)
944930d5
RD
6#
7# Created:
572c7069
RD
8# Version 0.92
9# Date: Nov 26, 2001
944930d5
RD
10# Licence: wxWindows license
11#----------------------------------------------------------------------------
12
13from wxPython.wx import *
14
e0473f5f 15from CDate import *
944930d5
RD
16import string, time
17
e0473f5f 18
944930d5
RD
19CalDays = [6, 0, 1, 2, 3, 4, 5]
20AbrWeekday = {6:"Sun", 0:"Mon", 1:"Tue", 2:"Wed", 3:"Thu", 4:"Fri", 5:"Sat"}
53fe40ba 21_MIDSIZE = 180
944930d5 22
f6bcfd97 23BusCalDays = [0, 1, 2, 3, 4, 5, 6]
944930d5
RD
24
25# calendar drawing routing
26
49875c53
RD
27def GetMonthList():
28 monthlist = []
29 for i in range(13):
30 name = Month[i]
31 if name != None:
32 monthlist.append(name)
33 return monthlist
6a1836a0 34
944930d5 35class CalDraw:
f6bcfd97
BP
36 def __init__(self, parent):
37 self.pwidth = 1
38 self.pheight = 1
39 try:
40 self.scale = parent.scale
41 except:
42 self.scale = 1
43
44 self.DefParms()
45
46 def DefParms(self):
53fe40ba
RD
47 self.num_auto = TRUE # auto scale of the cal number day size
48 self.num_size = 12 # default size of calendar if no auto size
49 self.max_num_size = 12 # maximum size for calendar number
50
51 self.num_align_horz = wxALIGN_CENTRE # alignment of numbers
52 self.num_align_vert = wxALIGN_CENTRE
53 self.num_indent_horz = 0 # points indent from position, used to offset if not centered
54 self.num_indent_vert = 0
55
56 self.week_auto = TRUE # auto scale of week font text
57 self.week_size = 10
58 self.max_week_size = 12
59
f6bcfd97
BP
60 self.grid_color = 'BLACK' # grid and selection colors
61 self.back_color = 'WHITE'
62 self.sel_color = 'RED'
63
64 self.high_color = 'LIGHT BLUE'
65 self.border_color = 'BLACK'
66 self.week_color = 'LIGHT GREY'
67
68 self.week_font_color = 'BLACK' # font colors
69 self.day_font_color = 'BLACK'
70
71 self.font = wxSWISS
72 self.bold = wxNORMAL
73
74 self.hide_title = FALSE
75 self.hide_grid = FALSE
76 self.outer_border = TRUE
77
78 self.title_offset = 0
79 self.cal_week_scale = 0.7
80 self.show_weekend = FALSE
81 self.cal_type = "NORMAL"
82
83 def SetWeekColor(self, font_color, week_color): # set font and background color for week title
84 self.week_font_color = font_color
85 self.week_color = week_color
944930d5
RD
86
87 def SetSize(self, size):
f6bcfd97
BP
88 self.set_sizew = size.width
89 self.set_sizeh = size.height
90
91 def InitValues(self): # default dimensions of various elements of the calendar
92 self.rg = {}
93 self.cal_sel = {}
94 self.set_cy_st = 0 # start position
95 self.set_cx_st = 0
96
97 self.set_y_mrg = 15 # start of vertical draw default
98 self.set_x_mrg = 10
99 self.set_y_end = 10
100
101 def SetPos(self, xpos, ypos):
102 self.set_cx_st = xpos
103 self.set_cy_st = ypos
944930d5 104
f6bcfd97
BP
105 def SetMarg(self, xmarg, ymarg):
106 self.set_x_st = xmarg
107 self.set_y_st = ymarg
108 self.set_y_end = ymarg
944930d5 109
f6bcfd97
BP
110 def InitScale(self): # scale position values
111 self.sizew = self.set_sizew * self.pwidth
112 self.sizeh = self.set_sizeh * self.pheight
113
114 self.cx_st = self.set_cx_st * self.pwidth # draw start position
115 self.cy_st = self.set_cy_st * self.pheight
116
117 self.x_mrg = self.set_x_mrg * self.pwidth # calendar draw margins
118 self.y_mrg = self.set_y_mrg * self.pheight
119 self.y_end = self.set_y_end * self.pheight
120
121 def DrawCal(self, DC, sel_lst=[]):
944930d5 122 self.DC = DC
f6bcfd97 123 self.InitScale()
944930d5
RD
124
125 self.DrawBorder()
944930d5
RD
126 if self.hide_title is FALSE:
127 self.DrawMonth()
128
129 self.Center()
130
131 self.DrawGrid()
132 self.GetRect()
133
f6bcfd97
BP
134 if self.show_weekend is TRUE: # highlight weekend dates
135 self.SetWeekEnd()
136
137 self.AddSelect(sel_lst) # overrides the weekend highlight
138
139 self.DrawSel() # highlighted days
944930d5
RD
140 self.DrawWeek()
141 self.DrawNum()
142
f6bcfd97
BP
143 def AddSelect(self, list, cfont=None, cbackgrd = None):
144 if cfont is None:
145 cfont = self.sel_color # font digit color
146 if cbackgrd is None:
147 cbackgrd = self.high_color # select background color
944930d5 148
f6bcfd97
BP
149 for val in list:
150 self.cal_sel[val] = (cfont, cbackgrd)
151
152 def DrawBorder(self): # draw border around the outside of the main display rectangle
153 brush = wxBrush(wxNamedColour(self.back_color), wxSOLID)
154 self.DC.SetBrush(brush)
155 self.DC.SetPen(wxPen(wxNamedColour(self.border_color), 1))
156
157 if self.outer_border is TRUE:
158 rect = wxRect(self.cx_st, self.cy_st, self.sizew, self.sizeh) # full display window area
159 self.DC.DrawRectangle(rect.x, rect.y, rect.width, rect.height)
944930d5
RD
160
161 def DrawNumVal(self):
162 self.DrawNum()
163
164# calculate the calendar days and offset position
165
166 def SetCal(self, year, month):
f6bcfd97
BP
167 self.InitValues() # reset initial values
168
944930d5
RD
169 self.year = year
170 self.month = month
171
172 day = 1
173 t = Date(year, month, day)
f6bcfd97
BP
174 dow = self.dow = t.day_of_week # start day in month
175 dim = self.dim = t.days_in_month # number of days in month
176 if self.cal_type == "NORMAL":
177 start_pos = dow+1
178 else:
179 start_pos = dow
180
944930d5
RD
181 self.st_pos = start_pos
182
183 self.cal = []
184 for i in range(start_pos):
185 self.cal.append('')
186 i = 1
187 while i <= dim:
188 self.cal.append(str(i))
189 i = i + 1
190 return start_pos
191
f6bcfd97
BP
192 def SetWeekEnd(self, font_color='BLACK', backgrd = 'LIGHT GREY'):
193 date = 6 - int(self.dow) # start day of first saturday
194 while date <= self.dim:
195 self.cal_sel[date] = (font_color, backgrd) # Saturday
196 date = date + 1
197 if date <= self.dim:
198 self.cal_sel[date] = (font_color, backgrd) # Sunday
199 date = date + 6
200 else:
201 date = date + 7
944930d5 202
f6bcfd97 203 def GetRect(self): # get the display rectange list of the day grid
944930d5
RD
204 cnt = 0
205 for y in self.gridy[1:-1]:
206 for x in self.gridx[:-1]:
207 rect = wxRect(x, y, self.dl_w, self.dl_h) # create rect region
208 self.rg[cnt] = rect
209 cnt = cnt + 1
210 return self.rg
211
212 def GetCal(self):
213 return self.cal
214
215 def GetOffset(self):
216 return self.st_pos
217
f6bcfd97 218 def DrawMonth(self): # month and year title
944930d5
RD
219 month = Month[self.month]
220
f6bcfd97 221 sizef = 11
e0473f5f
RD
222 if self.sizeh < _MIDSIZE:
223 sizef = 10
944930d5 224
e0473f5f 225 f = wxFont(sizef, self.font, wxNORMAL, self.bold)
944930d5
RD
226 self.DC.SetFont(f)
227
228 tw,th = self.DC.GetTextExtent(month)
f6bcfd97
BP
229 adjust = self.cx_st + (self.sizew-tw)/2
230 self.DC.DrawText(month, adjust, self.cy_st + th)
944930d5
RD
231
232 year = str(self.year)
233 tw,th = self.DC.GetTextExtent(year)
f6bcfd97 234 adjust = self.sizew - tw - self.x_mrg
944930d5 235
f6bcfd97 236 self.title_offset = th * 2
944930d5 237
e0473f5f 238 f = wxFont(sizef, self.font, wxNORMAL, self.bold)
944930d5 239 self.DC.SetFont(f)
f6bcfd97 240 self.DC.DrawText(year, self.cx_st + adjust, self.cy_st + th)
944930d5 241
f6bcfd97 242 def DrawWeek(self): # draw the week days
53fe40ba
RD
243 width = self.gridx[1]-self.gridx[0]
244 height = self.gridy[1] - self.gridy[0]
245 rect_w = self.gridx[7]-self.gridx[0]
246
247 f = wxFont(10, self.font, wxNORMAL, self.bold) # initial font setting
248 if self.week_auto == TRUE:
249 test_size = self.max_week_size # max size
250 test_day = ' Sun '
251 while test_size > 2:
252 f.SetPointSize(test_size)
253 self.DC.SetFont(f)
254 tw,th = self.DC.GetTextExtent(test_day)
255 if tw < width and th < height:
256 break
257 test_size = test_size - 1
258 else:
259 f.SetPointSize(self.week_size) # set fixed size
260 self.DC.SetFont(f)
944930d5 261
f6bcfd97 262 self.DC.SetTextForeground(wxNamedColour(self.week_font_color))
944930d5
RD
263
264 cnt_x = 0
265 cnt_y = 0
f6bcfd97
BP
266
267 brush = wxBrush(wxNamedColour(self.week_color), wxSOLID)
268 self.DC.SetBrush(brush)
269# self.DC.DrawRectangle(self.gridx[0], self.gridy[0], rect_w+1, height)
270
271 if self.cal_type == "NORMAL":
272 cal_days = CalDays
273 else:
274 cal_days = BusCalDays
275
276 for val in cal_days:
944930d5
RD
277 day = AbrWeekday[val]
278 if self.sizew < 200:
279 day = day[0]
280 dw,dh = self.DC.GetTextExtent(day)
281 diffx = (width-dw)/2
282 diffy = (height-dh)/2
283
284 x = self.gridx[cnt_x]
285 y = self.gridy[cnt_y]
f6bcfd97 286 self.DC.DrawRectangle(self.gridx[cnt_x], self.gridy[0], width+1, height)
944930d5
RD
287 self.DC.DrawText(day, x+diffx, y+diffy)
288 cnt_x = cnt_x + 1
289
f6bcfd97 290 def DrawNum(self): # draw the day numbers
53fe40ba
RD
291 f = wxFont(10, self.font, wxNORMAL, self.bold) # initial font setting
292 if self.num_auto == TRUE:
293 test_size = self.max_num_size # max size
294 test_day = ' 99 '
295 while test_size > 2:
296 f.SetPointSize(test_size)
297 self.DC.SetFont(f)
298 tw,th = self.DC.GetTextExtent(test_day)
299 if tw < self.dl_w and th < self.dl_h:
300 sizef = test_size
301 break
302 test_size = test_size - 1
303 else:
304 f.SetPointSize(self.num_size) # set fixed size
305 self.DC.SetFont(f)
944930d5
RD
306
307 cnt_x = 0
308 cnt_y = 1
309 for val in self.cal:
310 x = self.gridx[cnt_x]
311 y = self.gridy[cnt_y]
f6bcfd97
BP
312
313 try:
314 num_val = int(val)
315 num_color = self.cal_sel[num_val][0]
316 except:
317 num_color = self.day_font_color
318
319 self.DC.SetTextForeground(wxNamedColour(num_color))
320 self.DC.SetFont(f)
321
53fe40ba
RD
322 tw,th = self.DC.GetTextExtent(val)
323 if self.num_align_horz == wxALIGN_CENTRE:
324 adj_h = (self.dl_w - tw)/2
325 elif self.num_align_horz == wxALIGN_RIGHT:
326 adj_h = self.dl_w - tw
327 else:
328 adj_h = 0 # left alignment
329
330 adj_h = adj_h + self.num_indent_horz
331
332 if self.num_align_vert == wxALIGN_CENTRE:
333 adj_v = (self.dl_h - th)/2
334 elif self.num_align_horz == wxALIGN_RIGHT:
335 adj_v = self.dl_h - th
336 else:
337 adj_v = 0 # left alignment
338
339 adj_v = adj_v + self.num_indent_vert
340
341 self.DC.DrawText(val, x+adj_h, y+adj_v)
944930d5
RD
342 if cnt_x < 6:
343 cnt_x = cnt_x + 1
344 else:
345 cnt_x = 0
346 cnt_y = cnt_y + 1
347
f6bcfd97
BP
348 def Center(self): # calculate the dimensions in the center of the drawing area
349 bdw = self.x_mrg * 2
350 bdh = self.y_mrg + self.y_end + self.title_offset
944930d5 351
f6bcfd97
BP
352 self.dl_w = int((self.sizew-bdw)/7)
353 self.dl_h = int((self.sizeh-bdh)/7)
944930d5 354
f6bcfd97 355 self.dl_th = int(self.dl_h*self.cal_week_scale) # week title adjustment
944930d5 356 self.cwidth = self.dl_w * 7
f6bcfd97 357 self.cheight = self.dl_h * 6 + self.dl_th
944930d5 358
f6bcfd97
BP
359 def DrawSel(self): # highlighted selected days
360 for key in self.cal_sel.keys():
361 sel_color = self.cal_sel[key][1]
362 brush = wxBrush(wxNamedColour(sel_color), wxSOLID)
944930d5 363 self.DC.SetBrush(brush)
f6bcfd97 364
944930d5
RD
365 if self.hide_grid is FALSE:
366 self.DC.SetPen(wxPen(wxNamedColour(self.grid_color), 0))
367 else:
368 self.DC.SetPen(wxPen(wxNamedColour(self.back_color), 0))
369 nkey = key + self.st_pos -1
370 rect = self.rg[nkey]
371 self.DC.DrawRectangle(rect.x, rect.y, rect.width+1, rect.height+1)
372
f6bcfd97 373 def DrawGrid(self): # calculate and draw the grid lines
944930d5
RD
374 self.DC.SetPen(wxPen(wxNamedColour(self.grid_color), 0))
375
376 self.gridx = []
377 self.gridy = []
378
f6bcfd97
BP
379 self.x_st = self.cx_st + self.x_mrg
380 self.y_st = self.cy_st + self.y_mrg + self.title_offset # start postion of draw
381
944930d5
RD
382 x1 = self.x_st
383 y1 = self.y_st
f6bcfd97
BP
384
385 y2 = y1 + self.cheight
944930d5
RD
386 for i in range(8):
387 if self.hide_grid is FALSE:
388 self.DC.DrawLine(x1, y1, x1, y2)
389 self.gridx.append(x1)
390 x1 = x1 + self.dl_w
391
392 x1 = self.x_st
393 y1 = self.y_st
f6bcfd97
BP
394
395 x2 = x1 + self.cwidth
944930d5
RD
396 for i in range(8):
397 if self.hide_grid is FALSE:
398 self.DC.DrawLine(x1, y1, x2, y1)
399 self.gridy.append(y1)
400 if i == 0:
f6bcfd97 401 y1 = y1 + self.dl_th
944930d5
RD
402 else:
403 y1 = y1 + self.dl_h
404
405
f6bcfd97
BP
406class PrtCalDraw(CalDraw):
407 def InitValues(self):
408 self.rg = {}
409 self.cal_sel = {}
410 self.set_cx_st = 1.0 # start draw border location
411 self.set_cy_st = 1.0
412
413 self.set_y_mrg = 0.2 # draw offset position
414 self.set_x_mrg = 0.2
415 self.set_y_end = 0.2
416
417 def SetPSize(self, pwidth, pheight): # calculate the dimensions in the center of the drawing area
418 self.pwidth = int(pwidth)/self.scale
419 self.pheight = int(pheight)/self.scale
420
421 def SetPreview(self, preview):
422 self.preview = preview
423
e0473f5f 424class wxCalendar(wxWindow):
944930d5
RD
425 def __init__(self, parent, id, pos=wxDefaultPosition, size=wxDefaultSize):
426 wxWindow.__init__(self, parent, id, pos, size)
427
428 # set the calendar control attributes
429
430 self.grid_color = 'BLACK'
431 self.back_color = 'WHITE'
f6bcfd97 432 self.hide_grid = FALSE
944930d5 433 self.sel_color = 'RED'
f6bcfd97
BP
434 self.hide_title = FALSE
435 self.show_weekend = FALSE
436 self.cal_type = "NORMAL"
437
438 self.week_color = 'LIGHT GREY'
439 self.week_font_color = 'BLACK' # font colors
440
441 self.select_list = []
944930d5
RD
442
443 self.SetBackgroundColour(wxNamedColor(self.back_color))
444 self.Connect(-1, -1, wxEVT_LEFT_DOWN, self.OnLeftEvent)
445 self.Connect(-1, -1, wxEVT_LEFT_DCLICK, self.OnLeftDEvent)
446 self.Connect(-1, -1, wxEVT_RIGHT_DOWN, self.OnRightEvent)
447 self.Connect(-1, -1, wxEVT_RIGHT_DCLICK, self.OnRightDEvent)
448
449 self.sel_key = None # last used by
450 self.sel_lst = [] # highlighted selected days
451
452 self.SetNow() # default calendar for current month
453
454 self.size = None
944930d5
RD
455 self.set_day = None
456
f6bcfd97 457 EVT_PAINT(self, self.OnPaint)
943ca237 458 EVT_SIZE(self, self.OnSize)
f6bcfd97 459
944930d5
RD
460# control some of the main calendar attributes
461
462 def HideTitle(self):
463 self.hide_title = TRUE
464
465 def HideGrid(self):
466 self.hide_grid = TRUE
467
468# determine the calendar rectangle click area and draw a selection
469
470 def ProcessClick(self, event):
471 self.x, self.y = event.GetX(), event.GetY()
472 key = self.GetDayHit(self.x, self.y)
473 self.SelectDay(key)
474
475# tab mouse click events and process
476
477 def OnLeftEvent(self, event):
478 self.click = 'LEFT'
53fe40ba
RD
479 self.shiftkey = event.ShiftDown()
480 self.ctrlkey = event.ControlDown()
944930d5
RD
481 self.ProcessClick(event)
482
483 def OnLeftDEvent(self, event):
484 self.click = 'DLEFT'
485 self.ProcessClick(event)
486
487 def OnRightEvent(self, event):
488 self.click = 'RIGHT'
489 self.ProcessClick(event)
490
491 def OnRightDEvent(self, event):
492 self.click = 'DRIGHT'
493 self.ProcessClick(event)
494
495 def SetSize(self, set_size):
496 self.size = set_size
497
498 def SetSelDay(self, sel):
499 self.sel_lst = sel # list of highlighted days
500
501# get the current date
502
503 def SetNow(self):
504 dt = now()
505 self.month = dt.month
506 self.year = dt.year
507 self.day = dt.day
508
509# set the current day
510
511 def SetCurrentDay(self):
512 self.SetNow()
513 self.set_day = self.day
514
515# get the date, day, month, year set in calendar
516
517 def GetDate(self):
518 return self.day, self.month, self.year
519
520 def GetDay(self):
521 return self.day
522
523 def GetMonth(self):
524 return self.month
525
526 def GetYear(self):
527 return self.year
528
529# set the day, month, and year
530
531 def SetDayValue(self, day):
532 self.set_day = day
533
534 def SetMonth(self, month):
535 if month >= 1 and month <= 12:
536 self.month = month
537 else:
538 self.month = 1
539 self.set_day = None
540
541 def SetYear(self, year):
542 self.year = year
543
544# increment year and month
545
546 def IncYear(self):
547 self.year = self.year + 1
548 self.set_day = None
549
550 def DecYear(self):
551 self.year = self.year - 1
552 self.set_day = None
553
554 def IncMonth(self):
555 self.month = self.month + 1
556 if self.month > 12:
557 self.month = 1
558 self.year = self.year + 1
559 self.set_day = None
560
561 def DecMonth(self):
562 self.month = self.month - 1
563 if self.month < 1:
564 self.month = 12
565 self.year = self.year - 1
566 self.set_day = None
567
568# test to see if the selection has a date and create event
569
570 def TestDay(self, key):
571 try:
572 self.day = int(self.cal[key])
573 except:
574 return None
575 if self.day == "":
576 return None
577 else:
578 evt = wxPyCommandEvent(2100, self.GetId())
579 evt.click, evt.day, evt.month, evt.year = self.click, self.day, self.month, self.year
53fe40ba
RD
580 evt.shiftkey = self.shiftkey
581 evt.ctrlkey = self.ctrlkey
944930d5
RD
582 self.GetEventHandler().ProcessEvent(evt)
583
584 self.set_day = self.day
585 return key
586
587# find the clicked area rectangle
588
589 def GetDayHit(self, mx, my):
590 for key in self.rg.keys():
591 val = self.rg[key]
f6bcfd97
BP
592 ms_rect = wxRect(mx, my, 1, 1)
593 if wxIntersectRect(ms_rect, val) is not None:
944930d5
RD
594 result = self.TestDay(key)
595 return result
596 return None
597
598# calendar drawing
599
f6bcfd97
BP
600 def SetWeekColor(self, font_color, week_color): # set font and background color for week title
601 self.week_font_color = font_color
602 self.week_color = week_color
603
604 def AddSelect(self, list, font_color, back_color):
605 list_val = [list, font_color, back_color]
606 self.select_list.append(list_val)
607
608 def ShowWeekEnd(self):
609 self.show_weekend = TRUE # highlight weekend
610
611 def SetBusType(self):
612 self.cal_type = "BUS"
613
943ca237
RD
614 def OnSize(self, evt):
615 self.Refresh(false)
616 evt.Skip()
617
944930d5
RD
618 def OnPaint(self, event):
619 DC = wxPaintDC(self)
620 self.DoDrawing(DC)
621
622 def DoDrawing(self, DC):
623 DC = wxPaintDC(self)
624 DC.BeginDrawing()
625
f6bcfd97
BP
626 self.cal = cal = CalDraw(self)
627
628 cal.grid_color = self.grid_color
629 cal.back_color = self.back_color
630 cal.hide_grid = self.hide_grid
631 cal.grid_color = self.grid_color
632 cal.hide_title = self.hide_title
633 cal.show_weekend = self.show_weekend
634 cal.cal_type = self.cal_type
635
944930d5
RD
636 if self.size is None:
637 size = self.GetClientSize()
638 else:
639 size = self.size
640
641# drawing attributes
642
f6bcfd97
BP
643 cal.week_font_color = self.week_font_color
644 cal.week_color = self.week_color
944930d5
RD
645
646 cal.SetSize(size)
647 cal.SetCal(self.year, self.month)
f6bcfd97
BP
648 for val in self.select_list:
649 cal.AddSelect(val[0], val[1], val[2])
650
944930d5
RD
651 cal.DrawCal(DC, self.sel_lst)
652
653 self.rg = cal.GetRect()
654 self.cal = cal.GetCal()
655 self.st_pos = cal.GetOffset()
656 self.ymax = DC.MaxY()
657
658 if self.set_day != None:
659 self.SetDay(self.set_day)
660 DC.EndDrawing()
661
662# draw the selection rectangle
663
664 def DrawRect(self, key, color = 'BLACK', width = 0):
665 if key == None:
666 return
667 DC = wxClientDC(self)
668 DC.BeginDrawing()
669
670 brush = wxBrush(wxColour(0, 0xFF, 0x80), wxTRANSPARENT)
671 DC.SetBrush(brush)
672 DC.SetPen(wxPen(wxNamedColour(color), width))
673
674 rect = self.rg[key]
675 DC.DrawRectangle(rect.x, rect.y, rect.width+1, rect.height+1)
676
677 DC.EndDrawing()
678
679# set the day selection
680
681 def SetDay(self, day):
682 day = day + self.st_pos - 1
683 self.SelectDay(day)
684
685 def SelectDay(self, key):
686 sel_size = 1
687 self.DrawRect(self.sel_key, self.back_color, sel_size) # clear large selection
688 if self.hide_grid is FALSE:
689 self.DrawRect(self.sel_key, self.grid_color)
690
691 self.DrawRect(key, self.sel_color, sel_size)
692 self.sel_key = key # store last used by
693 self.select_day = None
694
695 def ClearDsp(self):
696 self.Clear()
6a1836a0 697
49875c53
RD
698class CalenDlg(wxDialog):
699 def __init__(self, parent, month=None, day = None, year=None):
700 wxDialog.__init__(self, parent, -1, "Event Calendar", wxPyDefaultPosition, wxSize(280, 360))
701
702 # set the calendar and attributes
703 self.calend = wxCalendar(self, -1, wxPoint(20, 60), wxSize(240, 200))
704 if month == None:
705 self.calend.SetCurrentDay()
706 start_month = self.calend.GetMonth()
707 start_year = self.calend.GetYear()
708 else:
6a1836a0
RD
709 self.calend.month = start_month = month
710 self.calend.year = start_year = year
49875c53
RD
711 self.calend.SetDayValue(day)
712
713 self.calend.HideTitle()
714 self.ResetDisplay()
715
716 # get month list from DateTime
717 monthlist = GetMonthList()
718
719 # select the month
720 mID = NewId()
721 self.date = wxComboBox(self, mID, Month[start_month], wxPoint(20, 20), wxSize(90, -1), monthlist, wxCB_DROPDOWN)
722 EVT_COMBOBOX(self, mID, self.EvtComboBox)
723
724 # alternate spin button to control the month
725 mID = NewId()
726 h = self.date.GetSize().height
727 self.m_spin = wxSpinButton(self, mID, wxPoint(130, 20), wxSize(h*2, h), wxSP_VERTICAL)
728 self.m_spin.SetRange(1, 12)
729 self.m_spin.SetValue(start_month)
730
731 EVT_SPIN(self, mID, self.OnMonthSpin)
732
733 # spin button to control the year
734 mID = NewId()
735 self.dtext = wxTextCtrl(self, -1, str(start_year), wxPoint(160, 20), wxSize(60, -1))
736 h = self.dtext.GetSize().height
737
738 self.y_spin = wxSpinButton(self, mID, wxPoint(220, 20), wxSize(h*2, h), wxSP_VERTICAL)
739 self.y_spin.SetRange(1980, 2010)
740 self.y_spin.SetValue(start_year)
741
742 EVT_SPIN(self, mID, self.OnYrSpin)
743
744 self.Connect(self.calend.GetId(), -1, 2100, self.MouseClick)
745
746 x_pos = 50
747 y_pos = 280
748 but_size = wxSize(60, 25)
749
750 mID = NewId()
751 wxButton(self, mID, ' Ok ', wxPoint(x_pos, y_pos), but_size)
752 EVT_BUTTON(self, mID, self.OnOk)
6a1836a0 753
49875c53
RD
754 mID = NewId()
755 wxButton(self, mID, ' Close ', wxPoint(x_pos + 120, y_pos), but_size)
756 EVT_BUTTON(self, mID, self.OnCancel)
757
758 def OnOk(self, event):
759 self.EndModal(wxID_OK)
760
761 def OnCancel(self, event):
762 self.EndModal(wxID_CANCEL)
763
764# log the mouse clicks
765 def MouseClick(self, evt):
6a1836a0 766 self.month = evt.month
49875c53
RD
767 self.result = [evt.click, str(evt.day), Month[evt.month], str(evt.year)] # result click type and date
768
769 if evt.click == 'DLEFT':
770 self.EndModal(wxID_OK)
771
772# month and year spin selection routines
773 def OnMonthSpin(self, event):
774 month = event.GetPosition()
775 self.date.SetValue(Month[month])
776 self.calend.SetMonth(month)
777 self.calend.Refresh()
778
779 def OnYrSpin(self, event):
780 year = event.GetPosition()
781 self.dtext.SetValue(str(year))
782 self.calend.SetYear(year)
783 self.calend.Refresh()
784
785 def EvtComboBox(self, event):
786 name = event.GetString()
787 monthval = self.date.FindString(name)
788 self.m_spin.SetValue(monthval+1)
789
790 self.calend.SetMonth(monthval+1)
791 self.ResetDisplay()
792
793# set the calendar for highlighted days
794
795 def ResetDisplay(self):
796 month = self.calend.GetMonth()
797 self.calend.Refresh()
944930d5
RD
798
799
6a1836a0 800