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