--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On 06/18/2018 11:17 AM, Eric Fahlgren wrote:
We have a handful of pure-Python classes, not derived from any wxWidgets class, that emulate the API of things like Menu or MenuItem (as a simple example). When constructing these objects, they are currently assigned an id using wx.NewId(), which is then used to bind them to various events. We can't use wx.ID_ANY (-1) for these, since that's simply a flag to wxWidgets to generate a real id. Is there some sanctioned means for generating a unique id that is not deprecated?
How will all the 100+ calls to NewId in wxPython itself, like the one below, be fixed?
On 06/18/2018 11:17 AM, Eric Fahlgren wrote:
We have a handful of pure-Python classes, not derived from any wxWidgets class, that emulate the API of things like Menu or MenuItem (as a simple example). When constructing these objects, they are currently assigned an id using wx.NewId(), which is then used to bind them to various events. We can't use wx.ID_ANY (-1) for these, since that's simply a flag to wxWidgets to generate a real id. Is there some sanctioned means for generating a unique id that is not deprecated?
How will all the 100+ calls to NewId in wxPython itself, like the one below, be fixed?
+1
Johnf
obj = SomeWidget(self, wx.ID_ANY, ...)obj.Bind(wx.EVT_SOMETHING, self.myHandler)
obj = SomeWidget(self, wx.ID_ANY, ...)self.Bind(wx.EVT_SOMETHING, self.myHandler)
objA = SomeWidget(self, wx.ID_ANY, ...)objB = SomeWidget(self, wx.ID_ANY, ...)self.Bind(wx.EVT_SOMETHING, self.myAHandler, objA)self.Bind(wx.EVT_SOMETHING, self.myBHandler, objB)
item = menu.Append(wx.ID_ANY, "&Foo", "Do some foo stuff")self.Bind(wx.EVT_MENU, self.onDoFoo, item)
item = menu.Append(wx.ID_ANY, "&Foo", "Do some foo stuff")toolbar.AddTool(item.GetId(), "Foo", fooBmp, "Do Some Foo stuff")self.Bind(wx.EVT_MENU, self.onDoFoo, item)
def OnHandleButtons(self, evt):if evt.GetId() == ID_A:self.doSomething()elif evt.GetId() == ID_B:self.doSomethingElse()...
def OnHandleButtons(self, evt):if evt.GetEventObject() is self.objA:self.doSomething()elif evt.GetEventObject() is self.objB:self.doSomethingElse()...
This a good tutorial - maybe in can be on the website?
Johnf
This a good tutorial - maybe in can be on the website?
--Robin
def ref_id():
return wx.NewId()
try: #Work around for wxpython prior to 4.0.2 where wx.NewIdRef first appeared
TestId = wx.NewIdRef()
except:
wx.NewIdRef = ref_id