]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/calendar.py
d81f52f1c8d9e59cf2464634ecab13803c36a93e
[wxWidgets.git] / wxPython / wxPython / lib / calendar.py
1 #----------------------------------------------------------------------------
2 # Name: calendar.py
3 # Purpose: Calendar display control
4 #
5 # Author: Lorne White (email: lorne.white@telusplanet.net)
6 #
7 # Created:
8 # Version 0.92
9 # Date: Nov 26, 2001
10 # Licence: wxWindows license
11 #----------------------------------------------------------------------------
12
13 from wxPython.wx import *
14
15 from CDate import *
16 import string, time
17
18
19 CalDays = [6, 0, 1, 2, 3, 4, 5]
20 AbrWeekday = {6:"Sun", 0:"Mon", 1:"Tue", 2:"Wed", 3:"Thu", 4:"Fri", 5:"Sat"}
21 _MIDSIZE = 180
22
23 BusCalDays = [0, 1, 2, 3, 4, 5, 6]
24
25 # calendar drawing routing
26
27 def GetMonthList():
28 monthlist = []
29 for i in range(13):
30 name = Month[i]
31 if name != None:
32 monthlist.append(name)
33 return monthlist
34
35 class CalDraw:
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):
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
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
86
87 def SetSize(self, size):
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
104
105 def SetMarg(self, xmarg, ymarg):
106 self.set_x_st = xmarg
107 self.set_y_st = ymarg
108 self.set_y_end = ymarg
109
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=[]):
122 self.DC = DC
123 self.InitScale()
124
125 self.DrawBorder()
126 if self.hide_title is FALSE:
127 self.DrawMonth()
128
129 self.Center()
130
131 self.DrawGrid()
132 self.GetRect()
133
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
140 self.DrawWeek()
141 self.DrawNum()
142
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
148
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)
160
161 def DrawNumVal(self):
162 self.DrawNum()
163
164 # calculate the calendar days and offset position
165
166 def SetCal(self, year, month):
167 self.InitValues() # reset initial values
168
169 self.year = year
170 self.month = month
171
172 day = 1
173 t = Date(year, month, day)
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
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
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
202
203 def GetRect(self): # get the display rectange list of the day grid
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
218 def DrawMonth(self): # month and year title
219 month = Month[self.month]
220
221 sizef = 11
222 if self.sizeh < _MIDSIZE:
223 sizef = 10
224
225 f = wxFont(sizef, self.font, wxNORMAL, self.bold)
226 self.DC.SetFont(f)
227
228 tw,th = self.DC.GetTextExtent(month)
229 adjust = self.cx_st + (self.sizew-tw)/2
230 self.DC.DrawText(month, adjust, self.cy_st + th)
231
232 year = str(self.year)
233 tw,th = self.DC.GetTextExtent(year)
234 adjust = self.sizew - tw - self.x_mrg
235
236 self.title_offset = th * 2
237
238 f = wxFont(sizef, self.font, wxNORMAL, self.bold)
239 self.DC.SetFont(f)
240 self.DC.DrawText(year, self.cx_st + adjust, self.cy_st + th)
241
242 def DrawWeek(self): # draw the week days
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)
261
262 self.DC.SetTextForeground(wxNamedColour(self.week_font_color))
263
264 cnt_x = 0
265 cnt_y = 0
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:
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]
286 self.DC.DrawRectangle(self.gridx[cnt_x], self.gridy[0], width+1, height)
287 self.DC.DrawText(day, x+diffx, y+diffy)
288 cnt_x = cnt_x + 1
289
290 def DrawNum(self): # draw the day numbers
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)
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]
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
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)
342 if cnt_x < 6:
343 cnt_x = cnt_x + 1
344 else:
345 cnt_x = 0
346 cnt_y = cnt_y + 1
347
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
351
352 self.dl_w = int((self.sizew-bdw)/7)
353 self.dl_h = int((self.sizeh-bdh)/7)
354
355 self.dl_th = int(self.dl_h*self.cal_week_scale) # week title adjustment
356 self.cwidth = self.dl_w * 7
357 self.cheight = self.dl_h * 6 + self.dl_th
358
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)
363 self.DC.SetBrush(brush)
364
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
373 def DrawGrid(self): # calculate and draw the grid lines
374 self.DC.SetPen(wxPen(wxNamedColour(self.grid_color), 0))
375
376 self.gridx = []
377 self.gridy = []
378
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
382 x1 = self.x_st
383 y1 = self.y_st
384
385 y2 = y1 + self.cheight
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
394
395 x2 = x1 + self.cwidth
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:
401 y1 = y1 + self.dl_th
402 else:
403 y1 = y1 + self.dl_h
404
405
406 class 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
424 class wxCalendar(wxWindow):
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'
432 self.hide_grid = FALSE
433 self.sel_color = 'RED'
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 = []
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
455 self.set_day = None
456
457 EVT_PAINT(self, self.OnPaint)
458
459
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'
479 self.shiftkey = event.ShiftDown()
480 self.ctrlkey = event.ControlDown()
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
580 evt.shiftkey = self.shiftkey
581 evt.ctrlkey = self.ctrlkey
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]
592 ms_rect = wxRect(mx, my, 1, 1)
593 if wxIntersectRect(ms_rect, val) is not None:
594 result = self.TestDay(key)
595 return result
596 return None
597
598 # calendar drawing
599
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
614 def OnPaint(self, event):
615 DC = wxPaintDC(self)
616 self.DoDrawing(DC)
617
618 def DoDrawing(self, DC):
619 DC = wxPaintDC(self)
620 DC.BeginDrawing()
621
622 self.cal = cal = CalDraw(self)
623
624 cal.grid_color = self.grid_color
625 cal.back_color = self.back_color
626 cal.hide_grid = self.hide_grid
627 cal.grid_color = self.grid_color
628 cal.hide_title = self.hide_title
629 cal.show_weekend = self.show_weekend
630 cal.cal_type = self.cal_type
631
632 if self.size is None:
633 size = self.GetClientSize()
634 else:
635 size = self.size
636
637 # drawing attributes
638
639 cal.week_font_color = self.week_font_color
640 cal.week_color = self.week_color
641
642 cal.SetSize(size)
643 cal.SetCal(self.year, self.month)
644 for val in self.select_list:
645 cal.AddSelect(val[0], val[1], val[2])
646
647 cal.DrawCal(DC, self.sel_lst)
648
649 self.rg = cal.GetRect()
650 self.cal = cal.GetCal()
651 self.st_pos = cal.GetOffset()
652 self.ymax = DC.MaxY()
653
654 if self.set_day != None:
655 self.SetDay(self.set_day)
656 DC.EndDrawing()
657
658 # draw the selection rectangle
659
660 def DrawRect(self, key, color = 'BLACK', width = 0):
661 if key == None:
662 return
663 DC = wxClientDC(self)
664 DC.BeginDrawing()
665
666 brush = wxBrush(wxColour(0, 0xFF, 0x80), wxTRANSPARENT)
667 DC.SetBrush(brush)
668 DC.SetPen(wxPen(wxNamedColour(color), width))
669
670 rect = self.rg[key]
671 DC.DrawRectangle(rect.x, rect.y, rect.width+1, rect.height+1)
672
673 DC.EndDrawing()
674
675 # set the day selection
676
677 def SetDay(self, day):
678 day = day + self.st_pos - 1
679 self.SelectDay(day)
680
681 def SelectDay(self, key):
682 sel_size = 1
683 self.DrawRect(self.sel_key, self.back_color, sel_size) # clear large selection
684 if self.hide_grid is FALSE:
685 self.DrawRect(self.sel_key, self.grid_color)
686
687 self.DrawRect(key, self.sel_color, sel_size)
688 self.sel_key = key # store last used by
689 self.select_day = None
690
691 def ClearDsp(self):
692 self.Clear()
693
694 class CalenDlg(wxDialog):
695 def __init__(self, parent, month=None, day = None, year=None):
696 wxDialog.__init__(self, parent, -1, "Event Calendar", wxPyDefaultPosition, wxSize(280, 360))
697
698 # set the calendar and attributes
699 self.calend = wxCalendar(self, -1, wxPoint(20, 60), wxSize(240, 200))
700 if month == None:
701 self.calend.SetCurrentDay()
702 start_month = self.calend.GetMonth()
703 start_year = self.calend.GetYear()
704 else:
705 self.calend.month = start_month = month
706 self.calend.year = start_year = year
707 self.calend.SetDayValue(day)
708
709 self.calend.HideTitle()
710 self.ResetDisplay()
711
712 # get month list from DateTime
713 monthlist = GetMonthList()
714
715 # select the month
716 mID = NewId()
717 self.date = wxComboBox(self, mID, Month[start_month], wxPoint(20, 20), wxSize(90, -1), monthlist, wxCB_DROPDOWN)
718 EVT_COMBOBOX(self, mID, self.EvtComboBox)
719
720 # alternate spin button to control the month
721 mID = NewId()
722 h = self.date.GetSize().height
723 self.m_spin = wxSpinButton(self, mID, wxPoint(130, 20), wxSize(h*2, h), wxSP_VERTICAL)
724 self.m_spin.SetRange(1, 12)
725 self.m_spin.SetValue(start_month)
726
727 EVT_SPIN(self, mID, self.OnMonthSpin)
728
729 # spin button to control the year
730 mID = NewId()
731 self.dtext = wxTextCtrl(self, -1, str(start_year), wxPoint(160, 20), wxSize(60, -1))
732 h = self.dtext.GetSize().height
733
734 self.y_spin = wxSpinButton(self, mID, wxPoint(220, 20), wxSize(h*2, h), wxSP_VERTICAL)
735 self.y_spin.SetRange(1980, 2010)
736 self.y_spin.SetValue(start_year)
737
738 EVT_SPIN(self, mID, self.OnYrSpin)
739
740 self.Connect(self.calend.GetId(), -1, 2100, self.MouseClick)
741
742 x_pos = 50
743 y_pos = 280
744 but_size = wxSize(60, 25)
745
746 mID = NewId()
747 wxButton(self, mID, ' Ok ', wxPoint(x_pos, y_pos), but_size)
748 EVT_BUTTON(self, mID, self.OnOk)
749
750 mID = NewId()
751 wxButton(self, mID, ' Close ', wxPoint(x_pos + 120, y_pos), but_size)
752 EVT_BUTTON(self, mID, self.OnCancel)
753
754 def OnOk(self, event):
755 self.EndModal(wxID_OK)
756
757 def OnCancel(self, event):
758 self.EndModal(wxID_CANCEL)
759
760 # log the mouse clicks
761 def MouseClick(self, evt):
762 self.month = evt.month
763 self.result = [evt.click, str(evt.day), Month[evt.month], str(evt.year)] # result click type and date
764
765 if evt.click == 'DLEFT':
766 self.EndModal(wxID_OK)
767
768 # month and year spin selection routines
769 def OnMonthSpin(self, event):
770 month = event.GetPosition()
771 self.date.SetValue(Month[month])
772 self.calend.SetMonth(month)
773 self.calend.Refresh()
774
775 def OnYrSpin(self, event):
776 year = event.GetPosition()
777 self.dtext.SetValue(str(year))
778 self.calend.SetYear(year)
779 self.calend.Refresh()
780
781 def EvtComboBox(self, event):
782 name = event.GetString()
783 monthval = self.date.FindString(name)
784 self.m_spin.SetValue(monthval+1)
785
786 self.calend.SetMonth(monthval+1)
787 self.ResetDisplay()
788
789 # set the calendar for highlighted days
790
791 def ResetDisplay(self):
792 month = self.calend.GetMonth()
793 self.calend.Refresh()
794
795
796