开发者

Telling if an Instance has been Destroyed

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜