【发布时间】:2018-06-07 12:07:24
【问题描述】:
我为微控制器编写了一个模拟器,我将函数的结果与事件一起传递给 GUI。问题是绑定到事件的函数从未被调用。 我在两个不同的线程中有 GUI 和模拟器。
'''Event class'''
NewRAMEvent = wx.NewEventType()
EVT_NEW_RAM = wx.PyEventBinder(NewRAMEvent, 1)
class RAM_Event(wx.PyCommandEvent):
def __init__(self, location = None, val = None):
wx.PyCommandEvent.__init__(self)
self._location = location
self._val = val
def SetVals(self, val, loc):
self._location = loc
self._val = val
def GetVal(self):
return self._val
def GetLocation(self):
return self._location
'''Creating event'''
evt1 = RAM_Event(0x03, uC.programCounter)
wx.CallAfter(recipient.ProcessEvent, evt1)
print("RAM event sent")
'''adding recipient to list and creating thread for simulator'''
simuThread = SimulatorThread()
simuThread.add_event_recipient(Myfrm)
'''GUI class'''
self.Bind(EVT_NEW_RAM, self.updateRAM)
def updateRAM(self, event):
print("received Event")
location = event.GetLocation()
value = event.GetVal()
print("value:", value)
RAM.writeToTable(self, location, value)
return
当我查看控制台时,我看到消息已发送但未收到。
【问题讨论】: