Search code examples
wxpythonwxwidgets

wx python cursor not released after mouse up event


I am using a slider control to set a dimension in my application. Unfortunately the cursor seems to be locked to the slider control after the EVT_LEFT_UP event and I need to click somewhere else on the application to release it. I am probably missing something simple, but what is it?

    import wx


    class Example(wx.Frame):
        def __init__(self):
            wx.Frame.__init__(self, None, -1, 'Slider control')
            self.Centre()
            self.sldr_size = wx.Slider(self, 100, 0, 1, 100, size=(250, -1), style=wx.SL_HORIZONTAL )
            self.sldr_size.Bind(wx.EVT_LEFT_UP, self.sldr_size_button_up)
            sizer = wx.GridBagSizer()
            sizer.Add(self.sldr_size, pos=(0, 0))
            self.SetSizer(sizer)
            self.sldr_size.SetValue(33)
            self.Show()

        def sldr_size_button_up(self, event):
            del event
            self.item_size = 1.3 - float(self.sldr_size.GetValue())/100
            print self.item_size

    if __name__ == '__main__':
        simple_screen_app = wx.App()
        main_frame = Example()
        main_frame.Show(True)
        simple_screen_app.MainLoop()

Edit: simplify code


Solution

  • The native slider widget most likely has a build-in event handler for EVT_LEFT_UP which releases the mouse capture. Since you have intercepted the EVT_LEFT_UP event then you are preventing that built-in handler from being called. You can tell the event processing system to continue looking for matching handlers, as it would have if yours was not there, by calling event.Skip() in your handler.