Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite recursion calling superclass EndEdit() in a GridCellNumberEditor subclass #2584

Open
andreamerello opened this issue Aug 5, 2024 · 0 comments

Comments

@andreamerello
Copy link

Operating system: Ubuntu 20.04
wxPython version & source: 4.2.1 (conda)
Python version & source: 3.12.2 (conda)

This has been reproduced also by other users

Description of the problem:

I end up in infinite recursion, with the following error getting printed on the console

...
...
End edit enter
End edit enter
object address  : 0x7ff66a8bd240
object refcount : 3
object type     : 0x55fb65c4e7e0
object type name: RecursionError
object repr     : RecursionError('maximum recursion depth exceeded while calling a Python object')
lost sys.stderr
End edit exit
End edit exit
...
...

This happens by doing those apparently licit steps:

  • Subclass GridCellNumberEditor
  • Override EndEdit()
  • Invoke the superclass EndEdit() method from within by overridden EndEdit() method
Code Example (click to expand)
import wx
import wx.grid as gridlib

class MyGridCellNumberEditor(gridlib.GridCellNumberEditor):
    def EndEdit(self, row, col, grid, oldval):
        print(f"End edit enter")
        super().EndEdit(row, col, grid, oldval)
        print(f"End edit exit")

class MyGrid(gridlib.Grid):
    def __init__(self, parent):
        super().__init__(parent, -1)
        self.CreateGrid(1, 1)
        self.SetCellEditor(0, 0, MyGridCellNumberEditor())

class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(None, title="Custom GridCellNumberEditor Example")
        panel = wx.Panel(self)
        grid = MyGrid(panel)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(grid, 1, wx.EXPAND)
        panel.SetSizer(sizer)
        self.SetSize((400, 300))

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame()
        frame.Show()
        return True

if __name__ == "__main__":
    app = MyApp(False)
    app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant