I wrote a simple (but sufficient for my needs) journaling app that uses the wx.adv.GenericCalendarCtrl control. I would like to change the font style of the days so that the day number is shown in bold (or another colour) if there is a journal entry for that day. Is this possible?
It’s derived from wx.Windows… so it should have a regular “SetFont” method… doesn’t work?
What I’ve been able to glean (following multiple “see also” links) is
If I want to display certain days in red text I do
attr = wx.adv.CalendarDateAttr(colText = wx.RED)
self.calendar.SetAttr(daynum, attr)
This causes my app to exit with no error.
I believe SetFont is to set the font for the entire control, not individual days.
Yes, I misread your intentions… “exit with no error” is a bit too vague to investigate, but this code works fine for me anyway:
import wx, wx.adv
class Main(wx.Frame):
def __init__(self, *a, **k):
wx.Frame.__init__(self, *a, **k)
p = wx.Panel(self)
b = wx.Button(p, -1, 'update', pos=(10, 10))
b.Bind(wx.EVT_BUTTON, self.update_attr)
self.cal = wx.adv.GenericCalendarCtrl(p, pos=(10, 50))
self.cal.SetAttr(4, wx.adv.CalendarDateAttr(
colBorder=wx.RED,
border=wx.adv.CAL_BORDER_ROUND))
self.cal.SetAttr(5, wx.adv.CalendarDateAttr(
colBack=wx.BLACK,
colText=wx.WHITE))
self.cal.SetAttr(6, wx.adv.CalendarDateAttr(
font=wx.Font(14,
wx.FONTFAMILY_ROMAN,
wx.FONTSTYLE_ITALIC,
wx.FONTWEIGHT_BOLD)))
def update_attr(self, evt):
self.cal.SetAttr(7, wx.adv.CalendarDateAttr(
colBorder=wx.BLACK,
border=wx.adv.CAL_BORDER_SQUARE))
self.cal.ResetAttr(4)
self.cal.Refresh()
if __name__ == '__main__':
app = wx.App()
Main(None).Show()
app.MainLoop()
That’s exactly what I was looking for. Thanks.