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