CalendarCtrl not responding to clicks with SashLayoutWindow

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()

Hi Alan,

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....)

The problem is with your code in "CreateCalendar" you are parenting the calendar to self instead of subpanel.

I discovered this by experimenting, i.e. didn't see why you needed a panel etc and not just have the calendar control on the SashLayoutWindow. When I had it directly it worked, so then went back and saw that you had the parenting wrong - this I noticed by looking at the application using the WIT (http://wiki.wxpython.org/Widget%20Inspection%20Tool).

Werner

BTW, attaching code is easier as it doesn't mess with the indentation etc.

calctrl.py (3.97 KB)

···

On 11/22/2011 04:55 PM, Alan Ristow wrote:

Thanks,

Alan

Hi Werner,

Hi Alan,

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 problem is with your code in "CreateCalendar" you are parenting the
calendar to self instead of subpanel.

Thanks for that. Last evening I did manage to discover that the
problem was not where I thought it was, but I had not yet figured out
that it was the parenting. I would have updated the thread, but my
message took forever to show up in my inbox....

this I noticed by looking at the application using the WIT
(http://wiki.wxpython.org/Widget%20Inspection%20Tool).

Thanks for the tip! I'm coming back to wxPython after a long layoff
and completely forgot that the WIT exists.

BTW, attaching code is easier as it doesn't mess with the indentation etc.

Good to know. Other mailing lists I have been on discourage
attachments, but I can see how the advantage of using them for Python
code.

Thanks again,

Alan

···

On Tue, Nov 22, 2011 at 8:26 PM, werner <wbruhin@free.fr> wrote:

On 11/22/2011 04:55 PM, Alan Ristow wrote: