]>
Commit | Line | Data |
---|---|---|
944930d5 | 1 | #---------------------------------------------------------------------------- |
95bfd958 | 2 | # Name: Calendar.py |
f6bcfd97 | 3 | # Purpose: Calendar control display testing on panel for wxPython demo |
944930d5 RD |
4 | # |
5 | # Author: Lorne White (email: lwhite1@planet.eon.net) | |
6 | # | |
96bfd053 | 7 | # Version 0.9 |
49875c53 | 8 | # Date: Feb 26, 2001 |
944930d5 RD |
9 | # Licence: wxWindows license |
10 | #---------------------------------------------------------------------------- | |
8fa876ca RD |
11 | # 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
12 | # | |
13 | # o Updated for wx namespace | |
8fa876ca RD |
14 | # |
15 | # 11/26/2003 - Jeff Grimmett (grimmtooth@softhome.net) | |
16 | # | |
8fa876ca RD |
17 | # o Ugh. AFter updating to the Bind() method, things lock up |
18 | # on various control clicks. Will have to debug. Only seems | |
19 | # to happen on windows with calendar controls, though. | |
20 | # | |
21 | # 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net) | |
22 | # | |
23 | # o Lockup issue clarification: it appears that the spinner is | |
24 | # the culprit. | |
25 | # | |
8fa876ca RD |
26 | |
27 | import os | |
944930d5 | 28 | |
8fa876ca | 29 | import wx |
c1ea08d3 | 30 | import wx.lib.calendar |
944930d5 | 31 | |
8fa876ca | 32 | import images |
944930d5 RD |
33 | |
34 | ||
35 | # highlighted days in month | |
36 | ||
37 | test_days ={ 0: [], | |
38 | 1: [3, 7, 9, 21], | |
39 | 2: [2, 10, 4, 9], | |
40 | 3: [4, 20, 29], | |
41 | 4: [1, 12, 22], | |
42 | 5: [2, 10, 15], | |
43 | 6: [4, 8, 17], | |
44 | 7: [6, 7, 8], | |
45 | 8: [5, 10, 20], | |
46 | 9: [1, 2, 5, 29], | |
47 | 10: [2, 4, 6, 22], | |
48 | 11: [6, 9, 12, 28, 29], | |
49 | 12: [8, 9, 10, 11, 20] } | |
50 | ||
51 | # test of full window calendar control functions | |
52 | ||
53 | def GetMonthList(): | |
8fa876ca | 54 | |
944930d5 | 55 | monthlist = [] |
8fa876ca | 56 | |
944930d5 | 57 | for i in range(13): |
c1ea08d3 | 58 | name = wx.lib.calendar.Month[i] |
8fa876ca | 59 | |
944930d5 RD |
60 | if name != None: |
61 | monthlist.append(name) | |
8fa876ca | 62 | |
944930d5 RD |
63 | return monthlist |
64 | ||
8fa876ca | 65 | class TestPanel(wx.Panel): |
f6bcfd97 | 66 | def __init__(self, parent, log, frame): |
8fa876ca | 67 | wx.Panel.__init__(self, parent, -1) |
944930d5 RD |
68 | |
69 | self.log = log | |
f6bcfd97 | 70 | self.frame = frame |
944930d5 | 71 | |
c1ea08d3 | 72 | self.calend = wx.lib.calendar.Calendar(self, -1, (100, 50), (200, 180)) |
944930d5 | 73 | |
49875c53 RD |
74 | # start_month = 2 # preselect the date for calendar |
75 | # start_year = 2001 | |
76 | ||
77 | start_month = self.calend.GetMonth() # get the current month & year | |
78 | start_year = self.calend.GetYear() | |
944930d5 | 79 | |
8fa876ca | 80 | # month list from DateTime module |
944930d5 RD |
81 | |
82 | monthlist = GetMonthList() | |
83 | ||
c1ea08d3 | 84 | self.date = wx.ComboBox(self, -1, "", |
8fa876ca RD |
85 | (100, 20), (90, -1), |
86 | monthlist, wx.CB_DROPDOWN) | |
87 | ||
eb0f373c | 88 | self.date.SetSelection(start_month-1) |
c1ea08d3 | 89 | self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.date) |
944930d5 | 90 | |
8fa876ca | 91 | # set start month and year |
944930d5 RD |
92 | |
93 | self.calend.SetMonth(start_month) | |
94 | self.calend.SetYear(start_year) | |
95 | ||
8fa876ca | 96 | # set attributes of calendar |
944930d5 | 97 | |
1e4a197e | 98 | self.calend.hide_title = True |
944930d5 | 99 | self.calend.HideGrid() |
f6bcfd97 | 100 | self.calend.SetWeekColor('WHITE', 'BLACK') |
944930d5 | 101 | |
8fa876ca | 102 | # display routine |
944930d5 RD |
103 | |
104 | self.ResetDisplay() | |
105 | ||
8fa876ca | 106 | # mouse click event |
c1ea08d3 | 107 | self.Bind(wx.lib.calendar.EVT_CALENDAR, self.MouseClick, self.calend) |
944930d5 | 108 | |
8fa876ca | 109 | # scroll bar for month selection |
c1ea08d3 | 110 | self.scroll = wx.ScrollBar(self, -1, (100, 240), (200, 20), wx.SB_HORIZONTAL) |
1e4a197e | 111 | self.scroll.SetScrollbar(start_month-1, 1, 12, 1, True) |
c1ea08d3 | 112 | self.Bind(wx.EVT_COMMAND_SCROLL, self.Scroll, self.scroll) |
944930d5 | 113 | |
8fa876ca | 114 | # spin control for year selection |
944930d5 | 115 | |
8fa876ca | 116 | self.dtext = wx.TextCtrl(self, -1, str(start_year), (200, 20), (60, -1)) |
944930d5 RD |
117 | h = self.dtext.GetSize().height |
118 | ||
c1ea08d3 | 119 | self.spin = wx.SpinButton(self, -1, (270, 20), (h*2, h)) |
944930d5 RD |
120 | self.spin.SetRange(1980, 2010) |
121 | self.spin.SetValue(start_year) | |
c1ea08d3 | 122 | self.Bind(wx.EVT_SPIN, self.OnSpin, self.spin) |
944930d5 | 123 | |
8fa876ca | 124 | # button for calendar dialog test |
944930d5 | 125 | |
8fa876ca | 126 | wx.StaticText(self, -1, "Test Calendar Dialog", (350, 50), (150, -1)) |
944930d5 | 127 | |
96bfd053 | 128 | bmp = images.getCalendarBitmap() |
c1ea08d3 RD |
129 | self.but1 = wx.BitmapButton(self, -1, bmp, (380, 80)) |
130 | self.Bind(wx.EVT_BUTTON, self.TestDlg, self.but1) | |
944930d5 | 131 | |
8fa876ca | 132 | # button for calendar window test |
944930d5 | 133 | |
8fa876ca | 134 | wx.StaticText(self, -1, "Test Calendar Window", (350, 150), (150, -1)) |
944930d5 | 135 | |
c1ea08d3 RD |
136 | self.but2 = wx.BitmapButton(self, -1, bmp, (380, 180)) |
137 | self.Bind(wx.EVT_BUTTON, self.TestFrame, self.but2) | |
944930d5 | 138 | |
8fa876ca | 139 | wx.StaticText(self, -1, "Test Calendar Print", (350, 250), (150, -1)) |
f6bcfd97 | 140 | |
c1ea08d3 RD |
141 | self.but3 = wx.BitmapButton(self, -1, bmp, (380, 280)) |
142 | self.Bind(wx.EVT_BUTTON, self.OnPreview, self.but3) | |
f6bcfd97 | 143 | |
8fa876ca | 144 | # calendar dialog |
944930d5 | 145 | |
49875c53 | 146 | def TestDlg(self, event): # test the date dialog |
c1ea08d3 | 147 | dlg = wx.lib.calendar.CalenDlg(self) |
944930d5 | 148 | dlg.Centre() |
8fa876ca RD |
149 | |
150 | if dlg.ShowModal() == wx.ID_OK: | |
49875c53 RD |
151 | result = dlg.result |
152 | day = result[1] | |
153 | month = result[2] | |
154 | year = result[3] | |
155 | new_date = str(month) + '/'+ str(day) + '/'+ str(year) | |
156 | self.log.WriteText('Date Selected: %s\n' % new_date) | |
157 | else: | |
158 | self.log.WriteText('No Date Selected') | |
944930d5 | 159 | |
8fa876ca | 160 | # calendar window test |
944930d5 RD |
161 | |
162 | def TestFrame(self, event): | |
e0473f5f | 163 | frame = CalendFrame(self, -1, "Test Calendar", self.log) |
1e4a197e RD |
164 | frame.Show(True) |
165 | return True | |
944930d5 | 166 | |
8fa876ca | 167 | # calendar print preview |
f6bcfd97 BP |
168 | |
169 | def OnPreview(self, event): | |
170 | month = self.calend.GetMonth() | |
171 | year = self.calend.GetYear() | |
172 | ||
173 | prt = PrintCalend(self.frame, month, year) | |
174 | prt.Preview() | |
175 | ||
8fa876ca | 176 | # month and year control events |
944930d5 RD |
177 | |
178 | def OnSpin(self, event): | |
179 | year = event.GetPosition() | |
180 | self.dtext.SetValue(str(year)) | |
181 | self.calend.SetYear(year) | |
182 | self.calend.Refresh() | |
183 | ||
184 | def EvtComboBox(self, event): | |
185 | name = event.GetString() | |
186 | self.log.WriteText('EvtComboBox: %s\n' % name) | |
187 | monthval = self.date.FindString(name) | |
1e4a197e | 188 | self.scroll.SetScrollbar(monthval, 1, 12, 1, True) |
944930d5 RD |
189 | |
190 | self.calend.SetMonth(monthval+1) | |
191 | self.ResetDisplay() | |
192 | ||
193 | def Scroll(self, event): | |
194 | value = self.scroll.GetThumbPosition() | |
195 | monthval = int(value)+1 | |
196 | self.calend.SetMonth(monthval) | |
197 | self.ResetDisplay() | |
198 | self.log.WriteText('Month: %s\n' % value) | |
199 | ||
c1ea08d3 | 200 | name = wx.lib.calendar.Month[monthval] |
944930d5 RD |
201 | self.date.SetValue(name) |
202 | ||
8fa876ca | 203 | # log mouse events |
944930d5 RD |
204 | |
205 | def MouseClick(self, evt): | |
206 | text = '%s CLICK %02d/%02d/%d' % (evt.click, evt.day, evt.month, evt.year) # format date | |
207 | self.log.WriteText('Date Selected: ' + text + '\n') | |
208 | ||
944930d5 | 209 | |
8fa876ca | 210 | # set the highlighted days for the calendar |
944930d5 RD |
211 | |
212 | def ResetDisplay(self): | |
213 | month = self.calend.GetMonth() | |
8fa876ca | 214 | |
944930d5 RD |
215 | try: |
216 | set_days = test_days[month] | |
217 | except: | |
218 | set_days = [1, 5, 12] | |
219 | ||
f6bcfd97 | 220 | self.calend.AddSelect([4, 11], 'BLUE', 'WHITE') |
944930d5 RD |
221 | self.calend.SetSelDay(set_days) |
222 | self.calend.Refresh() | |
223 | ||
8fa876ca | 224 | # increment and decrement toolbar controls |
944930d5 RD |
225 | |
226 | def OnIncYear(self, event): | |
227 | self.calend.IncYear() | |
228 | self.ResetDisplay() | |
229 | ||
230 | def OnDecYear(self, event): | |
231 | self.calend.DecYear() | |
232 | self.ResetDisplay() | |
233 | ||
234 | def OnIncMonth(self, event): | |
235 | self.calend.IncMonth() | |
236 | self.ResetDisplay() | |
237 | ||
238 | def OnDecMonth(self, event): | |
239 | self.calend.DecMonth() | |
240 | self.ResetDisplay() | |
241 | ||
242 | def OnCurrent(self, event): | |
243 | self.calend.SetCurrentDay() | |
244 | self.ResetDisplay() | |
245 | ||
944930d5 RD |
246 | # test of full window calendar control functions |
247 | ||
8fa876ca | 248 | class CalendFrame(wx.Frame): |
944930d5 | 249 | def __init__(self, parent, id, title, log): |
8fa876ca RD |
250 | wx.Frame.__init__(self, parent, id, title, size=(400, 400), |
251 | style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE) | |
252 | ||
253 | self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) | |
944930d5 RD |
254 | |
255 | self.log = log | |
256 | self.CreateStatusBar() | |
8fa876ca RD |
257 | self.mainmenu = wx.MenuBar() |
258 | menu = wx.Menu() | |
944930d5 RD |
259 | |
260 | menu = self.MakeFileMenu() | |
261 | self.mainmenu.Append(menu, '&File') | |
262 | ||
263 | self.MakeToolMenu() # toolbar | |
264 | ||
265 | self.SetMenuBar(self.mainmenu) | |
c1ea08d3 | 266 | self.calend = wx.lib.calendar.Calendar(self, -1) |
944930d5 RD |
267 | self.calend.SetCurrentDay() |
268 | self.calend.grid_color = 'BLUE' | |
f6bcfd97 BP |
269 | self.calend.SetBusType() |
270 | # self.calend.ShowWeekEnd() | |
271 | ||
944930d5 RD |
272 | self.ResetDisplay() |
273 | ||
c1ea08d3 | 274 | self.Bind(wx.lib.calendar.EVT_CALENDAR, self.MouseClick, self.calend) |
944930d5 RD |
275 | |
276 | def MouseClick(self, evt): | |
277 | text = '%s CLICK %02d/%02d/%d' % (evt.click, evt.day, evt.month, evt.year) # format date | |
278 | self.log.WriteText('Date Selected: ' + text + '\n') | |
279 | ||
280 | def OnCloseWindow(self, event): | |
281 | self.Destroy() | |
282 | ||
283 | def ResetDisplay(self): | |
284 | month = self.calend.GetMonth() | |
8fa876ca | 285 | |
944930d5 RD |
286 | try: |
287 | set_days = test_days[month] | |
288 | except: | |
289 | set_days = [1, 5, 12] | |
290 | ||
f6bcfd97 BP |
291 | self.calend.AddSelect([2, 16], 'GREEN', 'WHITE') |
292 | ||
944930d5 RD |
293 | self.calend.SetSelDay(set_days) |
294 | self.calend.Refresh() | |
295 | ||
296 | def OnIncYear(self, event): | |
297 | self.calend.IncYear() | |
298 | self.ResetDisplay() | |
299 | ||
300 | def OnDecYear(self, event): | |
301 | self.calend.DecYear() | |
302 | self.ResetDisplay() | |
303 | ||
304 | def OnIncMonth(self, event): | |
305 | self.calend.IncMonth() | |
306 | self.ResetDisplay() | |
307 | ||
308 | def OnDecMonth(self, event): | |
309 | self.calend.DecMonth() | |
310 | self.ResetDisplay() | |
311 | ||
312 | def OnCurrent(self, event): | |
313 | self.calend.SetCurrentDay() | |
314 | self.ResetDisplay() | |
315 | ||
316 | def MakeFileMenu(self): | |
8fa876ca | 317 | menu = wx.Menu() |
944930d5 | 318 | |
8fa876ca | 319 | mID = wx.NewId() |
944930d5 | 320 | menu.Append(mID, 'Decrement', 'Next') |
8fa876ca | 321 | self.Bind(wx.EVT_MENU, self.OnDecMonth, id=mID) |
944930d5 | 322 | |
8fa876ca | 323 | mID = wx.NewId() |
944930d5 | 324 | menu.Append(mID, 'Increment', 'Dec') |
8fa876ca | 325 | self.Bind(wx.EVT_MENU, self.OnIncMonth, id=mID) |
944930d5 RD |
326 | |
327 | menu.AppendSeparator() | |
328 | ||
8fa876ca | 329 | mID = wx.NewId() |
944930d5 | 330 | menu.Append(mID, 'E&xit', 'Exit') |
8fa876ca | 331 | self.Bind(wx.EVT_MENU, self.OnCloseWindow, id=mID) |
944930d5 RD |
332 | |
333 | return menu | |
334 | ||
335 | def MakeToolMenu(self): | |
8fa876ca | 336 | tb = self.CreateToolBar(wx.TB_HORIZONTAL|wx.NO_BORDER) |
944930d5 | 337 | |
8fa876ca | 338 | mID = wx.NewId() |
96bfd053 | 339 | SetToolPath(self, tb, mID, images.getDbDecBitmap(), 'Dec Year') |
8fa876ca | 340 | self.Bind(wx.EVT_TOOL, self.OnDecYear, id=mID) |
944930d5 | 341 | |
8fa876ca | 342 | mID = wx.NewId() |
96bfd053 | 343 | SetToolPath(self, tb, mID, images.getDecBitmap(), 'Dec Month') |
8fa876ca | 344 | self.Bind(wx.EVT_TOOL, self.OnDecMonth, id=mID) |
944930d5 | 345 | |
8fa876ca | 346 | mID = wx.NewId() |
96bfd053 | 347 | SetToolPath(self, tb, mID, images.getPtBitmap(), 'Current Month') |
8fa876ca | 348 | self.Bind(wx.EVT_TOOL, self.OnCurrent, id=mID) |
49875c53 | 349 | |
8fa876ca | 350 | mID = wx.NewId() |
96bfd053 | 351 | SetToolPath(self, tb, mID, images.getIncBitmap(), 'Inc Month') |
8fa876ca | 352 | self.Bind(wx.EVT_TOOL, self.OnIncMonth, id=mID) |
944930d5 | 353 | |
8fa876ca | 354 | mID = wx.NewId() |
96bfd053 | 355 | SetToolPath(self, tb, mID, images.getDbIncBitmap(), 'Inc Year') |
8fa876ca | 356 | self.Bind(wx.EVT_TOOL, self.OnIncYear, id=mID) |
944930d5 RD |
357 | |
358 | tb.Realize() | |
359 | ||
f6bcfd97 BP |
360 | #--------------------------------------------------------------------------- |
361 | ||
362 | # example class for printing/previewing calendars | |
363 | ||
364 | class PrintCalend: | |
365 | def __init__(self, parent, month, year): | |
366 | self.frame = parent | |
367 | self.month = month | |
368 | self.year = year | |
369 | ||
370 | self.SetParms() | |
371 | self.SetCal() | |
8fa876ca | 372 | self.printData = wx.PrintData() |
f6bcfd97 BP |
373 | |
374 | def SetCal(self): | |
375 | self.grid_color = 'BLUE' | |
376 | self.back_color = 'WHITE' | |
377 | self.sel_color = 'RED' | |
378 | self.high_color = 'LIGHT BLUE' | |
8fa876ca RD |
379 | self.font = wx.SWISS |
380 | self.bold = wx.NORMAL | |
f6bcfd97 | 381 | |
95bfd958 | 382 | self.sel_key = None # last used by |
f6bcfd97 BP |
383 | self.sel_lst = [] # highlighted selected days |
384 | ||
385 | self.size = None | |
1e4a197e RD |
386 | self.hide_title = False |
387 | self.hide_grid = False | |
f6bcfd97 BP |
388 | self.set_day = None |
389 | ||
390 | def SetParms(self): | |
391 | self.ymax = 1 | |
392 | self.xmax = 1 | |
393 | self.page = 1 | |
394 | self.total_pg = 1 | |
395 | ||
396 | self.preview = None | |
397 | self.scale = 1.0 | |
398 | ||
399 | self.pagew = 8.5 | |
400 | self.pageh = 11.0 | |
401 | ||
402 | self.txt_marg = 0.1 | |
403 | self.lf_marg = 0 | |
404 | self.top_marg = 0 | |
405 | ||
406 | self.page = 0 | |
407 | ||
408 | def SetDates(self, month, year): | |
409 | self.month = month | |
410 | self.year = year | |
411 | ||
412 | def SetStyleDef(self, desc): | |
413 | self.style = desc | |
414 | ||
415 | def SetCopies(self, copies): # number of copies of label | |
416 | self.copies = copies | |
417 | ||
418 | def SetStart(self, start): # start position of label | |
419 | self.start = start | |
420 | ||
421 | def Preview(self): | |
422 | printout = SetPrintout(self) | |
423 | printout2 = SetPrintout(self) | |
8fa876ca RD |
424 | self.preview = wx.PrintPreview(printout, printout2, self.printData) |
425 | ||
f6bcfd97 | 426 | if not self.preview.Ok(): |
8fa876ca | 427 | wx.MessageBox("There was a problem printing!", "Printing", wx.OK) |
f6bcfd97 BP |
428 | return |
429 | ||
430 | self.preview.SetZoom(60) # initial zoom value | |
431 | ||
8fa876ca | 432 | frame = wx.PreviewFrame(self.preview, self.frame, "Print preview") |
f6bcfd97 BP |
433 | |
434 | frame.Initialize() | |
435 | frame.SetPosition(self.frame.GetPosition()) | |
436 | frame.SetSize(self.frame.GetSize()) | |
1e4a197e | 437 | frame.Show(True) |
f6bcfd97 BP |
438 | |
439 | def Print(self): | |
8fa876ca | 440 | pdd = wx.PrintDialogData() |
f6bcfd97 | 441 | pdd.SetPrintData(self.printData) |
8fa876ca | 442 | printer = wx.Printer(pdd) |
f6bcfd97 | 443 | printout = SetPrintout(self) |
8fa876ca RD |
444 | frame = wx.Frame(None, -1, "Test") |
445 | ||
f6bcfd97 | 446 | if not printer.Print(frame, printout): |
8fa876ca | 447 | wx.MessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wx.OK) |
f6bcfd97 BP |
448 | else: |
449 | self.printData = printer.GetPrintDialogData().GetPrintData() | |
8fa876ca | 450 | |
f6bcfd97 BP |
451 | printout.Destroy() |
452 | ||
453 | def DoDrawing(self, DC): | |
8fa876ca | 454 | size = DC.GetSize() |
f6bcfd97 BP |
455 | DC.BeginDrawing() |
456 | ||
c1ea08d3 | 457 | cal = wx.lib.calendar.PrtCalDraw(self) |
f6bcfd97 BP |
458 | |
459 | if self.preview is None: | |
460 | cal.SetPSize(size[0]/self.pagew, size[1]/self.pageh) | |
1e4a197e | 461 | cal.SetPreview(False) |
f6bcfd97 BP |
462 | |
463 | else: | |
464 | if self.preview == 1: | |
465 | cal.SetPSize(size[0]/self.pagew, size[1]/self.pageh) | |
466 | else: | |
467 | cal.SetPSize(self.pwidth, self.pheight) | |
468 | ||
469 | cal.SetPreview(self.preview) | |
470 | ||
471 | cal.hide_title = self.hide_title # set the calendar parameters | |
472 | cal.hide_grid = self.hide_grid | |
473 | ||
474 | cal.grid_color = self.grid_color | |
475 | cal.high_color = self.high_color | |
476 | cal.back_color = self.back_color | |
1e4a197e | 477 | cal.outer_border = False |
f6bcfd97 BP |
478 | cal.font = self.font |
479 | cal.bold = self.bold | |
480 | ||
8fa876ca | 481 | cal_size = (3.0, 3.0) |
f6bcfd97 BP |
482 | cal.SetSize(cal_size) |
483 | ||
484 | year, month = self.year, self.month | |
485 | ||
4e6ab75b | 486 | x = 0.5 |
f6bcfd97 BP |
487 | for i in range(2): |
488 | y = 0.5 | |
8fa876ca | 489 | |
f6bcfd97 BP |
490 | for j in range(3): |
491 | cal.SetCal(year, month) # current month | |
492 | cal.SetPos(x, y) | |
493 | ||
494 | try: | |
495 | set_days = test_days[month] | |
496 | except: | |
497 | set_days = [1, 5, 12] | |
498 | ||
499 | cal.AddSelect([2, 16], 'GREEN', 'WHITE') | |
500 | ||
501 | cal.DrawCal(DC, set_days) | |
502 | ||
503 | year, month = self.IncMonth(year, month) | |
504 | y = y + 3.5 | |
8fa876ca | 505 | |
8b9a4190 | 506 | x = x + 4.0 # next column |
f6bcfd97 BP |
507 | |
508 | DC.EndDrawing() | |
509 | ||
510 | self.ymax = DC.MaxY() | |
511 | self.xmax = DC.MaxX() | |
512 | ||
513 | def IncMonth(self, year, month): # next month | |
514 | month = month + 1 | |
8fa876ca | 515 | |
f6bcfd97 BP |
516 | if month > 12: |
517 | month = 1 | |
518 | year = year + 1 | |
519 | ||
520 | return year, month | |
521 | ||
522 | def GetTotalPages(self): | |
523 | self.pg_cnt = 1 | |
524 | return self.pg_cnt | |
525 | ||
526 | def SetPage(self, page): | |
527 | self.page = page | |
528 | ||
529 | def SetPageSize(self, width, height): | |
530 | self.pwidth, self.pheight = width, height | |
531 | ||
532 | def SetTotalSize(self, width, height): | |
533 | self.ptwidth, self.ptheight = width, height | |
534 | ||
535 | def SetPreview(self, preview, scale): | |
536 | self.preview = preview | |
537 | self.scale = scale | |
538 | ||
539 | def SetTotalSize(self, width, height): | |
540 | self.ptwidth = width | |
541 | self.ptheight = height | |
542 | ||
944930d5 | 543 | def SetToolPath(self, tb, id, bmp, title): |
96bfd053 | 544 | tb.AddSimpleTool(id, bmp, title, title) |
944930d5 | 545 | |
8fa876ca | 546 | class SetPrintout(wx.Printout): |
f6bcfd97 | 547 | def __init__(self, canvas): |
8fa876ca | 548 | wx.Printout.__init__(self) |
f6bcfd97 BP |
549 | self.canvas = canvas |
550 | self.end_pg = 1 | |
551 | ||
552 | def OnBeginDocument(self, start, end): | |
553 | return self.base_OnBeginDocument(start, end) | |
554 | ||
555 | def OnEndDocument(self): | |
556 | self.base_OnEndDocument() | |
557 | ||
558 | def HasPage(self, page): | |
559 | if page <= self.end_pg: | |
1e4a197e | 560 | return True |
f6bcfd97 | 561 | else: |
1e4a197e | 562 | return False |
f6bcfd97 BP |
563 | |
564 | def GetPageInfo(self): | |
565 | self.end_pg = self.canvas.GetTotalPages() | |
566 | str_pg = 1 | |
8fa876ca | 567 | |
f6bcfd97 BP |
568 | try: |
569 | end_pg = self.end_pg | |
570 | except: | |
571 | end_pg = 1 | |
8fa876ca | 572 | |
f6bcfd97 BP |
573 | return (str_pg, end_pg, str_pg, end_pg) |
574 | ||
575 | def OnPreparePrinting(self): | |
576 | self.base_OnPreparePrinting() | |
577 | ||
578 | def OnBeginPrinting(self): | |
579 | dc = self.GetDC() | |
580 | ||
581 | self.preview = self.IsPreview() | |
8fa876ca | 582 | |
f6bcfd97 BP |
583 | if (self.preview): |
584 | self.pixelsPerInch = self.GetPPIScreen() | |
585 | else: | |
586 | self.pixelsPerInch = self.GetPPIPrinter() | |
587 | ||
8fa876ca | 588 | (w, h) = dc.GetSize() |
f6bcfd97 BP |
589 | scaleX = float(w) / 1000 |
590 | scaleY = float(h) / 1000 | |
591 | self.printUserScale = min(scaleX, scaleY) | |
592 | ||
593 | self.base_OnBeginPrinting() | |
594 | ||
595 | def GetSize(self): | |
596 | self.psizew, self.psizeh = self.GetPPIPrinter() | |
597 | return self.psizew, self.psizeh | |
598 | ||
599 | def GetTotalSize(self): | |
600 | self.ptsizew, self.ptsizeh = self.GetPageSizePixels() | |
601 | return self.ptsizew, self.ptsizeh | |
602 | ||
603 | def OnPrintPage(self, page): | |
604 | dc = self.GetDC() | |
8fa876ca | 605 | (w, h) = dc.GetSize() |
f6bcfd97 BP |
606 | scaleX = float(w) / 1000 |
607 | scaleY = float(h) / 1000 | |
608 | self.printUserScale = min(scaleX, scaleY) | |
609 | dc.SetUserScale(self.printUserScale, self.printUserScale) | |
610 | ||
611 | self.preview = self.IsPreview() | |
612 | ||
613 | self.canvas.SetPreview(self.preview, self.printUserScale) | |
614 | self.canvas.SetPage(page) | |
615 | ||
616 | self.ptsizew, self.ptsizeh = self.GetPageSizePixels() | |
617 | self.canvas.SetTotalSize(self.ptsizew, self.ptsizeh) | |
618 | ||
619 | self.psizew, self.psizeh = self.GetPPIPrinter() | |
620 | self.canvas.SetPageSize(self.psizew, self.psizeh) | |
621 | ||
622 | self.canvas.DoDrawing(dc) | |
1e4a197e | 623 | return True |
e0473f5f | 624 | |
8fa876ca | 625 | class MyApp(wx.App): |
944930d5 | 626 | def OnInit(self): |
8fa876ca | 627 | frame = CalendFrame(None, -1, "Test Calendar", log) |
1e4a197e | 628 | frame.Show(True) |
944930d5 | 629 | self.SetTopWindow(frame) |
1e4a197e | 630 | return True |
944930d5 RD |
631 | |
632 | #--------------------------------------------------------------------------- | |
633 | ||
634 | def MessageDlg(self, message, type = 'Message'): | |
8fa876ca | 635 | dlg = wx.MessageDialog(self, message, type, wx.OK | wx.ICON_INFORMATION) |
944930d5 RD |
636 | dlg.ShowModal() |
637 | dlg.Destroy() | |
638 | ||
639 | #--------------------------------------------------------------------------- | |
640 | ||
944930d5 | 641 | def runTest(frame, nb, log): |
f6bcfd97 | 642 | win = TestPanel(nb, log, frame) |
944930d5 RD |
643 | return win |
644 | ||
645 | #--------------------------------------------------------------------------- | |
646 | ||
647 | ||
648 | overview = """\ | |
c1ea08d3 RD |
649 | This control provides a Calendar control class for displaying and selecting dates. |
650 | In addition, the class is extended and can be used for printing/previewing. | |
f6bcfd97 | 651 | |
8fa876ca RD |
652 | Additional features include weekend highlighting and business type Monday-Sunday |
653 | format. | |
944930d5 | 654 | |
8fa876ca RD |
655 | See example for various methods used to set display month, year, and highlighted |
656 | dates (different font and background colours). | |
944930d5 RD |
657 | |
658 | by Lorne White | |
659 | ||
660 | """ | |
fd3f2efe RD |
661 | |
662 | ||
663 | ||
664 | ||
665 | if __name__ == '__main__': | |
666 | import sys,os | |
667 | import run | |
8eca4fef | 668 | run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) |
fd3f2efe | 669 |