]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/lib/calendar.py
added a test to check how exception handling works with Win32 SEH; corrected copyright
[wxWidgets.git] / wxPython / wx / lib / calendar.py
CommitLineData
d14a1e28
RD
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#----------------------------------------------------------------------------
b881fc78
RD
12# 12/01/2003 - Jeff Grimmett (grimmtooth@softhome.net)
13#
14# o Updated for wx namespace
15# o Tested with updated demo
16# o Added new event type EVT_CALENDAR. The reason for this is that the original
17# library used a hardcoded ID of 2100 for generating events. This makes it
18# very difficult to fathom when trying to decode the code since there's no
19# published API. Creating the new event binder might seem like overkill -
20# after all, you might ask, why not just use a new event ID and be done with
21# it? However, a consistent interface is very useful at times; also it makes
22# it clear that we're not just hunting for mouse clicks -- we're hunting
23# wabbit^H^H^H^H (sorry bout that) for calender-driven mouse clicks. So
24# that's my sad story. Shoot me if you must :-)
25# o There's still one deprecation warning buried in here somewhere, but I
26# haven't been able to find it yet. It only occurs when displaying a
27# print preview, and only the first time. It *could* be an error in the
28# demo, I suppose.
29#
30# Here's the traceback:
31#
32# C:\Python\lib\site-packages\wx\core.py:949: DeprecationWarning:
33# integer argument expected, got float
34# newobj = _core.new_Rect(*args, **kwargs)
35#
c1ea08d3
RD
36# 12/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
37#
38# o A few style-guide nips and tucks
39# o Renamed wxCalendar to Calendar
40# o Couple of bugfixes
41#
b25cb7db
RD
42# 06/02/2004 - Joerg "Adi" Sieker adi@sieker.info
43#
44# o Changed color handling, use dictionary instead of members.
45# This causes all color changes to be ignored if they manipluate the members directly.
46# SetWeekColor and other method color methods were adapted to use the new dictionary.
47# o Added COLOR_* constants
48# o Added SetColor method for Calendar class
49# o Added 3D look of week header
50# o Added colors for 3D look of header
51# o Fixed width calculation.
52# Because of rounding difference the total width and height of the
53# calendar could be up to 6 pixels to small. The last column and row
54# are now wider/taller by the missing amount.
55# o Added SetTextAlign method to wxCalendar. This exposes logic
56# which was already there.
57# o Fixed CalDraw.SetMarg which set set_x_st and set_y_st which don't get used anywhere.
58# Instead set set_x_mrg and set_y_mrg
59# o Changed default X and Y Margin to 0.
60# o Added wxCalendar.SetMargin.
9472490a
RD
61#
62# 17/03/2004 - Joerg "Adi" Sieker adi@sieker.info
63# o Added keyboard navigation to the control.
64# Use the cursor keys to navigate through the ages. :)
65# The Home key function as go to today
66# o select day is now a filled rect instead of just an outline
b25cb7db
RD
67
68import wx
d14a1e28
RD
69
70from CDate import *
71
d14a1e28
RD
72CalDays = [6, 0, 1, 2, 3, 4, 5]
73AbrWeekday = {6:"Sun", 0:"Mon", 1:"Tue", 2:"Wed", 3:"Thu", 4:"Fri", 5:"Sat"}
74_MIDSIZE = 180
75
b25cb7db
RD
76COLOR_GRID_LINES = "grid_lines"
77COLOR_BACKGROUND = "background"
78COLOR_SELECTION_FONT = "selection_font"
79COLOR_SELECTION_BACKGROUND = "selection_background"
80COLOR_BORDER = "border"
81COLOR_HEADER_BACKGROUND = "header_background"
82COLOR_HEADER_FONT = "header_font"
83COLOR_WEEKEND_BACKGROUND = "weekend_background"
84COLOR_WEEKEND_FONT = "weekend_font"
85COLOR_FONT = "font"
86COLOR_3D_LIGHT = "3d_light"
87COLOR_3D_DARK = "3d_dark"
88COLOR_HIGHLIGHT_FONT = "highlight_font"
89COLOR_HIGHLIGHT_BACKGROUND = "highlight_background"
90
d14a1e28
RD
91BusCalDays = [0, 1, 2, 3, 4, 5, 6]
92
b881fc78
RD
93# Calendar click event - added 12/1/03 by jmg (see above)
94wxEVT_COMMAND_PYCALENDAR_DAY_CLICKED = wx.NewEventType()
95EVT_CALENDAR = wx.PyEventBinder(wxEVT_COMMAND_PYCALENDAR_DAY_CLICKED, 1)
d14a1e28
RD
96
97def GetMonthList():
98 monthlist = []
99 for i in range(13):
100 name = Month[i]
101 if name != None:
102 monthlist.append(name)
103 return monthlist
104
b25cb7db
RD
105def MakeColor(in_color):
106 try:
107 color = wxNamedColour(in_color)
108 except:
109 color = in_color
110 return color
111
112def DefaultColors():
113 colors = {}
114 colors[COLOR_GRID_LINES] = 'BLACK'
115 colors[COLOR_BACKGROUND] = 'WHITE'
116 colors[COLOR_SELECTION_FONT] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWTEXT)
117 colors[COLOR_SELECTION_BACKGROUND] =wx.Colour(255,255,225)
118 colors[COLOR_BORDER] = 'BLACK'
119 colors[COLOR_HEADER_BACKGROUND] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE)
120 colors[COLOR_HEADER_FONT] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWTEXT)
121 colors[COLOR_WEEKEND_BACKGROUND] = 'LIGHT GREY'
122 colors[COLOR_WEEKEND_FONT] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWTEXT)
123 colors[COLOR_FONT] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWTEXT)
124 colors[COLOR_3D_LIGHT] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT)
125 colors[COLOR_3D_DARK] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNSHADOW)
9472490a
RD
126 colors[COLOR_HIGHLIGHT_FONT] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT)
127 colors[COLOR_HIGHLIGHT_BACKGROUND] = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT)
b25cb7db 128 return colors
b881fc78
RD
129# calendar drawing routing
130
d14a1e28
RD
131class CalDraw:
132 def __init__(self, parent):
133 self.pwidth = 1
134 self.pheight = 1
135 try:
136 self.scale = parent.scale
137 except:
138 self.scale = 1
139
b25cb7db
RD
140 self.gridx = []
141 self.gridy = []
142
d14a1e28
RD
143 self.DefParms()
144
145 def DefParms(self):
c1ea08d3
RD
146 self.num_auto = True # auto scale of the cal number day size
147 self.num_size = 12 # default size of calendar if no auto size
148 self.max_num_size = 12 # maximum size for calendar number
d14a1e28 149
b881fc78
RD
150 self.num_align_horz = wx.ALIGN_CENTRE # alignment of numbers
151 self.num_align_vert = wx.ALIGN_CENTRE
d14a1e28
RD
152 self.num_indent_horz = 0 # points indent from position, used to offset if not centered
153 self.num_indent_vert = 0
154
155 self.week_auto = True # auto scale of week font text
156 self.week_size = 10
157 self.max_week_size = 12
158
b25cb7db 159 self.colors = DefaultColors()
d14a1e28 160
b881fc78
RD
161 self.font = wx.SWISS
162 self.bold = wx.NORMAL
d14a1e28
RD
163
164 self.hide_title = False
165 self.hide_grid = False
166 self.outer_border = True
167
168 self.title_offset = 0
169 self.cal_week_scale = 0.7
170 self.show_weekend = False
171 self.cal_type = "NORMAL"
172
b25cb7db
RD
173 def SetWeekColor(self, font_color, week_color):
174 # set font and background color for week title
175 self.colors[COLOR_HEADER_FONT] = MakeColor(font_color)
176 self.colors[COLOR_HEADER_BACKGROUND] = MakeColor(week_color)
177 self.colors[COLOR_3D_LIGHT] = MakeColor(week_color)
178 self.colors[COLOR_3D_DARK] = MakeColor(week_color)
d14a1e28
RD
179
180 def SetSize(self, size):
b881fc78
RD
181 self.set_sizew = size[0]
182 self.set_sizeh = size[1]
d14a1e28
RD
183
184 def InitValues(self): # default dimensions of various elements of the calendar
185 self.rg = {}
186 self.cal_sel = {}
187 self.set_cy_st = 0 # start position
188 self.set_cx_st = 0
189
b25cb7db
RD
190 self.set_y_mrg = 1 # start of vertical draw default
191 self.set_x_mrg = 1
192 self.set_y_end = 1
d14a1e28
RD
193 def SetPos(self, xpos, ypos):
194 self.set_cx_st = xpos
195 self.set_cy_st = ypos
196
197 def SetMarg(self, xmarg, ymarg):
b25cb7db
RD
198 self.set_x_mrg = xmarg
199 self.set_y_mrg = ymarg
d14a1e28
RD
200 self.set_y_end = ymarg
201
202 def InitScale(self): # scale position values
c8431295
RD
203 self.sizew = int(self.set_sizew * self.pwidth)
204 self.sizeh = int(self.set_sizeh * self.pheight)
d14a1e28 205
c8431295
RD
206 self.cx_st = int(self.set_cx_st * self.pwidth) # draw start position
207 self.cy_st = int(self.set_cy_st * self.pheight)
d14a1e28 208
c8431295
RD
209 self.x_mrg = int(self.set_x_mrg * self.pwidth) # calendar draw margins
210 self.y_mrg = int(self.set_y_mrg * self.pheight)
211 self.y_end = int(self.set_y_end * self.pheight)
d14a1e28
RD
212
213 def DrawCal(self, DC, sel_lst=[]):
d14a1e28
RD
214 self.InitScale()
215
b25cb7db 216 self.DrawBorder(DC)
b881fc78 217
d14a1e28 218 if self.hide_title is False:
b25cb7db 219 self.DrawMonth(DC)
d14a1e28
RD
220
221 self.Center()
222
b25cb7db 223 self.DrawGrid(DC)
d14a1e28 224 self.GetRect()
d14a1e28
RD
225 if self.show_weekend is True: # highlight weekend dates
226 self.SetWeekEnd()
227
228 self.AddSelect(sel_lst) # overrides the weekend highlight
229
b25cb7db
RD
230 self.DrawSel(DC) # highlighted days
231 self.DrawWeek(DC)
232 self.DrawNum(DC)
d14a1e28
RD
233
234 def AddSelect(self, list, cfont=None, cbackgrd = None):
235 if cfont is None:
b25cb7db 236 cfont = self.colors[COLOR_SELECTION_FONT] # font digit color
d14a1e28 237 if cbackgrd is None:
b25cb7db 238 cbackgrd = self.colors[COLOR_SELECTION_BACKGROUND] # select background color
d14a1e28
RD
239
240 for val in list:
241 self.cal_sel[val] = (cfont, cbackgrd)
242
b881fc78 243 # draw border around the outside of the main display rectangle
9472490a
RD
244 def DrawBorder(self, DC, transparent = False):
245 if self.outer_border is True:
246 if transparent == False:
247 brush = wx.Brush(MakeColor(self.colors[COLOR_BACKGROUND]), wx.SOLID)
248 else:
249 brush = wx.TRANSPARENT_BRUSH
250 DC.SetBrush(brush)
251 DC.SetPen(wx.Pen(MakeColor(self.colors[COLOR_BORDER])))
252 # full display window area
253 rect = wx.Rect(self.cx_st, self.cy_st, self.sizew, self.sizeh)
254 DC.DrawRectangleRect(rect)
255
256 def DrawFocusIndicator(self, DC):
d14a1e28 257 if self.outer_border is True:
9472490a
RD
258 DC.SetBrush(wx.TRANSPARENT_BRUSH)
259 DC.SetPen(wx.Pen(MakeColor(self.colors[COLOR_HIGHLIGHT_BACKGROUND]), style=wx.DOT))
b881fc78
RD
260 # full display window area
261 rect = wx.Rect(self.cx_st, self.cy_st, self.sizew, self.sizeh)
b25cb7db 262 DC.DrawRectangleRect(rect)
d14a1e28
RD
263
264 def DrawNumVal(self):
265 self.DrawNum()
266
c1ea08d3 267 # calculate the calendar days and offset position
d14a1e28
RD
268 def SetCal(self, year, month):
269 self.InitValues() # reset initial values
270
271 self.year = year
272 self.month = month
273
274 day = 1
275 t = Date(year, month, day)
276 dow = self.dow = t.day_of_week # start day in month
277 dim = self.dim = t.days_in_month # number of days in month
b881fc78 278
d14a1e28
RD
279 if self.cal_type == "NORMAL":
280 start_pos = dow+1
281 else:
282 start_pos = dow
283
284 self.st_pos = start_pos
285
b25cb7db 286 self.cal_days = []
d14a1e28 287 for i in range(start_pos):
b25cb7db 288 self.cal_days.append('')
b881fc78 289
d14a1e28
RD
290 i = 1
291 while i <= dim:
b25cb7db 292 self.cal_days.append(str(i))
d14a1e28 293 i = i + 1
b881fc78 294
3e7c6081
RD
295 self.end_pos = dow + dim
296
d14a1e28
RD
297 return start_pos
298
b25cb7db
RD
299 def SetWeekEnd(self, font_color=None, backgrd = None):
300 if font_color != None:
301 self.SetColor(COLOR_WEEKEND_FONT, MakeColor(font_color))
302 if backgrd != None:
303 self.SetColor(COLOR_WEEKEND_BACKGROUND, MakeColor(backgrd))
304
d14a1e28 305 date = 6 - int(self.dow) # start day of first saturday
b881fc78 306
d14a1e28 307 while date <= self.dim:
b25cb7db 308 self.cal_sel[date] = (self.GetColor(COLOR_WEEKEND_FONT), self.GetColor(COLOR_WEEKEND_BACKGROUND)) # Saturday
d14a1e28 309 date = date + 1
b881fc78 310
d14a1e28 311 if date <= self.dim:
b25cb7db 312 self.cal_sel[date] = (self.GetColor(COLOR_WEEKEND_FONT), self.GetColor(COLOR_WEEKEND_BACKGROUND)) # Sunday
d14a1e28
RD
313 date = date + 6
314 else:
315 date = date + 7
316
c1ea08d3
RD
317 # get the display rectange list of the day grid
318 def GetRect(self):
d14a1e28 319 cnt = 0
9472490a
RD
320 h = 0
321 w = 0
d14a1e28 322 for y in self.gridy[1:-1]:
b25cb7db
RD
323 if y == self.gridy[-2]:
324 h = h + self.restH
325
d14a1e28 326 for x in self.gridx[:-1]:
c8431295
RD
327 assert type(y) == int
328 assert type(x) == int
b25cb7db
RD
329
330 w = self.cellW
331 h = self.cellH
332
333 if x == self.gridx[-2]:
334 w = w + self.restW
335
336 rect = wx.Rect(x, y, w+1, h+1) # create rect region
337
d14a1e28
RD
338 self.rg[cnt] = rect
339 cnt = cnt + 1
b881fc78 340
d14a1e28
RD
341 return self.rg
342
343 def GetCal(self):
b25cb7db 344 return self.cal_days
d14a1e28
RD
345
346 def GetOffset(self):
347 return self.st_pos
348
c1ea08d3 349 # month and year title
b25cb7db 350 def DrawMonth(self, DC):
d14a1e28
RD
351 month = Month[self.month]
352
353 sizef = 11
354 if self.sizeh < _MIDSIZE:
355 sizef = 10
356
b881fc78 357 f = wx.Font(sizef, self.font, wx.NORMAL, self.bold)
b25cb7db 358 DC.SetFont(f)
d14a1e28 359
b25cb7db 360 tw,th = DC.GetTextExtent(month)
d14a1e28 361 adjust = self.cx_st + (self.sizew-tw)/2
d7403ad2 362 DC.DrawText(month, adjust, self.cy_st + th)
d14a1e28
RD
363
364 year = str(self.year)
b25cb7db 365 tw,th = DC.GetTextExtent(year)
d14a1e28
RD
366 adjust = self.sizew - tw - self.x_mrg
367
368 self.title_offset = th * 2
369
b881fc78 370 f = wx.Font(sizef, self.font, wx.NORMAL, self.bold)
b25cb7db 371 DC.SetFont(f)
d7403ad2 372 DC.DrawText(year, self.cx_st + adjust, self.cy_st + th)
d14a1e28 373
b25cb7db
RD
374 def DrawWeek(self, DC): # draw the week days
375 # increase by 1 to include all gridlines
376 width = self.gridx[1] - self.gridx[0] + 1
377 height = self.gridy[1] - self.gridy[0] + 1
378 rect_w = self.gridx[-1] - self.gridx[0]
d14a1e28 379
b881fc78
RD
380 f = wx.Font(10, self.font, wx.NORMAL, self.bold) # initial font setting
381
d14a1e28
RD
382 if self.week_auto == True:
383 test_size = self.max_week_size # max size
384 test_day = ' Sun '
385 while test_size > 2:
386 f.SetPointSize(test_size)
b25cb7db
RD
387 DC.SetFont(f)
388 tw,th = DC.GetTextExtent(test_day)
b881fc78 389
d14a1e28
RD
390 if tw < width and th < height:
391 break
b881fc78 392
d14a1e28
RD
393 test_size = test_size - 1
394 else:
395 f.SetPointSize(self.week_size) # set fixed size
b25cb7db 396 DC.SetFont(f)
d14a1e28 397
b25cb7db 398 DC.SetTextForeground(MakeColor(self.colors[COLOR_HEADER_FONT]))
d14a1e28
RD
399
400 cnt_x = 0
401 cnt_y = 0
402
b25cb7db
RD
403 brush = wx.Brush(MakeColor(self.colors[COLOR_HEADER_BACKGROUND]), wx.SOLID)
404 DC.SetBrush(brush)
d14a1e28
RD
405
406 if self.cal_type == "NORMAL":
407 cal_days = CalDays
408 else:
409 cal_days = BusCalDays
410
411 for val in cal_days:
b25cb7db
RD
412 if val == cal_days[-1]:
413 width = width + self.restW
414
d14a1e28 415 day = AbrWeekday[val]
b881fc78 416
d14a1e28
RD
417 if self.sizew < 200:
418 day = day[0]
b881fc78 419
b25cb7db
RD
420 dw,dh = DC.GetTextExtent(day)
421
d14a1e28
RD
422 diffx = (width-dw)/2
423 diffy = (height-dh)/2
424
425 x = self.gridx[cnt_x]
426 y = self.gridy[cnt_y]
b25cb7db
RD
427 pointXY = (x, y)
428 pointWH = (width, height)
429 if self.hide_grid == False:
430 pen = wx.Pen(MakeColor(self.GetColor(COLOR_GRID_LINES)), 1, wx.SOLID)
431 else:
432 pen = wx.Pen(MakeColor(self.GetColor(COLOR_BACKGROUND)), 1, wx.SOLID)
433 DC.SetPen(pen)
d7403ad2 434 DC.DrawRectanglePointSize( pointXY, pointWH)
b25cb7db
RD
435
436 old_pen = DC.GetPen()
437
438 pen = wx.Pen(MakeColor(self.colors[COLOR_3D_LIGHT]), 1, wx.SOLID)
439 DC.SetPen(pen)
440 # draw the horizontal hilight
441 startPoint = wx.Point(x + 1 , y + 1)
442 endPoint = wx.Point(x + width - 1, y + 1)
d7403ad2 443 DC.DrawLinePoint(startPoint, endPoint )
b25cb7db
RD
444
445 # draw the vertical hilight
446 startPoint = wx.Point(x + 1 , y + 1)
447 endPoint = wx.Point(x + 1, y + height - 2)
d7403ad2 448 DC.DrawLinePoint(startPoint, endPoint )
b25cb7db
RD
449
450 pen = wx.Pen(MakeColor(self.colors[COLOR_3D_DARK]), 1, wx.SOLID)
451 DC.SetPen(pen)
452
453 # draw the horizontal lowlight
454 startPoint = wx.Point(x + 1, y + height - 2)
455 endPoint = wx.Point(x + width - 1, y + height - 2)
d7403ad2 456 DC.DrawLinePoint(startPoint, endPoint )
b25cb7db
RD
457
458 # draw the vertical lowlight
459 startPoint = wx.Point(x + width - 2 , y + 2)
460 endPoint = wx.Point(x + width - 2, y + height - 2)
d7403ad2 461 DC.DrawLinePoint(startPoint, endPoint )
b25cb7db
RD
462
463 pen = wx.Pen(MakeColor(self.colors[COLOR_FONT]), 1, wx.SOLID)
464
465 DC.SetPen(pen)
466
467 point = (x+diffx, y+diffy)
d7403ad2 468 DC.DrawTextPoint(day, point)
d14a1e28
RD
469 cnt_x = cnt_x + 1
470
9472490a 471 def _CalcFontSize(self, DC, f):
d14a1e28
RD
472 if self.num_auto == True:
473 test_size = self.max_num_size # max size
474 test_day = ' 99 '
b881fc78 475
d14a1e28
RD
476 while test_size > 2:
477 f.SetPointSize(test_size)
b25cb7db
RD
478 DC.SetFont(f)
479 tw,th = DC.GetTextExtent(test_day)
b881fc78 480
b25cb7db 481 if tw < self.cellW and th < self.cellH:
d14a1e28
RD
482 sizef = test_size
483 break
484 test_size = test_size - 1
485 else:
486 f.SetPointSize(self.num_size) # set fixed size
b25cb7db 487 DC.SetFont(f)
d14a1e28 488
9472490a
RD
489 # draw the day numbers
490 def DrawNum(self, DC):
491 f = wx.Font(10, self.font, wx.NORMAL, self.bold) # initial font setting
492 self._CalcFontSize(DC, f)
493
d14a1e28
RD
494 cnt_x = 0
495 cnt_y = 1
b25cb7db 496 for val in self.cal_days:
d14a1e28
RD
497 x = self.gridx[cnt_x]
498 y = self.gridy[cnt_y]
499
9472490a 500 self._DrawDayText(x, y, val, f, DC)
d14a1e28 501
b25cb7db
RD
502 if cnt_x < 6:
503 cnt_x = cnt_x + 1
d14a1e28 504 else:
b25cb7db
RD
505 cnt_x = 0
506 cnt_y = cnt_y + 1
d14a1e28 507
9472490a
RD
508 def _DrawDayText(self, x, y, text, font, DC):
509
b25cb7db
RD
510 try:
511 num_val = int(text)
512 num_color = self.cal_sel[num_val][0]
513 except:
514 num_color = self.colors[COLOR_FONT]
515
516 DC.SetTextForeground(MakeColor(num_color))
517 DC.SetFont(font)
518
519 tw,th = DC.GetTextExtent(text)
520
521 if self.num_align_horz == wx.ALIGN_CENTRE:
522 adj_h = (self.cellW - tw)/2
523 elif self.num_align_horz == wx.ALIGN_RIGHT:
524 adj_h = self.cellW - tw
525 else:
526 adj_h = 0 # left alignment
d14a1e28 527
b25cb7db 528 adj_h = adj_h + self.num_indent_horz
d14a1e28 529
b25cb7db
RD
530 if self.num_align_vert == wx.ALIGN_CENTRE:
531 adj_v = (self.cellH - th)/2
532 elif self.num_align_vert == wx.ALIGN_BOTTOM:
533 adj_v = self.cellH - th
534 else:
535 adj_v = 0 # left alignment
d14a1e28 536
b25cb7db 537 adj_v = adj_v + self.num_indent_vert
b881fc78 538
d7403ad2 539 DC.DrawTextPoint(text, (x+adj_h, y+adj_v))
9472490a
RD
540
541 def DrawDayText(self, DC, key):
542 f = wx.Font(10, self.font, wx.NORMAL, self.bold) # initial font setting
543 self._CalcFontSize(DC, f)
544
3e7c6081
RD
545 if key > self.end_pos:
546 key = self.end_pos
547
9472490a
RD
548 val = self.cal_days[key]
549 cnt_x = key % 7
550 cnt_y = int(key / 7)+1
551 x = self.gridx[cnt_x]
552 y = self.gridy[cnt_y]
553 self._DrawDayText(x, y, val, f, DC)
554
d14a1e28 555
c1ea08d3
RD
556 # calculate the dimensions in the center of the drawing area
557 def Center(self):
b25cb7db
RD
558 borderW = self.x_mrg * 2
559 borderH = self.y_mrg + self.y_end + self.title_offset
560
9472490a
RD
561 self.cellW = int((self.sizew - borderW)/7)
562 self.cellH = int((self.sizeh - borderH)/7)
d14a1e28 563
b25cb7db 564 self.restW = ((self.sizew - borderW)%7 ) - 1
d14a1e28 565
c1ea08d3 566 # week title adjustment
9472490a 567 self.weekHdrCellH = int(self.cellH * self.cal_week_scale)
b25cb7db
RD
568 # recalculate the cell height exkl. the week header and
569 # subtracting the size
9472490a 570 self.cellH = int((self.sizeh - borderH - self.weekHdrCellH)/6)
b25cb7db 571
9472490a 572 self.restH = ((self.sizeh - borderH - self.weekHdrCellH)%6 ) - 1
b25cb7db
RD
573 self.calW = self.cellW * 7
574 self.calH = self.cellH * 6 + self.weekHdrCellH
d14a1e28 575
c1ea08d3 576 # highlighted selected days
b25cb7db
RD
577 def DrawSel(self, DC):
578
d14a1e28
RD
579 for key in self.cal_sel.keys():
580 sel_color = self.cal_sel[key][1]
b25cb7db
RD
581 brush = wx.Brush(MakeColor(sel_color), wx.SOLID)
582 DC.SetBrush(brush)
d14a1e28
RD
583
584 if self.hide_grid is False:
b25cb7db 585 DC.SetPen(wx.Pen(MakeColor(self.colors[COLOR_GRID_LINES]), 0))
d14a1e28 586 else:
b25cb7db
RD
587 DC.SetPen(wx.Pen(MakeColor(self.colors[COLOR_BACKGROUND]), 0))
588
d14a1e28
RD
589 nkey = key + self.st_pos -1
590 rect = self.rg[nkey]
b25cb7db 591
d7403ad2 592 DC.DrawRectangleRect(rect)
d14a1e28 593
c1ea08d3 594 # calculate and draw the grid lines
b25cb7db
RD
595 def DrawGrid(self, DC):
596 DC.SetPen(wx.Pen(MakeColor(self.colors[COLOR_GRID_LINES]), 0))
d14a1e28
RD
597
598 self.gridx = []
599 self.gridy = []
600
601 self.x_st = self.cx_st + self.x_mrg
c1ea08d3
RD
602 # start postion of draw
603 self.y_st = self.cy_st + self.y_mrg + self.title_offset
b25cb7db 604
d14a1e28
RD
605 x1 = self.x_st
606 y1 = self.y_st
b25cb7db 607 y2 = y1 + self.calH + self.restH
b881fc78 608
d14a1e28 609 for i in range(8):
b25cb7db
RD
610 if i == 7:
611 x1 = x1 + self.restW
612
d14a1e28 613 if self.hide_grid is False:
d7403ad2 614 DC.DrawLinePoint((x1, y1), (x1, y2))
b25cb7db 615
d14a1e28 616 self.gridx.append(x1)
b25cb7db
RD
617
618 x1 = x1 + self.cellW
d14a1e28
RD
619
620 x1 = self.x_st
621 y1 = self.y_st
b25cb7db 622 x2 = x1 + self.calW + self.restW
b881fc78 623
d14a1e28 624 for i in range(8):
b25cb7db
RD
625 if i == 7:
626 y1 = y1 + self.restH
627
d14a1e28 628 if self.hide_grid is False:
d7403ad2 629 DC.DrawLinePoint((x1, y1), (x2, y1))
b881fc78 630
d14a1e28 631 self.gridy.append(y1)
b881fc78 632
d14a1e28 633 if i == 0:
b25cb7db 634 y1 = y1 + self.weekHdrCellH
d14a1e28 635 else:
b25cb7db
RD
636 y1 = y1 + self.cellH
637
638 def GetColor(self, name):
639 return MakeColor(self.colors[name])
d14a1e28 640
b25cb7db
RD
641 def SetColor(self, name, value):
642 self.colors[name] = MakeColor(value)
d14a1e28
RD
643
644class PrtCalDraw(CalDraw):
645 def InitValues(self):
646 self.rg = {}
647 self.cal_sel = {}
c1ea08d3
RD
648 # start draw border location
649 self.set_cx_st = 1.0
d14a1e28
RD
650 self.set_cy_st = 1.0
651
c1ea08d3
RD
652 # draw offset position
653 self.set_y_mrg = 0.2
d14a1e28
RD
654 self.set_x_mrg = 0.2
655 self.set_y_end = 0.2
656
b881fc78
RD
657 # calculate the dimensions in the center of the drawing area
658 def SetPSize(self, pwidth, pheight):
d14a1e28
RD
659 self.pwidth = int(pwidth)/self.scale
660 self.pheight = int(pheight)/self.scale
661
662 def SetPreview(self, preview):
663 self.preview = preview
664
9472490a
RD
665class Calendar( wx.PyControl ):
666 def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.Size(200,200),
667 style= 0, validator=wx.DefaultValidator,
668 name= "calendar"):
669 wx.PyControl.__init__(self, parent, id, pos, size, style | wx.WANTS_CHARS, validator, name)
d14a1e28 670
9472490a 671 self.hasFocus = False
c1ea08d3 672 # set the calendar control attributes
d14a1e28 673
d14a1e28 674 self.hide_grid = False
d14a1e28
RD
675 self.hide_title = False
676 self.show_weekend = False
677 self.cal_type = "NORMAL"
b25cb7db
RD
678 self.outer_border = True
679 self.num_align_horz = wx.ALIGN_CENTRE
680 self.num_align_vert = wx.ALIGN_CENTRE
681 self.colors = DefaultColors()
682 self.set_x_mrg = 1
683 self.set_y_mrg = 1
684 self.set_y_end = 1
d14a1e28
RD
685
686 self.select_list = []
687
b25cb7db 688 self.SetBackgroundColour(MakeColor(self.colors[COLOR_BACKGROUND]))
b881fc78
RD
689 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftEvent)
690 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDEvent)
691 self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightEvent)
692 self.Bind(wx.EVT_RIGHT_DCLICK, self.OnRightDEvent)
9472490a
RD
693 self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
694 self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
695 self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
d14a1e28
RD
696
697 self.sel_key = None # last used by
698 self.sel_lst = [] # highlighted selected days
699
c1ea08d3
RD
700 # default calendar for current month
701 self.SetNow()
d14a1e28
RD
702
703 self.size = None
704 self.set_day = None
705
b881fc78
RD
706 self.Bind(wx.EVT_PAINT, self.OnPaint)
707 self.Bind(wx.EVT_SIZE, self.OnSize)
9472490a
RD
708
709 def AcceptsFocus(self):
710 return self.IsShown() and self.IsEnabled()
711
b25cb7db
RD
712 def GetColor(self, name):
713 return MakeColor(self.colors[name])
714
715 def SetColor(self, name, value):
716 self.colors[name] = MakeColor(value)
717
c1ea08d3 718 # control some of the main calendar attributes
d14a1e28
RD
719
720 def HideTitle(self):
721 self.hide_title = True
722
723 def HideGrid(self):
724 self.hide_grid = True
725
c1ea08d3 726 # determine the calendar rectangle click area and draw a selection
d14a1e28
RD
727
728 def ProcessClick(self, event):
729 self.x, self.y = event.GetX(), event.GetY()
730 key = self.GetDayHit(self.x, self.y)
731 self.SelectDay(key)
732
c1ea08d3 733 # tab mouse click events and process
d14a1e28
RD
734
735 def OnLeftEvent(self, event):
736 self.click = 'LEFT'
737 self.shiftkey = event.ShiftDown()
738 self.ctrlkey = event.ControlDown()
739 self.ProcessClick(event)
740
741 def OnLeftDEvent(self, event):
742 self.click = 'DLEFT'
743 self.ProcessClick(event)
744
745 def OnRightEvent(self, event):
746 self.click = 'RIGHT'
747 self.ProcessClick(event)
748
749 def OnRightDEvent(self, event):
750 self.click = 'DRIGHT'
751 self.ProcessClick(event)
752
9472490a
RD
753 def OnSetFocus(self, event):
754 self.hasFocus = True
755 self.DrawFocusIndicator(True)
756
757 def OnKillFocus(self, event):
758 self.hasFocus = False
759 self.DrawFocusIndicator(False)
760
761 def OnKeyDown(self, event):
762 if not self.hasFocus:
763 event.Skip()
764 return
765
766 key_code = event.KeyCode()
767
768 if key_code == wx.WXK_TAB:
769 forward = not event.ShiftDown()
770 ne = wx.NavigationKeyEvent()
771 ne.SetDirection(forward)
772 ne.SetCurrentFocus(self)
773 ne.SetEventObject(self)
774 self.GetParent().GetEventHandler().ProcessEvent(ne)
775 event.Skip()
776 return
777
778 delta = None
779
780 if key_code == wx.WXK_UP:
781 delta = -7
782 elif key_code == wx.WXK_DOWN:
783 delta = 7
784 elif key_code == wx.WXK_LEFT:
785 delta = -1
786 elif key_code == wx.WXK_RIGHT:
787 delta = 1
788 elif key_code == wx.WXK_HOME:
789 curDate = wx.DateTimeFromDMY(int(self.cal_days[self.sel_key]),self.month - 1,self.year)
790 newDate = wx.DateTime_Now()
791 ts = newDate - curDate
792 delta = ts.GetDays()
793
794 if delta <> None:
795 curDate = wx.DateTimeFromDMY(int(self.cal_days[self.sel_key]),self.month - 1,self.year)
796 timeSpan = wx.TimeSpan_Days(delta)
797 newDate = curDate + timeSpan
798
799 if curDate.GetMonth() == newDate.GetMonth():
800 self.set_day = newDate.GetDay()
801 key = self.sel_key + delta
802 self.SelectDay(key)
803 else:
804 self.month = newDate.GetMonth() + 1
805 self.year = newDate.GetYear()
806 self.set_day = newDate.GetDay()
807 self.sel_key = None
808 self.DoDrawing(wx.ClientDC(self))
809
810 event.Skip()
811
d14a1e28
RD
812 def SetSize(self, set_size):
813 self.size = set_size
814
815 def SetSelDay(self, sel):
c1ea08d3
RD
816 # list of highlighted days
817 self.sel_lst = sel
d14a1e28 818
c1ea08d3 819 # get the current date
d14a1e28
RD
820 def SetNow(self):
821 dt = now()
822 self.month = dt.month
823 self.year = dt.year
824 self.day = dt.day
825
c1ea08d3 826 # set the current day
d14a1e28
RD
827 def SetCurrentDay(self):
828 self.SetNow()
829 self.set_day = self.day
830
c1ea08d3 831 # get the date, day, month, year set in calendar
d14a1e28
RD
832
833 def GetDate(self):
834 return self.day, self.month, self.year
835
836 def GetDay(self):
837 return self.day
838
839 def GetMonth(self):
840 return self.month
841
842 def GetYear(self):
843 return self.year
844
c1ea08d3 845 # set the day, month, and year
d14a1e28
RD
846
847 def SetDayValue(self, day):
848 self.set_day = day
849
850 def SetMonth(self, month):
851 if month >= 1 and month <= 12:
852 self.month = month
853 else:
854 self.month = 1
855 self.set_day = None
856
857 def SetYear(self, year):
858 self.year = year
859
c1ea08d3 860 # increment year and month
d14a1e28
RD
861
862 def IncYear(self):
863 self.year = self.year + 1
864 self.set_day = None
865
866 def DecYear(self):
867 self.year = self.year - 1
868 self.set_day = None
869
870 def IncMonth(self):
871 self.month = self.month + 1
872 if self.month > 12:
873 self.month = 1
874 self.year = self.year + 1
875 self.set_day = None
876
877 def DecMonth(self):
878 self.month = self.month - 1
879 if self.month < 1:
880 self.month = 12
881 self.year = self.year - 1
882 self.set_day = None
883
c1ea08d3 884 # test to see if the selection has a date and create event
d14a1e28
RD
885
886 def TestDay(self, key):
887 try:
b25cb7db 888 self.day = int(self.cal_days[key])
d14a1e28
RD
889 except:
890 return None
b25cb7db 891
d14a1e28
RD
892 if self.day == "":
893 return None
894 else:
b881fc78
RD
895 # Changed 12/1/03 by jmg (see above) to support 2.5 event binding
896 evt = wx.PyCommandEvent(wxEVT_COMMAND_PYCALENDAR_DAY_CLICKED, self.GetId())
d14a1e28
RD
897 evt.click, evt.day, evt.month, evt.year = self.click, self.day, self.month, self.year
898 evt.shiftkey = self.shiftkey
899 evt.ctrlkey = self.ctrlkey
900 self.GetEventHandler().ProcessEvent(evt)
901
902 self.set_day = self.day
903 return key
904
c1ea08d3 905 # find the clicked area rectangle
d14a1e28
RD
906
907 def GetDayHit(self, mx, my):
908 for key in self.rg.keys():
909 val = self.rg[key]
b881fc78
RD
910 ms_rect = wx.Rect(mx, my, 1, 1)
911 if wx.IntersectRect(ms_rect, val) is not None:
d14a1e28
RD
912 result = self.TestDay(key)
913 return result
b881fc78 914
d14a1e28
RD
915 return None
916
c1ea08d3 917 # calendar drawing
d14a1e28 918
c1ea08d3
RD
919 def SetWeekColor(self, font_color, week_color):
920 # set font and background color for week title
b25cb7db
RD
921 self.colors[COLOR_HEADER_FONT] = MakeColor(font_color)
922 self.colors[COLOR_HEADER_BACKGROUND] = MakeColor(week_color)
923 self.colors[COLOR_3D_LIGHT] = MakeColor(week_color)
924 self.colors[COLOR_3D_DARK] = MakeColor(week_color)
925
926 def SetTextAlign(self, vert, horz):
927 self.num_align_horz = horz
928 self.num_align_vert = vert
929
d14a1e28
RD
930 def AddSelect(self, list, font_color, back_color):
931 list_val = [list, font_color, back_color]
932 self.select_list.append(list_val)
933
934 def ShowWeekEnd(self):
c1ea08d3
RD
935 # highlight weekend
936 self.show_weekend = True
d14a1e28
RD
937
938 def SetBusType(self):
939 self.cal_type = "BUS"
940
941 def OnSize(self, evt):
942 self.Refresh(False)
943 evt.Skip()
944
945 def OnPaint(self, event):
b881fc78 946 DC = wx.PaintDC(self)
d14a1e28
RD
947 self.DoDrawing(DC)
948
949 def DoDrawing(self, DC):
b25cb7db 950 #DC = wx.PaintDC(self)
d14a1e28
RD
951 DC.BeginDrawing()
952
b25cb7db
RD
953 try:
954 cal = self.caldraw
955 except:
956 self.caldraw = CalDraw(self)
957 cal = self.caldraw
d14a1e28 958
d14a1e28 959 cal.hide_grid = self.hide_grid
d14a1e28
RD
960 cal.hide_title = self.hide_title
961 cal.show_weekend = self.show_weekend
962 cal.cal_type = self.cal_type
b25cb7db
RD
963 cal.outer_border = self.outer_border
964 cal.num_align_horz = self.num_align_horz
965 cal.num_align_vert = self.num_align_vert
966 cal.colors = self.colors
d14a1e28
RD
967
968 if self.size is None:
969 size = self.GetClientSize()
970 else:
971 size = self.size
972
c1ea08d3 973 # drawing attributes
d14a1e28 974
d14a1e28
RD
975 cal.SetSize(size)
976 cal.SetCal(self.year, self.month)
b881fc78 977
b25cb7db
RD
978 # these have to set after SetCal as SetCal would overwrite them again.
979 cal.set_x_mrg = self.set_x_mrg
980 cal.set_y_mrg = self.set_y_mrg
981 cal.set_y_end = self.set_y_end
982
d14a1e28
RD
983 for val in self.select_list:
984 cal.AddSelect(val[0], val[1], val[2])
985
986 cal.DrawCal(DC, self.sel_lst)
987
988 self.rg = cal.GetRect()
b25cb7db 989 self.cal_days = cal.GetCal()
d14a1e28
RD
990 self.st_pos = cal.GetOffset()
991 self.ymax = DC.MaxY()
992
993 if self.set_day != None:
994 self.SetDay(self.set_day)
b881fc78 995
d14a1e28
RD
996 DC.EndDrawing()
997
c1ea08d3 998 # draw the selection rectangle
9472490a
RD
999 def DrawFocusIndicator(self, draw):
1000 DC = wx.ClientDC(self)
1001 try:
1002 if draw == True:
1003 self.caldraw.DrawFocusIndicator(DC)
1004 else:
1005 self.caldraw.DrawBorder(DC,True)
1006 except:
1007 pass
1008
1009 def DrawRect(self, key, bgcolor = 'WHITE', fgcolor= 'PINK',width = 0):
1010 if key == None:
1011 return
1012
1013 DC = wx.ClientDC(self)
1014 DC.BeginDrawing()
1015
1016 brush = wx.Brush(MakeColor(bgcolor))
1017 DC.SetBrush(brush)
1018
1019 DC.SetPen(wx.TRANSPARENT_PEN)
1020
1021 rect = self.rg[key]
d7403ad2 1022 DC.DrawRectangle(rect.x+1, rect.y+1, rect.width-2, rect.height-2)
9472490a
RD
1023
1024 self.caldraw.DrawDayText(DC,key)
1025
1026 DC.EndDrawing()
1027
1028 def DrawRectOrg(self, key, fgcolor = 'BLACK', width = 0):
d14a1e28
RD
1029 if key == None:
1030 return
b881fc78
RD
1031
1032 DC = wx.ClientDC(self)
d14a1e28
RD
1033 DC.BeginDrawing()
1034
b881fc78 1035 brush = wx.Brush(wx.Colour(0, 0xFF, 0x80), wx.TRANSPARENT)
d14a1e28 1036 DC.SetBrush(brush)
b25cb7db
RD
1037
1038 try:
1039 DC.SetPen(wx.Pen(MakeColor(fgcolor), width))
1040 except:
1041 DC.SetPen(wx.Pen(MakeColor(self.GetColor(COLOR_GRID_LINES)), width))
d14a1e28
RD
1042
1043 rect = self.rg[key]
d7403ad2 1044 DC.DrawRectangleRect(rect)
d14a1e28
RD
1045
1046 DC.EndDrawing()
1047
c1ea08d3 1048 # set the day selection
d14a1e28
RD
1049
1050 def SetDay(self, day):
9472490a
RD
1051 d = day + self.st_pos - 1
1052 self.SelectDay(d)
d14a1e28 1053
9472490a
RD
1054 def IsDayInWeekend(self, key):
1055 try:
1056 t = Date(self.year, self.month, 1)
1057
1058 day = self.cal_days[key]
1059 day = int(day) + t.day_of_week
1060
1061 if day % 7 == 6 or day % 7 == 0:
1062 return True
1063 except:
1064 return False
1065
d14a1e28
RD
1066 def SelectDay(self, key):
1067 sel_size = 1
c1ea08d3 1068 # clear large selection
9472490a
RD
1069
1070 if self.sel_key != None:
1071 (cfont, bgcolor) = self.__GetColorsForDay(self.sel_key)
1072 self.DrawRect(self.sel_key, bgcolor,cfont, sel_size)
b881fc78 1073
9472490a 1074 self.DrawRect(key, self.GetColor(COLOR_HIGHLIGHT_BACKGROUND), self.GetColor(COLOR_HIGHLIGHT_FONT), sel_size)
d14a1e28 1075
c1ea08d3
RD
1076 # store last used by
1077 self.sel_key = key
d14a1e28
RD
1078 self.select_day = None
1079
1080 def ClearDsp(self):
1081 self.Clear()
b25cb7db
RD
1082 def SetMargin(self, xmarg, ymarg):
1083 self.set_x_mrg = xmarg
1084 self.set_y_mrg = ymarg
1085 self.set_y_end = ymarg
9472490a
RD
1086 def __GetColorsForDay(self, key):
1087 cfont = self.GetColor(COLOR_FONT)
1088 bgcolor = self.GetColor(COLOR_BACKGROUND)
1089
1090 if self.IsDayInWeekend(key) is True and self.show_weekend is True:
1091 cfont = self.GetColor(COLOR_WEEKEND_FONT)
1092 bgcolor = self.GetColor(COLOR_WEEKEND_BACKGROUND)
1093
1094 try:
1095 dayIdx = int(self.cal_days[key])
1096 (cfont, bgcolor) = self.caldraw.cal_sel[dayIdx]
1097 except:
1098 pass
1099
1100 return (cfont, bgcolor)
d14a1e28 1101
b881fc78 1102class CalenDlg(wx.Dialog):
d14a1e28 1103 def __init__(self, parent, month=None, day = None, year=None):
b881fc78 1104 wx.Dialog.__init__(self, parent, -1, "Event Calendar", wx.DefaultPosition, (280, 360))
d14a1e28 1105
c1ea08d3
RD
1106 # set the calendar and attributes
1107 self.calend = Calendar(self, -1, (20, 60), (240, 200))
b881fc78 1108
d14a1e28
RD
1109 if month == None:
1110 self.calend.SetCurrentDay()
1111 start_month = self.calend.GetMonth()
1112 start_year = self.calend.GetYear()
1113 else:
1114 self.calend.month = start_month = month
1115 self.calend.year = start_year = year
1116 self.calend.SetDayValue(day)
1117
1118 self.calend.HideTitle()
1119 self.ResetDisplay()
1120
c1ea08d3 1121 # get month list from DateTime
d14a1e28
RD
1122 monthlist = GetMonthList()
1123
c1ea08d3 1124 # select the month
b881fc78
RD
1125 self.date = wx.ComboBox(self, -1, Month[start_month], (20, 20), (90, -1),
1126 monthlist, wx.CB_DROPDOWN)
1127 self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.date)
d14a1e28 1128
c1ea08d3 1129 # alternate spin button to control the month
d14a1e28 1130 h = self.date.GetSize().height
b881fc78 1131 self.m_spin = wx.SpinButton(self, -1, (130, 20), (h*2, h), wx.SP_VERTICAL)
d14a1e28
RD
1132 self.m_spin.SetRange(1, 12)
1133 self.m_spin.SetValue(start_month)
b881fc78 1134 self.Bind(wx.EVT_SPIN, self.OnMonthSpin, self.m_spin)
d14a1e28 1135
c1ea08d3 1136 # spin button to control the year
b881fc78 1137 self.dtext = wx.TextCtrl(self, -1, str(start_year), (160, 20), (60, -1))
d14a1e28
RD
1138 h = self.dtext.GetSize().height
1139
b881fc78 1140 self.y_spin = wx.SpinButton(self, -1, (220, 20), (h*2, h), wx.SP_VERTICAL)
d14a1e28
RD
1141 self.y_spin.SetRange(1980, 2010)
1142 self.y_spin.SetValue(start_year)
1143
b881fc78
RD
1144 self.Bind(wx.EVT_SPIN, self.OnYrSpin, self.y_spin)
1145 self.Bind(EVT_CALENDAR, self.MouseClick, self.calend)
d14a1e28
RD
1146
1147 x_pos = 50
1148 y_pos = 280
b881fc78 1149 but_size = (60, 25)
d14a1e28 1150
b881fc78
RD
1151 btn = wx.Button(self, -1, ' Ok ', (x_pos, y_pos), but_size)
1152 self.Bind(wx.EVT_BUTTON, self.OnOk, btn)
d14a1e28 1153
c1ea08d3 1154 btn = wx.Button(self, -1, ' Close ', (x_pos + 120, y_pos), but_size)
b881fc78 1155 self.Bind(wx.EVT_BUTTON, self.OnCancel, btn)
d14a1e28
RD
1156
1157 def OnOk(self, event):
b881fc78 1158 self.EndModal(wx.ID_OK)
d14a1e28
RD
1159
1160 def OnCancel(self, event):
b881fc78 1161 self.EndModal(wx.ID_CANCEL)
d14a1e28 1162
c1ea08d3 1163 # log the mouse clicks
d14a1e28
RD
1164 def MouseClick(self, evt):
1165 self.month = evt.month
c1ea08d3
RD
1166 # result click type and date
1167 self.result = [evt.click, str(evt.day), Month[evt.month], str(evt.year)]
d14a1e28
RD
1168
1169 if evt.click == 'DLEFT':
b881fc78 1170 self.EndModal(wx.ID_OK)
d14a1e28 1171
c1ea08d3 1172 # month and year spin selection routines
d14a1e28
RD
1173 def OnMonthSpin(self, event):
1174 month = event.GetPosition()
1175 self.date.SetValue(Month[month])
1176 self.calend.SetMonth(month)
1177 self.calend.Refresh()
1178
1179 def OnYrSpin(self, event):
1180 year = event.GetPosition()
1181 self.dtext.SetValue(str(year))
1182 self.calend.SetYear(year)
1183 self.calend.Refresh()
1184
1185 def EvtComboBox(self, event):
1186 name = event.GetString()
1187 monthval = self.date.FindString(name)
1188 self.m_spin.SetValue(monthval+1)
1189
1190 self.calend.SetMonth(monthval+1)
1191 self.ResetDisplay()
1192
c1ea08d3 1193 # set the calendar for highlighted days
d14a1e28
RD
1194
1195 def ResetDisplay(self):
1196 month = self.calend.GetMonth()
1197 self.calend.Refresh()
1198
1fded56b 1199
1fded56b 1200