why should I play on me own or, if you ever wondered what cloning is good for
import wx
class MyEvent(wx.PyEvent):
def __new__(cls):
if 'EventType' not in vars(cls):
cls.EventType = wx.GetApp()._my_evt_type_
return super().__new__(cls)
def __init__(self):
super().__init__(eventType=__class__.EventType)
print(f'{self} __init__ C++ {wx.siplib.isdeleted(self)}')
def __del__(self):
print(f'{self} __del__ C++ {wx.siplib.isdeleted(self)}')
def evt_test(evt):
'''only clones are send into space..and fade away (after usage)'''
print(f'{evt} {evt.count=}')
class Gui(wx.Frame):
def __init__(self, parent):
print(f'{self.__class__} __init__')
super().__init__(parent, title='PyEvent Class (cloning)')
btn = wx.Button(self, label='left click me, please')
btn.Bind(wx.EVT_BUTTON, self.test)
self.Centre()
self.Show()
self.evt = MyEvent()
self.Bind(wx.PyEventBinder(self.evt.EventType), evt_test)
self.evt.count = 0
def __del__(self):
self.evt.Destroy()
print(f'\n{self.__class__} __del__')
def test(self, _):
print(f'\n{self.evt} being posted..')
# self.QueueEvent(self.evt)
self.AddPendingEvent(self.evt)
# wx.PostEvent(self, self.evt)
self.evt.count += 1
if __name__ == '__main__':
app = wx.App()
app._my_evt_type_ = wx.NewEventType()
Gui(None)
app.MainLoop()