ShapedButton SBitmapToggleButton ReleaseMouse error (and demo issue)

54 views
Skip to first unread message

Mike Driscoll

unread,
Jun 9, 2010, 5:23:25 PM6/9/10
to wxPytho...@googlegroups.com
Hi,

I am having some odd trouble with SBitmapToggleButton. If I bind it to an event handler and just print in the handler, it works fine. If I try to open a dialog, I get a PyAssertionError when I close the dialog. Here's the traceback:

wx._core.PyAssertionError: C++ assertion "GetCapture() == this" failed at ..\..\src\common\wincmn.cpp(2536) in wxWindowBase::ReleaseMouse(): attempt to release mouse, but this window hasn't captured it
File "c:\mldStuff\Profile\My Documents\My Dropbox\Scripts\wx tutorials\buttons\shapedBtnDemo.py", line 82, in <module>
app.MainLoop()
File "c:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 8007, in MainLoop
wx.PyApp.MainLoop(self)
File "c:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7303, in MainLoop
return _core_.PyApp_MainLoop(*args, **kwargs)
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\shapedbutton.py", line 1301, in OnLeftUp
self.ReleaseMouse()
File "c:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 9741, in ReleaseMouse
return _core_.Window_ReleaseMouse(*args, **kwargs)

I have attached a small runnable example that demonstrates the issue. I am running wxPython 2.8.11.0 (unicode), Python 2.5, Windows XP. Also, the ShapedButton demo has a small issue. If you press the "play" button and then try to untoggle it, it retoggles itself.

--
-----------------
Mike Driscoll

Blog:   http://blog.pythonlibrary.org
sbitmaptoggle.py

Cody Precord

unread,
Jun 9, 2010, 6:14:26 PM6/9/10
to wxpytho...@googlegroups.com
Hi,

The ReleaseMouse call should be guarded with a HasCapture check. Its
throwing an assertion since the window doesn't have the capture.


Cody

Mike Driscoll

unread,
Jun 9, 2010, 7:36:47 PM6/9/10
to wxpytho...@googlegroups.com
Are you saying I need to implement this functionality? I looked at the ShapedButton's code and it looks like it has a HasCapture check in the OnLeftUp method (lines 1066-1076).

Cody Precord

unread,
Jun 9, 2010, 7:51:31 PM6/9/10
to wxpytho...@googlegroups.com
Hi,

On Wed, Jun 9, 2010 at 6:36 PM, Mike Driscoll <mi...@pythonlibrary.org> wrote:
>
> Are you saying I need to implement this functionality? I looked at the
> ShapedButton's code and it looks like it has a HasCapture check in the
> OnLeftUp method (lines 1066-1076).

No, sorry I should have been more clear. If thats the case its a bug
in the control. It should release the mouse capture before sending its
event. The error is happening because it is dispatching another event
with its Notify() method while still in the context of handling the
mouse event. So its notify will cause your event handler to execute
at which point the control will loose the mouse capture when you show
your dialog. Then when control returns to the event handler after
Notify and it calls ReleaseMouse it no longer has the capture.

A patch would be to move

if self._isup != self._saveup:
self.Notify()

after the ReleaseMouse call in shapedbutton.py.

A workaround in your code would be to do a CallAfter to show the dialog.


Cody

Robin Dunn

unread,
Jun 9, 2010, 8:05:20 PM6/9/10
to wxpytho...@googlegroups.com
On 6/9/10 4:36 PM, Mike Driscoll wrote:
>
> Are you saying I need to implement this functionality? I looked at the
> ShapedButton's code and it looks like it has a HasCapture check in the
> OnLeftUp method (lines 1066-1076).

The problem is probably that the button is sending the event before it
does the release. So yes, it is checking that it still has the capture,
but then your event handler is being called and showing the dialog will
cause the capture to be lost, and then when it gets back to OnLeftUp it
is trying to release the capture it no longer has. Please test moving
the release to before the if statement that results in self.Notify being
called.

--
Robin Dunn
Software Craftsman
http://wxPython.org

Reply all
Reply to author
Forward
0 new messages