1999-11-10 08:03:29 +00:00
|
|
|
#----------------------------------------------------------------------------
|
2004-01-13 03:17:17 +00:00
|
|
|
# Name: Calendar.py
|
2000-07-15 19:51:35 +00:00
|
|
|
# Purpose: Calendar control display testing on panel for wxPython demo
|
1999-11-10 08:03:29 +00:00
|
|
|
#
|
|
|
|
# Author: Lorne White (email: lwhite1@planet.eon.net)
|
|
|
|
#
|
2001-04-09 19:36:36 +00:00
|
|
|
# Version 0.9
|
2001-04-02 05:57:32 +00:00
|
|
|
# Date: Feb 26, 2001
|
1999-11-10 08:03:29 +00:00
|
|
|
# Licence: wxWindows license
|
|
|
|
#----------------------------------------------------------------------------
|
2003-12-09 01:23:28 +00:00
|
|
|
# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o Updated for wx namespace
|
|
|
|
#
|
|
|
|
# 11/26/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o Ugh. AFter updating to the Bind() method, things lock up
|
|
|
|
# on various control clicks. Will have to debug. Only seems
|
|
|
|
# to happen on windows with calendar controls, though.
|
|
|
|
#
|
|
|
|
# 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o Lockup issue clarification: it appears that the spinner is
|
|
|
|
# the culprit.
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
import wx
|
2003-12-18 19:10:26 +00:00
|
|
|
import wx.lib.calendar
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
import images
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
# highlighted days in month
|
|
|
|
|
|
|
|
test_days ={ 0: [],
|
|
|
|
1: [3, 7, 9, 21],
|
|
|
|
2: [2, 10, 4, 9],
|
|
|
|
3: [4, 20, 29],
|
|
|
|
4: [1, 12, 22],
|
|
|
|
5: [2, 10, 15],
|
|
|
|
6: [4, 8, 17],
|
|
|
|
7: [6, 7, 8],
|
|
|
|
8: [5, 10, 20],
|
|
|
|
9: [1, 2, 5, 29],
|
|
|
|
10: [2, 4, 6, 22],
|
|
|
|
11: [6, 9, 12, 28, 29],
|
|
|
|
12: [8, 9, 10, 11, 20] }
|
|
|
|
|
|
|
|
# test of full window calendar control functions
|
|
|
|
|
|
|
|
def GetMonthList():
|
2003-12-09 01:23:28 +00:00
|
|
|
|
1999-11-10 08:03:29 +00:00
|
|
|
monthlist = []
|
2003-12-09 01:23:28 +00:00
|
|
|
|
1999-11-10 08:03:29 +00:00
|
|
|
for i in range(13):
|
2003-12-18 19:10:26 +00:00
|
|
|
name = wx.lib.calendar.Month[i]
|
2003-12-09 01:23:28 +00:00
|
|
|
|
1999-11-10 08:03:29 +00:00
|
|
|
if name != None:
|
|
|
|
monthlist.append(name)
|
2003-12-09 01:23:28 +00:00
|
|
|
|
1999-11-10 08:03:29 +00:00
|
|
|
return monthlist
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
class TestPanel(wx.Panel):
|
2000-07-15 19:51:35 +00:00
|
|
|
def __init__(self, parent, log, frame):
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
self.log = log
|
2000-07-15 19:51:35 +00:00
|
|
|
self.frame = frame
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-18 19:10:26 +00:00
|
|
|
self.calend = wx.lib.calendar.Calendar(self, -1, (100, 50), (200, 180))
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2001-04-02 05:57:32 +00:00
|
|
|
# start_month = 2 # preselect the date for calendar
|
|
|
|
# start_year = 2001
|
|
|
|
|
|
|
|
start_month = self.calend.GetMonth() # get the current month & year
|
|
|
|
start_year = self.calend.GetYear()
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# month list from DateTime module
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
monthlist = GetMonthList()
|
|
|
|
|
2003-12-18 19:10:26 +00:00
|
|
|
self.date = wx.ComboBox(self, -1, "",
|
2003-12-09 01:23:28 +00:00
|
|
|
(100, 20), (90, -1),
|
|
|
|
monthlist, wx.CB_DROPDOWN)
|
|
|
|
|
2002-08-13 23:59:08 +00:00
|
|
|
self.date.SetSelection(start_month-1)
|
2003-12-18 19:10:26 +00:00
|
|
|
self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.date)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# set start month and year
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
self.calend.SetMonth(start_month)
|
|
|
|
self.calend.SetYear(start_year)
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# set attributes of calendar
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-03-25 06:35:27 +00:00
|
|
|
self.calend.hide_title = True
|
1999-11-10 08:03:29 +00:00
|
|
|
self.calend.HideGrid()
|
2000-07-15 19:51:35 +00:00
|
|
|
self.calend.SetWeekColor('WHITE', 'BLACK')
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# display routine
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
self.ResetDisplay()
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# mouse click event
|
2003-12-18 19:10:26 +00:00
|
|
|
self.Bind(wx.lib.calendar.EVT_CALENDAR, self.MouseClick, self.calend)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# scroll bar for month selection
|
2003-12-18 19:10:26 +00:00
|
|
|
self.scroll = wx.ScrollBar(self, -1, (100, 240), (200, 20), wx.SB_HORIZONTAL)
|
2003-03-25 06:35:27 +00:00
|
|
|
self.scroll.SetScrollbar(start_month-1, 1, 12, 1, True)
|
2003-12-18 19:10:26 +00:00
|
|
|
self.Bind(wx.EVT_COMMAND_SCROLL, self.Scroll, self.scroll)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# spin control for year selection
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
self.dtext = wx.TextCtrl(self, -1, str(start_year), (200, 20), (60, -1))
|
1999-11-10 08:03:29 +00:00
|
|
|
h = self.dtext.GetSize().height
|
|
|
|
|
2003-12-18 19:10:26 +00:00
|
|
|
self.spin = wx.SpinButton(self, -1, (270, 20), (h*2, h))
|
1999-11-10 08:03:29 +00:00
|
|
|
self.spin.SetRange(1980, 2010)
|
|
|
|
self.spin.SetValue(start_year)
|
2003-12-18 19:10:26 +00:00
|
|
|
self.Bind(wx.EVT_SPIN, self.OnSpin, self.spin)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# button for calendar dialog test
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.StaticText(self, -1, "Test Calendar Dialog", (350, 50), (150, -1))
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2001-04-09 19:36:36 +00:00
|
|
|
bmp = images.getCalendarBitmap()
|
2003-12-18 19:10:26 +00:00
|
|
|
self.but1 = wx.BitmapButton(self, -1, bmp, (380, 80))
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.TestDlg, self.but1)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# button for calendar window test
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.StaticText(self, -1, "Test Calendar Window", (350, 150), (150, -1))
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-18 19:10:26 +00:00
|
|
|
self.but2 = wx.BitmapButton(self, -1, bmp, (380, 180))
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.TestFrame, self.but2)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.StaticText(self, -1, "Test Calendar Print", (350, 250), (150, -1))
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2003-12-18 19:10:26 +00:00
|
|
|
self.but3 = wx.BitmapButton(self, -1, bmp, (380, 280))
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnPreview, self.but3)
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# calendar dialog
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2001-04-02 05:57:32 +00:00
|
|
|
def TestDlg(self, event): # test the date dialog
|
2003-12-18 19:10:26 +00:00
|
|
|
dlg = wx.lib.calendar.CalenDlg(self)
|
1999-11-10 08:03:29 +00:00
|
|
|
dlg.Centre()
|
2003-12-09 01:23:28 +00:00
|
|
|
|
|
|
|
if dlg.ShowModal() == wx.ID_OK:
|
2001-04-02 05:57:32 +00:00
|
|
|
result = dlg.result
|
|
|
|
day = result[1]
|
|
|
|
month = result[2]
|
|
|
|
year = result[3]
|
|
|
|
new_date = str(month) + '/'+ str(day) + '/'+ str(year)
|
|
|
|
self.log.WriteText('Date Selected: %s\n' % new_date)
|
|
|
|
else:
|
|
|
|
self.log.WriteText('No Date Selected')
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# calendar window test
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
def TestFrame(self, event):
|
1999-11-10 22:47:12 +00:00
|
|
|
frame = CalendFrame(self, -1, "Test Calendar", self.log)
|
2003-03-25 06:35:27 +00:00
|
|
|
frame.Show(True)
|
|
|
|
return True
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# calendar print preview
|
2000-07-15 19:51:35 +00:00
|
|
|
|
|
|
|
def OnPreview(self, event):
|
|
|
|
month = self.calend.GetMonth()
|
|
|
|
year = self.calend.GetYear()
|
|
|
|
|
|
|
|
prt = PrintCalend(self.frame, month, year)
|
|
|
|
prt.Preview()
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# month and year control events
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
def OnSpin(self, event):
|
|
|
|
year = event.GetPosition()
|
|
|
|
self.dtext.SetValue(str(year))
|
|
|
|
self.calend.SetYear(year)
|
|
|
|
self.calend.Refresh()
|
|
|
|
|
|
|
|
def EvtComboBox(self, event):
|
|
|
|
name = event.GetString()
|
|
|
|
self.log.WriteText('EvtComboBox: %s\n' % name)
|
|
|
|
monthval = self.date.FindString(name)
|
2003-03-25 06:35:27 +00:00
|
|
|
self.scroll.SetScrollbar(monthval, 1, 12, 1, True)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
self.calend.SetMonth(monthval+1)
|
|
|
|
self.ResetDisplay()
|
|
|
|
|
|
|
|
def Scroll(self, event):
|
|
|
|
value = self.scroll.GetThumbPosition()
|
|
|
|
monthval = int(value)+1
|
|
|
|
self.calend.SetMonth(monthval)
|
|
|
|
self.ResetDisplay()
|
|
|
|
self.log.WriteText('Month: %s\n' % value)
|
|
|
|
|
2003-12-18 19:10:26 +00:00
|
|
|
name = wx.lib.calendar.Month[monthval]
|
1999-11-10 08:03:29 +00:00
|
|
|
self.date.SetValue(name)
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# log mouse events
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
def MouseClick(self, evt):
|
|
|
|
text = '%s CLICK %02d/%02d/%d' % (evt.click, evt.day, evt.month, evt.year) # format date
|
|
|
|
self.log.WriteText('Date Selected: ' + text + '\n')
|
|
|
|
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# set the highlighted days for the calendar
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
def ResetDisplay(self):
|
|
|
|
month = self.calend.GetMonth()
|
2003-12-09 01:23:28 +00:00
|
|
|
|
1999-11-10 08:03:29 +00:00
|
|
|
try:
|
|
|
|
set_days = test_days[month]
|
|
|
|
except:
|
|
|
|
set_days = [1, 5, 12]
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
self.calend.AddSelect([4, 11], 'BLUE', 'WHITE')
|
1999-11-10 08:03:29 +00:00
|
|
|
self.calend.SetSelDay(set_days)
|
|
|
|
self.calend.Refresh()
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
# increment and decrement toolbar controls
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
def OnIncYear(self, event):
|
|
|
|
self.calend.IncYear()
|
|
|
|
self.ResetDisplay()
|
|
|
|
|
|
|
|
def OnDecYear(self, event):
|
|
|
|
self.calend.DecYear()
|
|
|
|
self.ResetDisplay()
|
|
|
|
|
|
|
|
def OnIncMonth(self, event):
|
|
|
|
self.calend.IncMonth()
|
|
|
|
self.ResetDisplay()
|
|
|
|
|
|
|
|
def OnDecMonth(self, event):
|
|
|
|
self.calend.DecMonth()
|
|
|
|
self.ResetDisplay()
|
|
|
|
|
|
|
|
def OnCurrent(self, event):
|
|
|
|
self.calend.SetCurrentDay()
|
|
|
|
self.ResetDisplay()
|
|
|
|
|
|
|
|
# test of full window calendar control functions
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
class CalendFrame(wx.Frame):
|
1999-11-10 08:03:29 +00:00
|
|
|
def __init__(self, parent, id, title, log):
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.Frame.__init__(self, parent, id, title, size=(400, 400),
|
|
|
|
style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
|
|
|
|
|
|
|
|
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
self.log = log
|
|
|
|
self.CreateStatusBar()
|
2003-12-09 01:23:28 +00:00
|
|
|
self.mainmenu = wx.MenuBar()
|
|
|
|
menu = wx.Menu()
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
menu = self.MakeFileMenu()
|
|
|
|
self.mainmenu.Append(menu, '&File')
|
|
|
|
|
|
|
|
self.MakeToolMenu() # toolbar
|
|
|
|
|
|
|
|
self.SetMenuBar(self.mainmenu)
|
2003-12-18 19:10:26 +00:00
|
|
|
self.calend = wx.lib.calendar.Calendar(self, -1)
|
1999-11-10 08:03:29 +00:00
|
|
|
self.calend.SetCurrentDay()
|
|
|
|
self.calend.grid_color = 'BLUE'
|
2000-07-15 19:51:35 +00:00
|
|
|
self.calend.SetBusType()
|
|
|
|
# self.calend.ShowWeekEnd()
|
|
|
|
|
1999-11-10 08:03:29 +00:00
|
|
|
self.ResetDisplay()
|
|
|
|
|
2003-12-18 19:10:26 +00:00
|
|
|
self.Bind(wx.lib.calendar.EVT_CALENDAR, self.MouseClick, self.calend)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
def MouseClick(self, evt):
|
|
|
|
text = '%s CLICK %02d/%02d/%d' % (evt.click, evt.day, evt.month, evt.year) # format date
|
|
|
|
self.log.WriteText('Date Selected: ' + text + '\n')
|
|
|
|
|
|
|
|
def OnCloseWindow(self, event):
|
|
|
|
self.Destroy()
|
|
|
|
|
|
|
|
def ResetDisplay(self):
|
|
|
|
month = self.calend.GetMonth()
|
2003-12-09 01:23:28 +00:00
|
|
|
|
1999-11-10 08:03:29 +00:00
|
|
|
try:
|
|
|
|
set_days = test_days[month]
|
|
|
|
except:
|
|
|
|
set_days = [1, 5, 12]
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
self.calend.AddSelect([2, 16], 'GREEN', 'WHITE')
|
|
|
|
|
1999-11-10 08:03:29 +00:00
|
|
|
self.calend.SetSelDay(set_days)
|
|
|
|
self.calend.Refresh()
|
|
|
|
|
|
|
|
def OnIncYear(self, event):
|
|
|
|
self.calend.IncYear()
|
|
|
|
self.ResetDisplay()
|
|
|
|
|
|
|
|
def OnDecYear(self, event):
|
|
|
|
self.calend.DecYear()
|
|
|
|
self.ResetDisplay()
|
|
|
|
|
|
|
|
def OnIncMonth(self, event):
|
|
|
|
self.calend.IncMonth()
|
|
|
|
self.ResetDisplay()
|
|
|
|
|
|
|
|
def OnDecMonth(self, event):
|
|
|
|
self.calend.DecMonth()
|
|
|
|
self.ResetDisplay()
|
|
|
|
|
|
|
|
def OnCurrent(self, event):
|
|
|
|
self.calend.SetCurrentDay()
|
|
|
|
self.ResetDisplay()
|
|
|
|
|
|
|
|
def MakeFileMenu(self):
|
2003-12-09 01:23:28 +00:00
|
|
|
menu = wx.Menu()
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
mID = wx.NewId()
|
1999-11-10 08:03:29 +00:00
|
|
|
menu.Append(mID, 'Decrement', 'Next')
|
2003-12-09 01:23:28 +00:00
|
|
|
self.Bind(wx.EVT_MENU, self.OnDecMonth, id=mID)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
mID = wx.NewId()
|
1999-11-10 08:03:29 +00:00
|
|
|
menu.Append(mID, 'Increment', 'Dec')
|
2003-12-09 01:23:28 +00:00
|
|
|
self.Bind(wx.EVT_MENU, self.OnIncMonth, id=mID)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
menu.AppendSeparator()
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
mID = wx.NewId()
|
1999-11-10 08:03:29 +00:00
|
|
|
menu.Append(mID, 'E&xit', 'Exit')
|
2003-12-09 01:23:28 +00:00
|
|
|
self.Bind(wx.EVT_MENU, self.OnCloseWindow, id=mID)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
return menu
|
|
|
|
|
|
|
|
def MakeToolMenu(self):
|
2003-12-09 01:23:28 +00:00
|
|
|
tb = self.CreateToolBar(wx.TB_HORIZONTAL|wx.NO_BORDER)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
mID = wx.NewId()
|
2001-04-09 19:36:36 +00:00
|
|
|
SetToolPath(self, tb, mID, images.getDbDecBitmap(), 'Dec Year')
|
2003-12-09 01:23:28 +00:00
|
|
|
self.Bind(wx.EVT_TOOL, self.OnDecYear, id=mID)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
mID = wx.NewId()
|
2001-04-09 19:36:36 +00:00
|
|
|
SetToolPath(self, tb, mID, images.getDecBitmap(), 'Dec Month')
|
2003-12-09 01:23:28 +00:00
|
|
|
self.Bind(wx.EVT_TOOL, self.OnDecMonth, id=mID)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
mID = wx.NewId()
|
2001-04-09 19:36:36 +00:00
|
|
|
SetToolPath(self, tb, mID, images.getPtBitmap(), 'Current Month')
|
2003-12-09 01:23:28 +00:00
|
|
|
self.Bind(wx.EVT_TOOL, self.OnCurrent, id=mID)
|
2001-04-02 05:57:32 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
mID = wx.NewId()
|
2001-04-09 19:36:36 +00:00
|
|
|
SetToolPath(self, tb, mID, images.getIncBitmap(), 'Inc Month')
|
2003-12-09 01:23:28 +00:00
|
|
|
self.Bind(wx.EVT_TOOL, self.OnIncMonth, id=mID)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
mID = wx.NewId()
|
2001-04-09 19:36:36 +00:00
|
|
|
SetToolPath(self, tb, mID, images.getDbIncBitmap(), 'Inc Year')
|
2003-12-09 01:23:28 +00:00
|
|
|
self.Bind(wx.EVT_TOOL, self.OnIncYear, id=mID)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
tb.Realize()
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# example class for printing/previewing calendars
|
|
|
|
|
|
|
|
class PrintCalend:
|
|
|
|
def __init__(self, parent, month, year):
|
|
|
|
self.frame = parent
|
|
|
|
self.month = month
|
|
|
|
self.year = year
|
|
|
|
|
|
|
|
self.SetParms()
|
|
|
|
self.SetCal()
|
2003-12-09 01:23:28 +00:00
|
|
|
self.printData = wx.PrintData()
|
2000-07-15 19:51:35 +00:00
|
|
|
|
|
|
|
def SetCal(self):
|
|
|
|
self.grid_color = 'BLUE'
|
|
|
|
self.back_color = 'WHITE'
|
|
|
|
self.sel_color = 'RED'
|
|
|
|
self.high_color = 'LIGHT BLUE'
|
2003-12-09 01:23:28 +00:00
|
|
|
self.font = wx.SWISS
|
|
|
|
self.bold = wx.NORMAL
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2004-01-13 03:17:17 +00:00
|
|
|
self.sel_key = None # last used by
|
2000-07-15 19:51:35 +00:00
|
|
|
self.sel_lst = [] # highlighted selected days
|
|
|
|
|
|
|
|
self.size = None
|
2003-03-25 06:35:27 +00:00
|
|
|
self.hide_title = False
|
|
|
|
self.hide_grid = False
|
2000-07-15 19:51:35 +00:00
|
|
|
self.set_day = None
|
|
|
|
|
|
|
|
def SetParms(self):
|
|
|
|
self.ymax = 1
|
|
|
|
self.xmax = 1
|
|
|
|
self.page = 1
|
|
|
|
self.total_pg = 1
|
|
|
|
|
|
|
|
self.preview = None
|
|
|
|
self.scale = 1.0
|
|
|
|
|
|
|
|
self.pagew = 8.5
|
|
|
|
self.pageh = 11.0
|
|
|
|
|
|
|
|
self.txt_marg = 0.1
|
|
|
|
self.lf_marg = 0
|
|
|
|
self.top_marg = 0
|
|
|
|
|
|
|
|
self.page = 0
|
|
|
|
|
|
|
|
def SetDates(self, month, year):
|
|
|
|
self.month = month
|
|
|
|
self.year = year
|
|
|
|
|
|
|
|
def SetStyleDef(self, desc):
|
|
|
|
self.style = desc
|
|
|
|
|
|
|
|
def SetCopies(self, copies): # number of copies of label
|
|
|
|
self.copies = copies
|
|
|
|
|
|
|
|
def SetStart(self, start): # start position of label
|
|
|
|
self.start = start
|
|
|
|
|
|
|
|
def Preview(self):
|
|
|
|
printout = SetPrintout(self)
|
|
|
|
printout2 = SetPrintout(self)
|
2003-12-09 01:23:28 +00:00
|
|
|
self.preview = wx.PrintPreview(printout, printout2, self.printData)
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
if not self.preview.Ok():
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.MessageBox("There was a problem printing!", "Printing", wx.OK)
|
2000-07-15 19:51:35 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
self.preview.SetZoom(60) # initial zoom value
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
frame = wx.PreviewFrame(self.preview, self.frame, "Print preview")
|
2000-07-15 19:51:35 +00:00
|
|
|
|
|
|
|
frame.Initialize()
|
|
|
|
frame.SetPosition(self.frame.GetPosition())
|
|
|
|
frame.SetSize(self.frame.GetSize())
|
2003-03-25 06:35:27 +00:00
|
|
|
frame.Show(True)
|
2000-07-15 19:51:35 +00:00
|
|
|
|
|
|
|
def Print(self):
|
2003-12-09 01:23:28 +00:00
|
|
|
pdd = wx.PrintDialogData()
|
2000-07-15 19:51:35 +00:00
|
|
|
pdd.SetPrintData(self.printData)
|
2003-12-09 01:23:28 +00:00
|
|
|
printer = wx.Printer(pdd)
|
2000-07-15 19:51:35 +00:00
|
|
|
printout = SetPrintout(self)
|
2003-12-09 01:23:28 +00:00
|
|
|
frame = wx.Frame(None, -1, "Test")
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
if not printer.Print(frame, printout):
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.MessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wx.OK)
|
2000-07-15 19:51:35 +00:00
|
|
|
else:
|
|
|
|
self.printData = printer.GetPrintDialogData().GetPrintData()
|
2003-12-09 01:23:28 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
printout.Destroy()
|
|
|
|
|
|
|
|
def DoDrawing(self, DC):
|
2003-12-09 01:23:28 +00:00
|
|
|
size = DC.GetSize()
|
2000-07-15 19:51:35 +00:00
|
|
|
DC.BeginDrawing()
|
|
|
|
|
2003-12-18 19:10:26 +00:00
|
|
|
cal = wx.lib.calendar.PrtCalDraw(self)
|
2000-07-15 19:51:35 +00:00
|
|
|
|
|
|
|
if self.preview is None:
|
|
|
|
cal.SetPSize(size[0]/self.pagew, size[1]/self.pageh)
|
2003-03-25 06:35:27 +00:00
|
|
|
cal.SetPreview(False)
|
2000-07-15 19:51:35 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
if self.preview == 1:
|
|
|
|
cal.SetPSize(size[0]/self.pagew, size[1]/self.pageh)
|
|
|
|
else:
|
|
|
|
cal.SetPSize(self.pwidth, self.pheight)
|
|
|
|
|
|
|
|
cal.SetPreview(self.preview)
|
|
|
|
|
|
|
|
cal.hide_title = self.hide_title # set the calendar parameters
|
|
|
|
cal.hide_grid = self.hide_grid
|
|
|
|
|
|
|
|
cal.grid_color = self.grid_color
|
|
|
|
cal.high_color = self.high_color
|
|
|
|
cal.back_color = self.back_color
|
2003-03-25 06:35:27 +00:00
|
|
|
cal.outer_border = False
|
2000-07-15 19:51:35 +00:00
|
|
|
cal.font = self.font
|
|
|
|
cal.bold = self.bold
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
cal_size = (3.0, 3.0)
|
2000-07-15 19:51:35 +00:00
|
|
|
cal.SetSize(cal_size)
|
|
|
|
|
|
|
|
year, month = self.year, self.month
|
|
|
|
|
2003-12-30 01:43:59 +00:00
|
|
|
x = 0.5
|
2000-07-15 19:51:35 +00:00
|
|
|
for i in range(2):
|
|
|
|
y = 0.5
|
2003-12-09 01:23:28 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
for j in range(3):
|
|
|
|
cal.SetCal(year, month) # current month
|
|
|
|
cal.SetPos(x, y)
|
|
|
|
|
|
|
|
try:
|
|
|
|
set_days = test_days[month]
|
|
|
|
except:
|
|
|
|
set_days = [1, 5, 12]
|
|
|
|
|
|
|
|
cal.AddSelect([2, 16], 'GREEN', 'WHITE')
|
|
|
|
|
|
|
|
cal.DrawCal(DC, set_days)
|
|
|
|
|
|
|
|
year, month = self.IncMonth(year, month)
|
|
|
|
y = y + 3.5
|
2003-12-09 01:23:28 +00:00
|
|
|
|
2003-10-02 00:58:06 +00:00
|
|
|
x = x + 4.0 # next column
|
2000-07-15 19:51:35 +00:00
|
|
|
|
|
|
|
DC.EndDrawing()
|
|
|
|
|
|
|
|
self.ymax = DC.MaxY()
|
|
|
|
self.xmax = DC.MaxX()
|
|
|
|
|
|
|
|
def IncMonth(self, year, month): # next month
|
|
|
|
month = month + 1
|
2003-12-09 01:23:28 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
if month > 12:
|
|
|
|
month = 1
|
|
|
|
year = year + 1
|
|
|
|
|
|
|
|
return year, month
|
|
|
|
|
|
|
|
def GetTotalPages(self):
|
|
|
|
self.pg_cnt = 1
|
|
|
|
return self.pg_cnt
|
|
|
|
|
|
|
|
def SetPage(self, page):
|
|
|
|
self.page = page
|
|
|
|
|
|
|
|
def SetPageSize(self, width, height):
|
|
|
|
self.pwidth, self.pheight = width, height
|
|
|
|
|
|
|
|
def SetTotalSize(self, width, height):
|
|
|
|
self.ptwidth, self.ptheight = width, height
|
|
|
|
|
|
|
|
def SetPreview(self, preview, scale):
|
|
|
|
self.preview = preview
|
|
|
|
self.scale = scale
|
|
|
|
|
|
|
|
def SetTotalSize(self, width, height):
|
|
|
|
self.ptwidth = width
|
|
|
|
self.ptheight = height
|
|
|
|
|
1999-11-10 08:03:29 +00:00
|
|
|
def SetToolPath(self, tb, id, bmp, title):
|
2001-04-09 19:36:36 +00:00
|
|
|
tb.AddSimpleTool(id, bmp, title, title)
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
class SetPrintout(wx.Printout):
|
2000-07-15 19:51:35 +00:00
|
|
|
def __init__(self, canvas):
|
2003-12-09 01:23:28 +00:00
|
|
|
wx.Printout.__init__(self)
|
2000-07-15 19:51:35 +00:00
|
|
|
self.canvas = canvas
|
|
|
|
self.end_pg = 1
|
|
|
|
|
|
|
|
def OnBeginDocument(self, start, end):
|
|
|
|
return self.base_OnBeginDocument(start, end)
|
|
|
|
|
|
|
|
def OnEndDocument(self):
|
|
|
|
self.base_OnEndDocument()
|
|
|
|
|
|
|
|
def HasPage(self, page):
|
|
|
|
if page <= self.end_pg:
|
2003-03-25 06:35:27 +00:00
|
|
|
return True
|
2000-07-15 19:51:35 +00:00
|
|
|
else:
|
2003-03-25 06:35:27 +00:00
|
|
|
return False
|
2000-07-15 19:51:35 +00:00
|
|
|
|
|
|
|
def GetPageInfo(self):
|
|
|
|
self.end_pg = self.canvas.GetTotalPages()
|
|
|
|
str_pg = 1
|
2003-12-09 01:23:28 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
try:
|
|
|
|
end_pg = self.end_pg
|
|
|
|
except:
|
|
|
|
end_pg = 1
|
2003-12-09 01:23:28 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
return (str_pg, end_pg, str_pg, end_pg)
|
|
|
|
|
|
|
|
def OnPreparePrinting(self):
|
|
|
|
self.base_OnPreparePrinting()
|
|
|
|
|
|
|
|
def OnBeginPrinting(self):
|
|
|
|
dc = self.GetDC()
|
|
|
|
|
|
|
|
self.preview = self.IsPreview()
|
2003-12-09 01:23:28 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
if (self.preview):
|
|
|
|
self.pixelsPerInch = self.GetPPIScreen()
|
|
|
|
else:
|
|
|
|
self.pixelsPerInch = self.GetPPIPrinter()
|
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
(w, h) = dc.GetSize()
|
2000-07-15 19:51:35 +00:00
|
|
|
scaleX = float(w) / 1000
|
|
|
|
scaleY = float(h) / 1000
|
|
|
|
self.printUserScale = min(scaleX, scaleY)
|
|
|
|
|
|
|
|
self.base_OnBeginPrinting()
|
|
|
|
|
|
|
|
def GetSize(self):
|
|
|
|
self.psizew, self.psizeh = self.GetPPIPrinter()
|
|
|
|
return self.psizew, self.psizeh
|
|
|
|
|
|
|
|
def GetTotalSize(self):
|
|
|
|
self.ptsizew, self.ptsizeh = self.GetPageSizePixels()
|
|
|
|
return self.ptsizew, self.ptsizeh
|
|
|
|
|
|
|
|
def OnPrintPage(self, page):
|
|
|
|
dc = self.GetDC()
|
2003-12-09 01:23:28 +00:00
|
|
|
(w, h) = dc.GetSize()
|
2000-07-15 19:51:35 +00:00
|
|
|
scaleX = float(w) / 1000
|
|
|
|
scaleY = float(h) / 1000
|
|
|
|
self.printUserScale = min(scaleX, scaleY)
|
|
|
|
dc.SetUserScale(self.printUserScale, self.printUserScale)
|
|
|
|
|
|
|
|
self.preview = self.IsPreview()
|
|
|
|
|
|
|
|
self.canvas.SetPreview(self.preview, self.printUserScale)
|
|
|
|
self.canvas.SetPage(page)
|
|
|
|
|
|
|
|
self.ptsizew, self.ptsizeh = self.GetPageSizePixels()
|
|
|
|
self.canvas.SetTotalSize(self.ptsizew, self.ptsizeh)
|
|
|
|
|
|
|
|
self.psizew, self.psizeh = self.GetPPIPrinter()
|
|
|
|
self.canvas.SetPageSize(self.psizew, self.psizeh)
|
|
|
|
|
|
|
|
self.canvas.DoDrawing(dc)
|
2003-03-25 06:35:27 +00:00
|
|
|
return True
|
1999-11-10 22:47:12 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
class MyApp(wx.App):
|
1999-11-10 08:03:29 +00:00
|
|
|
def OnInit(self):
|
2003-12-09 01:23:28 +00:00
|
|
|
frame = CalendFrame(None, -1, "Test Calendar", log)
|
2003-03-25 06:35:27 +00:00
|
|
|
frame.Show(True)
|
1999-11-10 08:03:29 +00:00
|
|
|
self.SetTopWindow(frame)
|
2003-03-25 06:35:27 +00:00
|
|
|
return True
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def MessageDlg(self, message, type = 'Message'):
|
2003-12-09 01:23:28 +00:00
|
|
|
dlg = wx.MessageDialog(self, message, type, wx.OK | wx.ICON_INFORMATION)
|
1999-11-10 08:03:29 +00:00
|
|
|
dlg.ShowModal()
|
|
|
|
dlg.Destroy()
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
2000-07-15 19:51:35 +00:00
|
|
|
win = TestPanel(nb, log, frame)
|
1999-11-10 08:03:29 +00:00
|
|
|
return win
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
overview = """\
|
2003-12-18 19:10:26 +00:00
|
|
|
This control provides a Calendar control class for displaying and selecting dates.
|
|
|
|
In addition, the class is extended and can be used for printing/previewing.
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
Additional features include weekend highlighting and business type Monday-Sunday
|
|
|
|
format.
|
1999-11-10 08:03:29 +00:00
|
|
|
|
2003-12-09 01:23:28 +00:00
|
|
|
See example for various methods used to set display month, year, and highlighted
|
|
|
|
dates (different font and background colours).
|
1999-11-10 08:03:29 +00:00
|
|
|
|
|
|
|
by Lorne White
|
|
|
|
|
|
|
|
"""
|
2003-11-22 22:57:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
2004-03-05 00:06:33 +00:00
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
2003-11-22 22:57:49 +00:00
|
|
|
|