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