Phoenix
Phoenix copied to clipboard
exception on grid labels click in 4.1.1a
Operating system: win 10 wxPython version & source: wxPython-4.1.1a1.dev5032+4402d875-cp37-cp37m-win_amd64 Python version & source: 3.7, stock
Description of the problem:
In my app is systematic to get the following exception with a single click on a grid column label while in the demo GridDragable.py you should repeatedly click with left and right mouse button on a label to get it.
Traceback (most recent call last): File "c:\users\user1\envs\af4137\lib\site-packages\wx\lib\gridmovers.py", line 327, in OnPress self.lwin.CaptureMouse() wx._core.wxAssertionError: C++ assertion "!wxMouseCapture::IsInCaptureStack(this)" failed at ....\src\common\wincmn.cpp(3326) in wxWindowBase::CaptureMouse(): Recapturing the mouse in the same window?
The problem doesn't occur with wxpython4.1.0 Could it eventually be related to this? https://github.com/wxWidgets/wxWidgets/commit/408ebfd253144ef3535932314a42fe34256d4a56
Is an exception that could be avoided with changes in gridmovers code?
Marco
Is an exception that could be avoided with changes in gridmovers code?
Yes, it could probably benefit from checking for the capture before capturing it or releasing it.
should this fix be present in wxPython-4.1.1a1.dev5062+6f9b1fb1-cp37-cp37m-win_amd64.whl? If so there is still an exception raised (open "a wx.Grid with draggable rows and columns" in the demo and left click on description label, win10, py3.7)
wx._core.wxAssertionError: C++ assertion ""!wxMouseCapture::stack.empty()"" failed at ....\src\common\wincmn.cpp(3374) in wxWindowBase::ReleaseMouse(): Releasing mouse capture but capture stack empty?
The above exception was the direct cause of the following exception:
SystemError: <class 'wx._core.IdleEvent'> returned a result with an error set
should be re-opened. It's also present in the new 4.1.1
The problem is still there with recent snapshots.
I have just tested wxPython-4.1.2a1.dev5259+d3bdb143-cp39-cp39-win_amd64
in the last days.
P.S.:
At least in my application, the call in OnPress
to wx.Window.GetCapture()
does return None
, so CaptureMouse
is not called. But anyway it does not make a difference.
Removing evt.Skip()
would fix the exception, but does interfere with exception handling.
Recently I found that wx has an event EVT_GRID_COL_MOVE
. Unfortunately, there's no ROW
version. Otherwise gridmovers coould be dropped.
OK, I think actually this is to be fixed on the wxPython end.
- The check in
OnPress
should probably bewx.Window.GetCapture() is None
-
evt.Skip()
should probably not be called, as then wxWidget's grid.cpp will handle it as well and will capture the mouse. - The check in
OnRelease
forself.lwin.HasCapture()
is also true if grid.cpp has captured the mouse, not gridmovers. - The mouse should not be captured twice for the same window.
The question is whether gridmovers.py
should capture the mouse at all. I'm in preference of not capturing, but instead handling EVT_LEAVE_WINDOW
.
Probably it's fine to bind the event to OnRelease
:
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnRelease)
@mprosperi : would you mind trying it out and give feedback?
- add the
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnRelease)
to bothGridColMover
andGridRowMover
- comment out the
CaptureMouse
andReleaseMouse
related code
I think the user experience is OK. If the user drags outside the row or column label window, the dragging stops.
Medium term I would like to get rid of gridmovers. I'm preparing a PR for wxWidgets to implement EnableDragRowMove / EVT_GRID_ROW_MOVE
.
If you need only column moving, then you can handle EVT_GRID_COL_MOVE
today already.
I followed your solution and it works fine. I've tried only on win10 but with an app that provides the user with several interactions on column labels (tooltips, textctrl for filtering) and everything works as expected
thank you
good
In the next days I will submit a PR to fix the issue.
Another PR has been merged into wxWidgets. The next version will have support for EVT_GRID_COL_MOVE
. Then it's time to bury gridmovers.py
with one of the next wxPython versions.
@mprosperi : PR #2144 is submitted.
You may want to test the version at https://raw.githubusercontent.com/DietmarSchwertberger/Phoenix/ISSUE_1841/wx/lib/gridmovers.py The user interface is slightly better: The mouse is now captured again.
works fine, thank for your time
Marco
Il giorno lun 2 mag 2022 alle ore 23:07 Dietmar Schwertberger < @.***> ha scritto:
@mprosperi https://github.com/mprosperi : PR #2144 https://github.com/wxWidgets/Phoenix/pull/2144 is submitted.
You may want to test the version at https://raw.githubusercontent.com/DietmarSchwertberger/Phoenix/ISSUE_1841/wx/lib/gridmovers.py The user interface is slightly better: The mouse is now captured again.
— Reply to this email directly, view it on GitHub https://github.com/wxWidgets/Phoenix/issues/1841#issuecomment-1115368396, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADTPVI2OEYJBQYETHOL66WDVIA7YJANCNFSM4TNZVA6A . You are receiving this because you were mentioned.Message ID: @.***>