开发者

Telling if an Instance has been Destroyed

开发者 https://www.devze.com 2023-02-14 10:28 出处:网络
I have a list of instances of objects (wxPython widgets). I\'d like to be able to tell if an instance within my list has been destroyed. How would o开发者_如何转开发ne go about this? wxPython widgets

I have a list of instances of objects (wxPython widgets). I'd like to be able to tell if an instance within my list has been destroyed. How would o开发者_如何转开发ne go about this?


wxPython widgets are False when they're destroyed. So you can simply do this:

if self.textCtrl:
   self.textCtrl...
else:
   return # textCtrl is destroyed


Assuming wxPython is playing by the rules and by "destroyed" you mean "is no longer referenced", then the weakref module in the standard library should let you do what you want (specifically, you can register a callback when creating a weak reference that is invoked just before the target of the weak reference is destroyed).

If wxPython isn't playing by the rules, or has disabled weak referencing for its objects, you may be out of luck.


This is applicable to all wx.Window derived objects. If it has been destroyed or disposed, it won't be None, but it will be False.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号