Python 和 Phidgets:想要将事件/消息从对象发送到其父级
我有一个 Phidgets 步进控制器(Stepper 类),它允许事件处理程序成为该类的方法:
self.setOnAttachHandler(self.StepperAttached)
self.setOnDetachHandler(self.StepperDetached)
这些方法很有用,因为它们可以在步进控制器与 PC 连接/分离时执行任务。
我已经在 Python 中的 wxFrame 中创建了一个 Stepper 对象,并且想知道如何将这些消息发送到 wxFrame,以便它可以指示控制器已连接/分离而无需轮询。
或者一般来说,如何在 Python 中将事件/消息从对象发送到父对象?
谢谢!
I have a Phidgets stepper controller (Stepper class) and it allows event handlers to be methods of the class:
self.setOnAttachHandler(self.StepperAttached)
self.setOnDetachHandler(self.StepperDetached)
These are useful as they can perform tasks when the stepper controller is attached/detached from the PC.
I have created a Stepper object in a wxFrame in Python and would like to know how to send those messages to the wxFrame so that it can, for example, indicated that the controller has been attached/dettached without polling.
Or in general, how do I send events/messages from object to parent in Python?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行此操作的规范方法是将父对象的引用传递给子对象。
希望这有帮助。代码可能不太准确,因为我手边没有参考资料,但即使上面的代码略有偏差,原理也是相同的。
The canonical way to do this is to pass a reference of the parent object down into the children.
Hopefully this helps. Code might not be quite accurate, as I don't have a reference handy, but the principal is the same even if the code above is slightly off.