#
# o New Bind() method now fully supported.
#
+# 12/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o wxCalendar renamed to Calendar
+# o Got rid of unneeded IDs where Bind() could figure it
+# out for itself.
+#
import os
import wx
-import wx.lib.calendar as calendar
+import wx.lib.calendar
import images
monthlist = []
for i in range(13):
- name = calendar.Month[i]
+ name = wx.lib.calendar.Month[i]
if name != None:
monthlist.append(name)
self.log = log
self.frame = frame
- self.calend = calendar.wxCalendar(self, -1, (100, 50), (200, 180))
+ self.calend = wx.lib.calendar.Calendar(self, -1, (100, 50), (200, 180))
# start_month = 2 # preselect the date for calendar
# start_year = 2001
monthlist = GetMonthList()
- mID = wx.NewId()
- self.date = wx.ComboBox(self, mID, "",
+ self.date = wx.ComboBox(self, -1, "",
(100, 20), (90, -1),
monthlist, wx.CB_DROPDOWN)
self.date.SetSelection(start_month-1)
- self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, id=mID)
+ self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.date)
# set start month and year
self.ResetDisplay()
# mouse click event
- self.Bind(calendar.EVT_CALENDAR, self.MouseClick, self.calend)
+ self.Bind(wx.lib.calendar.EVT_CALENDAR, self.MouseClick, self.calend)
# scroll bar for month selection
-
- mID = wx.NewId()
-
- self.scroll = wx.ScrollBar(self, mID, (100, 240), (200, 20), wx.SB_HORIZONTAL)
+ self.scroll = wx.ScrollBar(self, -1, (100, 240), (200, 20), wx.SB_HORIZONTAL)
self.scroll.SetScrollbar(start_month-1, 1, 12, 1, True)
- self.Bind(wx.EVT_COMMAND_SCROLL, self.Scroll, id=mID)
+ self.Bind(wx.EVT_COMMAND_SCROLL, self.Scroll, self.scroll)
# spin control for year selection
self.dtext = wx.TextCtrl(self, -1, str(start_year), (200, 20), (60, -1))
h = self.dtext.GetSize().height
- mID = wx.NewId()
- self.spin = wx.SpinButton(self, mID, (270, 20), (h*2, h))
+ self.spin = wx.SpinButton(self, -1, (270, 20), (h*2, h))
self.spin.SetRange(1980, 2010)
self.spin.SetValue(start_year)
- self.Bind(wx.EVT_SPIN, self.OnSpin, id=mID)
+ self.Bind(wx.EVT_SPIN, self.OnSpin, self.spin)
# button for calendar dialog test
wx.StaticText(self, -1, "Test Calendar Dialog", (350, 50), (150, -1))
- mID = wx.NewId()
bmp = images.getCalendarBitmap()
- self.but = wx.BitmapButton(self, mID, bmp, (380, 80))
- self.Bind(wx.EVT_BUTTON, self.TestDlg, id=mID)
+ self.but1 = wx.BitmapButton(self, -1, bmp, (380, 80))
+ self.Bind(wx.EVT_BUTTON, self.TestDlg, self.but1)
# button for calendar window test
wx.StaticText(self, -1, "Test Calendar Window", (350, 150), (150, -1))
- mID = wx.NewId()
- self.but = wx.BitmapButton(self, mID, bmp, (380, 180))
- self.Bind(wx.EVT_BUTTON, self.TestFrame, id=mID)
+ self.but2 = wx.BitmapButton(self, -1, bmp, (380, 180))
+ self.Bind(wx.EVT_BUTTON, self.TestFrame, self.but2)
wx.StaticText(self, -1, "Test Calendar Print", (350, 250), (150, -1))
- mID = wx.NewId()
- self.but = wx.BitmapButton(self, mID, bmp, (380, 280))
- self.Bind(wx.EVT_BUTTON, self.OnPreview, id=mID)
+ self.but3 = wx.BitmapButton(self, -1, bmp, (380, 280))
+ self.Bind(wx.EVT_BUTTON, self.OnPreview, self.but3)
# calendar dialog
def TestDlg(self, event): # test the date dialog
- dlg = calendar.CalenDlg(self)
+ dlg = wx.lib.calendar.CalenDlg(self)
dlg.Centre()
if dlg.ShowModal() == wx.ID_OK:
self.ResetDisplay()
self.log.WriteText('Month: %s\n' % value)
- name = calendar.Month[monthval]
+ name = wx.lib.calendar.Month[monthval]
self.date.SetValue(name)
# log mouse events
self.MakeToolMenu() # toolbar
self.SetMenuBar(self.mainmenu)
- self.calend = calendar.wxCalendar(self, -1)
+ self.calend = wx.lib.calendar.Calendar(self, -1)
self.calend.SetCurrentDay()
self.calend.grid_color = 'BLUE'
self.calend.SetBusType()
self.ResetDisplay()
- self.Bind(calendar.EVT_CALENDAR, self.MouseClick, self.calend)
+ self.Bind(wx.lib.calendar.EVT_CALENDAR, self.MouseClick, self.calend)
def MouseClick(self, evt):
text = '%s CLICK %02d/%02d/%d' % (evt.click, evt.day, evt.month, evt.year) # format date
size = DC.GetSize()
DC.BeginDrawing()
- cal = calendar.PrtCalDraw(self)
+ cal = wx.lib.calendar.PrtCalDraw(self)
if self.preview is None:
cal.SetPSize(size[0]/self.pagew, size[1]/self.pageh)
overview = """\
-This control provides a calendar control class for displaying and selecting dates.
-In addition, the class is extended and can now be used for printing/previewing.
+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.
Additional features include weekend highlighting and business type Monday-Sunday
format.
# integer argument expected, got float
# newobj = _core.new_Rect(*args, **kwargs)
#
+# 12/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o A few style-guide nips and tucks
+# o Renamed wxCalendar to Calendar
+# o Couple of bugfixes
+#
import wx
self.DefParms()
def DefParms(self):
- self.num_auto = True # auto scale of the cal number day size
- self.num_size = 12 # default size of calendar if no auto size
- self.max_num_size = 12 # maximum size for calendar number
+ self.num_auto = True # auto scale of the cal number day size
+ self.num_size = 12 # default size of calendar if no auto size
+ self.max_num_size = 12 # maximum size for calendar number
self.num_align_horz = wx.ALIGN_CENTRE # alignment of numbers
self.num_align_vert = wx.ALIGN_CENTRE
def DrawNumVal(self):
self.DrawNum()
-# calculate the calendar days and offset position
+ # calculate the calendar days and offset position
def SetCal(self, year, month):
self.InitValues() # reset initial values
else:
date = date + 7
- def GetRect(self): # get the display rectange list of the day grid
+ # get the display rectange list of the day grid
+ def GetRect(self):
cnt = 0
for y in self.gridy[1:-1]:
for x in self.gridx[:-1]:
def GetOffset(self):
return self.st_pos
- def DrawMonth(self): # month and year title
+ # month and year title
+ def DrawMonth(self):
month = Month[self.month]
sizef = 11
self.DC.DrawText(day, (x+diffx, y+diffy))
cnt_x = cnt_x + 1
- def DrawNum(self): # draw the day numbers
+ # draw the day numbers
+ def DrawNum(self):
f = wx.Font(10, self.font, wx.NORMAL, self.bold) # initial font setting
if self.num_auto == True:
cnt_x = 0
cnt_y = cnt_y + 1
- def Center(self): # calculate the dimensions in the center of the drawing area
+ # calculate the dimensions in the center of the drawing area
+ def Center(self):
bdw = self.x_mrg * 2
bdh = self.y_mrg + self.y_end + self.title_offset
self.dl_w = int((self.sizew-bdw)/7)
self.dl_h = int((self.sizeh-bdh)/7)
- self.dl_th = int(self.dl_h*self.cal_week_scale) # week title adjustment
+ # week title adjustment
+ self.dl_th = int(self.dl_h*self.cal_week_scale)
self.cwidth = self.dl_w * 7
self.cheight = self.dl_h * 6 + self.dl_th
- def DrawSel(self): # highlighted selected days
+ # highlighted selected days
+ def DrawSel(self):
for key in self.cal_sel.keys():
sel_color = self.cal_sel[key][1]
brush = wx.Brush(wx.NamedColour(sel_color), wx.SOLID)
rect = self.rg[nkey]
self.DC.DrawRectangle((rect.x, rect.y), (rect.width+1, rect.height+1))
- def DrawGrid(self): # calculate and draw the grid lines
+ # calculate and draw the grid lines
+ def DrawGrid(self):
self.DC.SetPen(wx.Pen(wx.NamedColour(self.grid_color), 0))
self.gridx = []
self.gridy = []
self.x_st = self.cx_st + self.x_mrg
- self.y_st = self.cy_st + self.y_mrg + self.title_offset # start postion of draw
+ # start postion of draw
+ self.y_st = self.cy_st + self.y_mrg + self.title_offset
x1 = self.x_st
y1 = self.y_st
def InitValues(self):
self.rg = {}
self.cal_sel = {}
- self.set_cx_st = 1.0 # start draw border location
+ # start draw border location
+ self.set_cx_st = 1.0
self.set_cy_st = 1.0
- self.set_y_mrg = 0.2 # draw offset position
+ # draw offset position
+ self.set_y_mrg = 0.2
self.set_x_mrg = 0.2
self.set_y_end = 0.2
def SetPreview(self, preview):
self.preview = preview
-class wxCalendar(wx.Window):
+class Calendar(wx.Window):
def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize):
wx.Window.__init__(self, parent, id, pos, size)
- # set the calendar control attributes
+ # set the calendar control attributes
self.grid_color = 'BLACK'
self.back_color = 'WHITE'
self.show_weekend = False
self.cal_type = "NORMAL"
+ # font colors
self.week_color = 'LIGHT GREY'
- self.week_font_color = 'BLACK' # font colors
+ self.week_font_color = 'BLACK'
self.select_list = []
self.sel_key = None # last used by
self.sel_lst = [] # highlighted selected days
- self.SetNow() # default calendar for current month
+ # default calendar for current month
+ self.SetNow()
self.size = None
self.set_day = None
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_SIZE, self.OnSize)
-# control some of the main calendar attributes
+ # control some of the main calendar attributes
def HideTitle(self):
self.hide_title = True
def HideGrid(self):
self.hide_grid = True
-# determine the calendar rectangle click area and draw a selection
+ # determine the calendar rectangle click area and draw a selection
def ProcessClick(self, event):
self.x, self.y = event.GetX(), event.GetY()
key = self.GetDayHit(self.x, self.y)
self.SelectDay(key)
-# tab mouse click events and process
+ # tab mouse click events and process
def OnLeftEvent(self, event):
self.click = 'LEFT'
self.size = set_size
def SetSelDay(self, sel):
- self.sel_lst = sel # list of highlighted days
-
-# get the current date
+ # list of highlighted days
+ self.sel_lst = sel
+ # get the current date
def SetNow(self):
dt = now()
self.month = dt.month
self.year = dt.year
self.day = dt.day
-# set the current day
-
+ # set the current day
def SetCurrentDay(self):
self.SetNow()
self.set_day = self.day
-# get the date, day, month, year set in calendar
+ # get the date, day, month, year set in calendar
def GetDate(self):
return self.day, self.month, self.year
def GetYear(self):
return self.year
-# set the day, month, and year
+ # set the day, month, and year
def SetDayValue(self, day):
self.set_day = day
def SetYear(self, year):
self.year = year
-# increment year and month
+ # increment year and month
def IncYear(self):
self.year = self.year + 1
self.year = self.year - 1
self.set_day = None
-# test to see if the selection has a date and create event
+ # test to see if the selection has a date and create event
def TestDay(self, key):
try:
self.set_day = self.day
return key
-# find the clicked area rectangle
+ # find the clicked area rectangle
def GetDayHit(self, mx, my):
for key in self.rg.keys():
return None
-# calendar drawing
+ # calendar drawing
- def SetWeekColor(self, font_color, week_color): # set font and background color for week title
+ def SetWeekColor(self, font_color, week_color):
+ # set font and background color for week title
self.week_font_color = font_color
self.week_color = week_color
self.select_list.append(list_val)
def ShowWeekEnd(self):
- self.show_weekend = True # highlight weekend
+ # highlight weekend
+ self.show_weekend = True
def SetBusType(self):
self.cal_type = "BUS"
else:
size = self.size
-# drawing attributes
+ # drawing attributes
cal.week_font_color = self.week_font_color
cal.week_color = self.week_color
DC.EndDrawing()
-# draw the selection rectangle
-
+ # draw the selection rectangle
def DrawRect(self, key, color = 'BLACK', width = 0):
if key == None:
return
DC.EndDrawing()
-# set the day selection
+ # set the day selection
def SetDay(self, day):
day = day + self.st_pos - 1
def SelectDay(self, key):
sel_size = 1
- self.DrawRect(self.sel_key, self.back_color, sel_size) # clear large selection
+ # clear large selection
+ self.DrawRect(self.sel_key, self.back_color, sel_size)
if self.hide_grid is False:
self.DrawRect(self.sel_key, self.grid_color)
self.DrawRect(key, self.sel_color, sel_size)
- self.sel_key = key # store last used by
+ # store last used by
+ self.sel_key = key
self.select_day = None
def ClearDsp(self):
def __init__(self, parent, month=None, day = None, year=None):
wx.Dialog.__init__(self, parent, -1, "Event Calendar", wx.DefaultPosition, (280, 360))
- # set the calendar and attributes
- self.calend = wxCalendar(self, -1, (20, 60), (240, 200))
+ # set the calendar and attributes
+ self.calend = Calendar(self, -1, (20, 60), (240, 200))
if month == None:
self.calend.SetCurrentDay()
self.calend.HideTitle()
self.ResetDisplay()
- # get month list from DateTime
+ # get month list from DateTime
monthlist = GetMonthList()
- # select the month
+ # select the month
self.date = wx.ComboBox(self, -1, Month[start_month], (20, 20), (90, -1),
monthlist, wx.CB_DROPDOWN)
self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, self.date)
- # alternate spin button to control the month
+ # alternate spin button to control the month
h = self.date.GetSize().height
self.m_spin = wx.SpinButton(self, -1, (130, 20), (h*2, h), wx.SP_VERTICAL)
self.m_spin.SetRange(1, 12)
self.m_spin.SetValue(start_month)
self.Bind(wx.EVT_SPIN, self.OnMonthSpin, self.m_spin)
- # spin button to control the year
+ # spin button to control the year
self.dtext = wx.TextCtrl(self, -1, str(start_year), (160, 20), (60, -1))
h = self.dtext.GetSize().height
btn = wx.Button(self, -1, ' Ok ', (x_pos, y_pos), but_size)
self.Bind(wx.EVT_BUTTON, self.OnOk, btn)
- btn = wx.Button(self, mID, ' Close ', (x_pos + 120, y_pos), but_size)
+ btn = wx.Button(self, -1, ' Close ', (x_pos + 120, y_pos), but_size)
self.Bind(wx.EVT_BUTTON, self.OnCancel, btn)
def OnOk(self, event):
def OnCancel(self, event):
self.EndModal(wx.ID_CANCEL)
-# log the mouse clicks
+ # log the mouse clicks
def MouseClick(self, evt):
self.month = evt.month
- self.result = [evt.click, str(evt.day), Month[evt.month], str(evt.year)] # result click type and date
+ # result click type and date
+ self.result = [evt.click, str(evt.day), Month[evt.month], str(evt.year)]
if evt.click == 'DLEFT':
self.EndModal(wx.ID_OK)
-# month and year spin selection routines
+ # month and year spin selection routines
def OnMonthSpin(self, event):
month = event.GetPosition()
self.date.SetValue(Month[month])
self.calend.SetMonth(monthval+1)
self.ResetDisplay()
-# set the calendar for highlighted days
+ # set the calendar for highlighted days
def ResetDisplay(self):
month = self.calend.GetMonth()