#
# Author: Lorne White (email: lwhite1@planet.eon.net)
#
-# Created:
-# Version 0.8 2000/04/16
+# Version 0.9
+# Date: Feb 26, 2001
# Licence: wxWindows license
#----------------------------------------------------------------------------
from wxPython.wx import *
-from wxPython.lib.calendar import wxCalendar, Month, PrtCalDraw
+from wxPython.lib.calendar import wxCalendar, Month, PrtCalDraw, CalenDlg
+import images
import os
-dir_path = os.getcwd()
# highlighted days in month
self.calend = wxCalendar(self, -1, wxPoint(100, 50), wxSize(200, 180))
- start_month = 11
- start_year = 1999
+# 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()
# month list from DateTime module
monthlist = GetMonthList()
- self.date = wxComboBox(self, 10, Month[start_month], wxPoint(100, 20), wxSize(90, -1), monthlist, wxCB_DROPDOWN)
- EVT_COMBOBOX(self, 10, self.EvtComboBox)
+ mID = wxNewId()
+ self.date = wxComboBox(self, mID, "",
+ wxPoint(100, 20), wxSize(90, -1),
+ monthlist, wxCB_DROPDOWN)
+ self.date.SetSelection(start_month-1)
+ EVT_COMBOBOX(self, mID, self.EvtComboBox)
# set start month and year
# set attributes of calendar
- self.calend.hide_title = TRUE
+ self.calend.hide_title = True
self.calend.HideGrid()
self.calend.SetWeekColor('WHITE', 'BLACK')
# scroll bar for month selection
- self.scroll = wxScrollBar(self, 40, wxPoint(100, 240), wxSize(200, 20), wxSB_HORIZONTAL)
- self.scroll.SetScrollbar(start_month-1, 1, 12, 1, TRUE)
- EVT_COMMAND_SCROLL(self, 40, self.Scroll)
+ mID = wxNewId()
+ self.scroll = wxScrollBar(self, mID, wxPoint(100, 240), wxSize(200, 20), wxSB_HORIZONTAL)
+ self.scroll.SetScrollbar(start_month-1, 1, 12, 1, True)
+ EVT_COMMAND_SCROLL(self, mID, self.Scroll)
# spin control for year selection
self.dtext = wxTextCtrl(self, -1, str(start_year), wxPoint(200, 20), wxSize(60, -1))
h = self.dtext.GetSize().height
- self.spin = wxSpinButton(self, 20, wxPoint(270, 20), wxSize(h*2, h))
+ mID = wxNewId()
+ self.spin = wxSpinButton(self, mID, wxPoint(270, 20), wxSize(h*2, h))
self.spin.SetRange(1980, 2010)
self.spin.SetValue(start_year)
- EVT_SPIN(self, 20, self.OnSpin)
+ EVT_SPIN(self, mID, self.OnSpin)
# button for calendar dialog test
wxStaticText(self, -1, "Test Calendar Dialog", wxPoint(350, 50), wxSize(150, -1))
- bmp = wxBitmap('bitmaps/Calend.bmp', wxBITMAP_TYPE_BMP)
- self.but = wxBitmapButton(self, 60, bmp, wxPoint(380, 80))#, wxSize(30, 30))
- EVT_BUTTON(self, 60, self.TestDlg)
+ mID = wxNewId()
+ bmp = images.getCalendarBitmap()
+ self.but = wxBitmapButton(self, mID, bmp, wxPoint(380, 80))#, wxSize(30, 30))
+ EVT_BUTTON(self, mID, self.TestDlg)
# button for calendar window test
wxStaticText(self, -1, "Test Calendar Window", wxPoint(350, 150), wxSize(150, -1))
- bmp = wxBitmap('bitmaps/Calend.bmp', wxBITMAP_TYPE_BMP)
- self.but = wxBitmapButton(self, 160, bmp, wxPoint(380, 180))#, wxSize(30, 30))
- EVT_BUTTON(self, 160, self.TestFrame)
+ mID = wxNewId()
+ self.but = wxBitmapButton(self, mID, bmp, wxPoint(380, 180))#, wxSize(30, 30))
+ EVT_BUTTON(self, mID, self.TestFrame)
wxStaticText(self, -1, "Test Calendar Print", wxPoint(350, 250), wxSize(150, -1))
- bmp = wxBitmap('bitmaps/Calend.bmp', wxBITMAP_TYPE_BMP)
- self.but = wxBitmapButton(self, 170, bmp, wxPoint(380, 280))#, wxSize(30, 30))
- EVT_BUTTON(self, 170, self.OnPreview)
+ mID = wxNewId()
+ self.but = wxBitmapButton(self, mID, bmp, wxPoint(380, 280))#, wxSize(30, 30))
+ EVT_BUTTON(self, mID, self.OnPreview)
# calendar dialog
- def TestDlg(self, event):
- dlg = CalenDlg(self, self.log)
+ def TestDlg(self, event): # test the date dialog
+ dlg = CalenDlg(self)
dlg.Centre()
- dlg.ShowModal()
- dlg.Destroy()
+ if dlg.ShowModal() == wxID_OK:
+ 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')
# calendar window test
def TestFrame(self, event):
frame = CalendFrame(self, -1, "Test Calendar", self.log)
- frame.Show(true)
- return true
+ frame.Show(True)
+ return True
# calendar print preview
name = event.GetString()
self.log.WriteText('EvtComboBox: %s\n' % name)
monthval = self.date.FindString(name)
- self.scroll.SetScrollbar(monthval, 1, 12, 1, TRUE)
+ self.scroll.SetScrollbar(monthval, 1, 12, 1, True)
self.calend.SetMonth(monthval+1)
self.ResetDisplay()
self.calend.SetCurrentDay()
self.ResetDisplay()
-# test the calendar control in a dialog
-
-class CalenDlg(wxDialog):
- def __init__(self, parent, log):
- self.log = log
- wxDialog.__init__(self, parent, -1, "Test Calendar", wxPyDefaultPosition, wxSize(280, 300))
-
- start_month = 2
- start_year = 1999
-
-# get month list from DateTime
-
- monthlist = GetMonthList()
-
-# select the month
-
- self.date = wxComboBox(self, 100, Month[start_month], wxPoint(20, 20), wxSize(90, -1), monthlist, wxCB_DROPDOWN)
- EVT_COMBOBOX(self, 100, self.EvtComboBox)
-
-# alternate spin button to control the month
-
- h = self.date.GetSize().height
- self.m_spin = wxSpinButton(self, 120, wxPoint(120, 20), wxSize(h*2, h), wxSP_VERTICAL)
- self.m_spin.SetRange(1, 12)
- self.m_spin.SetValue(start_month)
-
- EVT_SPIN(self, 120, self.OnMonthSpin)
-
-# spin button to conrol the year
-
- self.dtext = wxTextCtrl(self, -1, str(start_year), wxPoint(160, 20), wxSize(60, -1))
- h = self.dtext.GetSize().height
-
- self.y_spin = wxSpinButton(self, 20, wxPoint(220, 20), wxSize(h*2, h), wxSP_VERTICAL)
- self.y_spin.SetRange(1980, 2010)
- self.y_spin.SetValue(start_year)
-
- EVT_SPIN(self, 20, self.OnYrSpin)
-
-# set the calendar and attributes
-
- self.calend = wxCalendar(self, -1, wxPoint(20, 60), wxSize(240, 200))
- self.calend.SetMonth(start_month)
- self.calend.SetYear(start_year)
-
- self.calend.HideTitle()
- self.calend.ShowWeekEnd()
-
- self.ResetDisplay()
-
- self.Connect(self.calend.GetId(), -1, 2100, self.MouseClick)
-
-# log the mouse clicks
-
- 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')
-
- if evt.click == 'DLEFT':
- self.EndModal(wxID_OK)
-
-# month and year spin selection routines
-
- def OnMonthSpin(self, event):
- month = event.GetPosition()
- if month >= 0 and month <= 12:
- self.date.SetValue(Month[month])
- self.calend.SetMonth(month)
- self.calend.Refresh()
-
- def OnYrSpin(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)
- self.m_spin.SetValue(monthval+1)
-
- self.calend.SetMonth(monthval+1)
- self.ResetDisplay()
-
-# set the calendar for highlighted days
-
- def ResetDisplay(self):
- month = self.calend.GetMonth()
- try:
- set_days = test_days[month]
- except:
- set_days = [1, 5, 12]
-
- self.calend.AddSelect([4, 11], 'BLUE', 'WHITE')
-
- self.calend.SetSelDay(set_days)
- self.calend.Refresh()
-
# test of full window calendar control functions
class CalendFrame(wxFrame):
def __init__(self, parent, id, title, log):
- wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition, wxSize(400, 400))
+ wxFrame.__init__(self, parent, id, title, size=wxSize(400, 400),
+ style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE)
EVT_CLOSE(self, self.OnCloseWindow)
self.log = log
def MakeFileMenu(self):
menu = wxMenu()
- mID = NewId()
+ mID = wxNewId()
menu.Append(mID, 'Decrement', 'Next')
EVT_MENU(self, mID, self.OnDecMonth)
- mID = NewId()
+ mID = wxNewId()
menu.Append(mID, 'Increment', 'Dec')
EVT_MENU(self, mID, self.OnIncMonth)
menu.AppendSeparator()
- mID = NewId()
+ mID = wxNewId()
menu.Append(mID, 'E&xit', 'Exit')
EVT_MENU(self, mID, self.OnCloseWindow)
def MakeToolMenu(self):
tb = self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER)
- bmp_path = 'bitmaps/'
- SetToolPath(self, tb, 10, bmp_path + 'DbDec.bmp', 'Dec Year')
- EVT_TOOL(self, 10, self.OnDecYear)
+ mID = wxNewId()
+ SetToolPath(self, tb, mID, images.getDbDecBitmap(), 'Dec Year')
+ EVT_TOOL(self, mID, self.OnDecYear)
- SetToolPath(self, tb, 15, bmp_path + 'Dec.bmp', 'Dec Month')
- EVT_TOOL(self, 15, self.OnDecMonth)
+ mID = wxNewId()
+ SetToolPath(self, tb, mID, images.getDecBitmap(), 'Dec Month')
+ EVT_TOOL(self, mID, self.OnDecMonth)
- SetToolPath(self, tb, 30, bmp_path + 'Pt.bmp', 'Current Month')
- EVT_TOOL(self, 30, self.OnCurrent)
+ mID = wxNewId()
+ SetToolPath(self, tb, mID, images.getPtBitmap(), 'Current Month')
+ EVT_TOOL(self, mID, self.OnCurrent)
- SetToolPath(self, tb, 40, bmp_path + 'Inc.bmp', 'Inc Month')
- EVT_TOOL(self, 40, self.OnIncMonth)
+ mID = wxNewId()
+ SetToolPath(self, tb, mID, images.getIncBitmap(), 'Inc Month')
+ EVT_TOOL(self, mID, self.OnIncMonth)
- SetToolPath(self, tb, 45, bmp_path + 'DbInc.bmp', 'Inc Year')
- EVT_TOOL(self, 45, self.OnIncYear)
+ mID = wxNewId()
+ SetToolPath(self, tb, mID, images.getDbIncBitmap(), 'Inc Year')
+ EVT_TOOL(self, mID, self.OnIncYear)
tb.Realize()
self.sel_lst = [] # highlighted selected days
self.size = None
- self.hide_title = FALSE
- self.hide_grid = FALSE
+ self.hide_title = False
+ self.hide_grid = False
self.set_day = None
def SetParms(self):
frame.Initialize()
frame.SetPosition(self.frame.GetPosition())
frame.SetSize(self.frame.GetSize())
- frame.Show(true)
+ frame.Show(True)
def Print(self):
pdd = wxPrintDialogData()
pdd.SetPrintData(self.printData)
printer = wxPrinter(pdd)
printout = SetPrintout(self)
- frame = wxFrame(NULL, -1, "Test")
+ frame = wxFrame(None, -1, "Test")
if not printer.Print(frame, printout):
wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wxOK)
else:
if self.preview is None:
cal.SetPSize(size[0]/self.pagew, size[1]/self.pageh)
- cal.SetPreview(FALSE)
+ cal.SetPreview(False)
else:
if self.preview == 1:
cal.grid_color = self.grid_color
cal.high_color = self.high_color
cal.back_color = self.back_color
- cal.outer_border = FALSE
+ cal.outer_border = False
cal.font = self.font
cal.bold = self.bold
self.ptheight = height
def SetToolPath(self, tb, id, bmp, title):
- global dir_path
- tb.AddSimpleTool(id, wxBitmap(os.path.join(dir_path, bmp), wxBITMAP_TYPE_BMP),
- title, title)
+ tb.AddSimpleTool(id, bmp, title, title)
class SetPrintout(wxPrintout):
def __init__(self, canvas):
def HasPage(self, page):
if page <= self.end_pg:
- return true
+ return True
else:
- return false
+ return False
def GetPageInfo(self):
self.end_pg = self.canvas.GetTotalPages()
self.canvas.SetPageSize(self.psizew, self.psizeh)
self.canvas.DoDrawing(dc)
- return true
+ return True
class MyApp(wxApp):
def OnInit(self):
- frame = CalendFrame(NULL, -1, "Test Calendar")
- frame.Show(true)
+ frame = CalendFrame(None, -1, "Test Calendar")
+ frame.Show(True)
self.SetTopWindow(frame)
- return true
+ return True
#---------------------------------------------------------------------------