I’m on wxPython version 4.0.7.post2, and Python version 3.8.2. I’ve enabled warnings to catch the things I need to change in preparation for upgrading both Python and wxPython. One of the warnings I get is that wx.NewId()
is deprecated. According to documentation, I should be using wx.NewIdRef()
, which is supposed to be a drop-in replacement. Indeed, replacing all instances of wx.NewId()
with wx.NewIdRef()
works, but all the functions that take the id as a parameter trigger a new warning:
DeprecationWarning: an integer is required (got type WindowIDRef).
Implicit conversion to integers using int is deprecated, and may
be removed in a future version of Python.
Fine I say, let us use wx.NewIdRef().GetId()
instead. i.e.:
my_id = wx.NewIdRef().GetId()
target.Bind(wx.EVT_MENU, self.foo, id=my_id)
This gives me the following error:
wx._core.wxAssertionError: C++ assertion “gs_autoIdsRefCount[winid] !=
ID_FREE” failed at ….srccommonwindowid.cpp(110) in
`anonymous-namespace’::IncIdRefCount(): id should first be reserved
OK then, since it looks like passing wx.NewIdRef
triggers an implicit __int__()
conversion, what if I do this: my_id = wx.NewIdRef().__int__()
?
Same error. Does wx.NewIdRef
have a function to manually reserve it? Nope.
So what’s the deal? How am I supposed to use wx.NewIdRef()
correctly? And can I use wx.Window.NewControlId()
instead?