From: Bernie H. <ber...@ut...> - 2005-05-22 20:32:16
|
Hi Brad,=20 All windows have an OnClose() method: It derails any closing event =AD so be sure to have a self.Destroy a the end = =AD in the middle just stick in what you want. Try this: def OnClose(self, event): dlg =3D wxMessageDialog(self, "Would you like to save before you close?", "Hmmm....", wxYES_NO) if (dlg.ShowModal() =3D=3D wxID_YES): self.doSave(event) self.Destroy() BERNiE Bernie Hogan PhD Student Department of Sociology NetLab, Knowledge Media Design Institute University of Toronto I received a message from bra...@om... at approximately 5/22/05 4:21 PM. Above is my reply. >=20 > When a window closes, I want to prompted the user to save changes if need= ed. > The script=20 > below seems to work fine for that, except for one glitch: if the user edi= ts a > field, then clicks > the closebox on the window, an on_closefield never gets sent. I'd like to= send > a closefield=20 > event to the widget that has the focus (if it's a field). I've tried usin= g > self.components.getFocus, > among other things...there must be something obvious I'm missing. >=20 > Thanks! >=20 >=20 > def on_close (self, event): > print 'caught a close window' > if hasattr (self, 'entity'): > if len (self.entity.newData) > 0: > result =3D self.warningUnsavedChanges() > if result.accepted: > if result.returnedString =3D=3D 'No': > print "Don't save changes; c= lose > window"=20 > self.revert() > self.visible =3D False > else: > #save changes > try: > self.save() > self.visible =3D False > except Exception, thisErr: > errMsg =3D str(thisErr= ) > self.warningGeneral > ('Problem saving changes: ' + errMsg) > else: > pass #do nothing; do not close wind= ow > else: > #nothing to save > self.visible =3D False > else: > print "this must not be a window with a DbEntity; > nothing to save"=20 > event.skip() > =20 --=20 |