Hi all,
I put together a very simple class based on CalendarCtrl and it worked
just fine in an ordinary wx.Panel. Now I would like to use it in a
SashLayoutWindow. I have had little trouble getting it to display the
way I would like, but for some reason the calendar does not respond to
clicks. The issue is not just that my EVT_CALENDAR_SEL_CHANGED
callback is not being called, but that the calendar completely fails
to respond -- the date does not change when the CalendarCtrl is
clicked, nor does the month change when the month-changing arrows are
clicked.
I have attached demo code below. Am I missing something obvious that
is keeping my clicks from getting through to the CalendarCtrl? Is
there some sort of incompatibility between CalendarCtrl and
SashLayoutWindow? Any help would be appreciated! (And apologies if the
code is not minimal enough -- it does feel a little long to me -- but
at this point, anything I comment seems to result in the code not
functioning correctly....)
Thanks,
Alan
### BEGIN DEMO CODE ###
import wx
import wx.calendar as cal
class CalendarPanel(wx.Panel):
def __init__(self, parent, id, pos = wx.DefaultPosition, size =
wx.DefaultSize,
style = wx.NO_BORDER | wx.TAB_TRAVERSAL):
wx.Panel.__init__(self, parent, id, pos, size, style)
self.CreateCalendar()
self.GetSizer().Fit(self)
self.GetSizer().SetSizeHints(self)
self.GetSizer().Layout()
def CreateCalendar(self):
sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(sizer)
subpanel = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
wx.NO_BORDER | wx.TAB_TRAVERSAL)
sizer.Add(subpanel, 1, wx.GROW | wx.ADJUST_MINSIZE, 5)
subsizer = wx.BoxSizer(wx.VERTICAL)
subpanel.SetSizer(subsizer)
default_date = wx.DateTime_Now() - wx.DateSpan_Day()
self._calendar = cal.CalendarCtrl(self, wx.ID_ANY,
default_date, pos = wx.DefaultPosition,
size = wx.DefaultSize, style
= cal.CAL_SHOW_HOLIDAYS
> cal.CAL_MONDAY_FIRST |
cal.CAL_SEQUENTIAL_MONTH_SELECTION)
self.Bind(cal.EVT_CALENDAR_SEL_CHANGED,
self.OnCalendarSelected, id = self._calendar.GetId())
subsizer.Add(self._calendar, 0, wx.GROW | wx.ALL, 5)
def OnCalendarSelected(self, event):
print 'Clicked the calendar!'
class AppFrame(wx.Frame):
def __init__(self,
parent = None,
id = wx.ID_ANY,
title = 'Application',
pos = wx.DefaultPosition,
size = (850, 600),
style = wx.DEFAULT_FRAME_STYLE):
wx.Frame.__init__(self, parent, id, title, pos, size, style)
self.ID_WINDOW_TOP = wx.NewId()
self.ID_WINDOW_LEFT = wx.NewId()
self.ID_WINDOW_BOTTOM = wx.NewId()
self._left_window = wx.SashLayoutWindow(self,
self.ID_WINDOW_LEFT, wx.DefaultPosition, wx.Size(200, 1000),
wx.NO_BORDER |
wx.SW_3D | wx.CLIP_CHILDREN)
self._left_window.SetDefaultSize(wx.Size(220, 1000))
self._left_window.SetOrientation(wx.LAYOUT_VERTICAL)
self._left_window.SetAlignment(wx.LAYOUT_LEFT)
self._left_window.SetSashVisible(wx.SASH_RIGHT, True)
self._left_window.SetExtraBorderSize(10)
self._right_window = wx.Panel(self, wx.ID_ANY)
calendar = CalendarPanel(self._right_window, wx.ID_ANY)
cal_sizer = wx.BoxSizer(wx.VERTICAL)
cal_sizer.Add(calendar, 1, wx.ALL, 5)
self._right_window.SetSizer(cal_sizer)
self._left_window.Bind(wx.EVT_SASH_DRAGGED_RANGE,
self.OnFoldPanelBarDrag,
id = self.ID_WINDOW_TOP, id2 =
self.ID_WINDOW_BOTTOM)
self.Bind(wx.EVT_SIZE, self.OnSize)
def OnSize(self, event):
wx.LayoutAlgorithm().LayoutWindow(self, self._right_window)
event.Skip()
def OnFoldPanelBarDrag(self, event):
if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE:
return
if event.GetId() == self.ID_WINDOW_LEFT:
self._left_window.SetDefaultSize(wx.Size(event.GetDragRect().width,
1000))
# Make sure the left window is correctly redrawn.
wx.LayoutAlgorithm().LayoutWindow(self, self._right_window)
self._right_window.Refresh()
event.Skip()
if __name__ == "__main__":
app = wx.App(False)
frame = AppFrame()
frame.Show()
app.MainLoop()