Phoenix icon indicating copy to clipboard operation
Phoenix copied to clipboard

exception on grid labels click in 4.1.1a

Open mprosperi opened this issue 4 years ago • 9 comments

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

mprosperi avatar Nov 07 '20 18:11 mprosperi

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.

RobinD42 avatar Nov 10 '20 21:11 RobinD42

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

mprosperi avatar Nov 21 '20 07:11 mprosperi

should be re-opened. It's also present in the new 4.1.1

mprosperi avatar Nov 26 '20 18:11 mprosperi

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.

DietmarSchwertberger avatar Dec 20 '21 17:12 DietmarSchwertberger

Recently I found that wx has an event EVT_GRID_COL_MOVE. Unfortunately, there's no ROW version. Otherwise gridmovers coould be dropped.

DietmarSchwertberger avatar Feb 15 '22 18:02 DietmarSchwertberger

OK, I think actually this is to be fixed on the wxPython end.

  • The check in OnPress should probably be wx.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 for self.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 both GridColMover and GridRowMover
  • comment out the CaptureMouse and ReleaseMouse 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.

DietmarSchwertberger avatar Apr 02 '22 14:04 DietmarSchwertberger

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

mprosperi avatar Apr 07 '22 17:04 mprosperi

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.

DietmarSchwertberger avatar Apr 07 '22 17:04 DietmarSchwertberger

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

DietmarSchwertberger avatar May 02 '22 21:05 DietmarSchwertberger

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: @.***>

mprosperi avatar Oct 11 '22 08:10 mprosperi