Say you’re writing a wxPython GUI, and you want a menuitem that spawns a popup frame, and that stays disabled until that popup is gone.
The obvious thing would be to do this.
self.popup_menuitem.Enable(False) self.popup_frame = wx.Frame(self, wx.ID_ANY) self.popup_frame.Show() def destroyed_callback(e): self.popup_menuitem.Enable(True) self.popup_frame.Bind(wx.EVT_WINDOW_DESTROY, destroyed_callback)
Disable the menuitem, spawn the popup, and reenable on destruction.
Problem: What if you close the parent window first?
That’ll also cause the popup to close. But by then, there’s no menu left to toggle because the parent’s gone. You may get a PyDeadObjectError, or the OS will step in to complain. Bad.
Read the rest of this entry »

