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