SashWindow event-binding problem

Bob Klahn bobklahn at comcast.net
Mon Oct 1 15:26:17 PDT 2007


The attached file is the wxPython 2.8.4 sash window demo, modified to 
demonstrate an event-binding problem:

Despite binding both wx.EVT_LEFT_DOWN and wx.EVT_KEY_DOWN to 
self.OnUserAction, self.OnUserAction is not called when the left 
mouse button is pressed or when a key is pressed.

What am I missing here?

Bob
-------------- next part --------------
import  wx

# Extracted from the wxPython 2.8.4 demo
# to demonstrate an event-binding problem:
#
#     Despite binding both wx.EVT_LEFT_DOWN and wx.EVT_KEY_DOWN
#     to self.OnUserAction, self.OnUserAction is not called when
#     the left mouse button is pressed or when a key is pressed.
#
#     What am I missing here?
#

#---------------------------------------------------------------------------

class TestSashWindow(wx.Panel):

    def __init__(self, parent, log):
        wx.Panel.__init__(self, parent, -1)

        self.log = log
        winids = []

        # A window to the left of the client window
        leftwin1 =  wx.SashLayoutWindow(
                self, -1, wx.DefaultPosition, (200, 300),
                wx.NO_BORDER|wx.SW_3D
                )

        leftwin1.SetDefaultSize((200, 1000))
        leftwin1.SetOrientation(wx.LAYOUT_VERTICAL)
        leftwin1.SetAlignment(wx.LAYOUT_LEFT)
        leftwin1.SetBackgroundColour(wx.Colour(0, 255, 0))
        leftwin1.SetSashVisible(wx.SASH_RIGHT, True)
        leftwin1.SetExtraBorderSize(10)

        self.leftWindow1 = leftwin1
        winids.append(leftwin1.GetId())

        # Another window to the left of the client window
        leftwin2 = wx.SashLayoutWindow(
                self, -1, wx.DefaultPosition, (200, 300),
                wx.NO_BORDER|wx.SW_3D
                )

        leftwin2.SetDefaultSize((200, 1000))
        leftwin2.SetOrientation(wx.LAYOUT_VERTICAL)
        leftwin2.SetAlignment(wx.LAYOUT_RIGHT)
        leftwin2.SetBackgroundColour(wx.Colour(0, 255, 255))
        leftwin2.SetSashVisible(wx.SASH_LEFT, True)

        self.leftWindow2 = leftwin2
        winids.append(leftwin2.GetId())

        # will occupy the space not used by the Layout Algorithm
        self.remainingSpace = wx.Panel(self, -1, style=wx.SUNKEN_BORDER)

        self.Bind(
            wx.EVT_SASH_DRAGGED_RANGE, self.OnSashDrag,
            id=min(winids), id2=max(winids)
            )

        self.Bind(wx.EVT_SIZE, self.OnSize)

        self.Bind(wx.EVT_LEFT_DOWN, self.OnUserAction)
        self.Bind(wx.EVT_KEY_DOWN , self.OnUserAction)

    def OnUserAction():
        self.log.write('OnUserAction\n')

    def OnSashDrag(self, event):
        if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE:
            self.log.write('drag is out of range\n')
            return

        eobj = event.GetEventObject()

        if   eobj is self.leftWindow1:
            self.log.write('leftwin1 received drag event\n')
            self.leftWindow1.SetDefaultSize((event.GetDragRect().width, 1000))

        elif eobj is self.leftWindow2:
            self.log.write('leftwin2 received drag event\n')
            self.leftWindow2.SetDefaultSize((event.GetDragRect().width, 100))

        wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
        self.remainingSpace.Refresh()

    def OnSize(self, event):
        wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace)

#---------------------------------------------------------------------------

class TestFrame(wx.Frame):
    def __init__(self, parent, log):
        wx.Frame.__init__(self, parent, -1, "SashWindow", size=(600,400))
        win = TestSashWindow(self, log)

#---------------------------------------------------------------------------

if __name__ == '__main__':
    import sys

    app = wx.PySimpleApp()
    frame = TestFrame(None, sys.stdout)
    frame.Show(True)
    app.MainLoop()

-------------- next part --------------



More information about the wxpython-users mailing list