Re: wx.Dialog not reported as destroyed after '.Destroy()' is called
Robin Dunn <[email protected]> Wed, 5 Jun 2019 12:28:53 -0700 (PDT)
| Newsgroups | gmane.comp.python.wxpython.devel |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_41_1798114816.1559762933779
Content-Type: multipart/alternative;
boundary="----=_Part_42_1864146471.1559762933779"
------=_Part_42_1864146471.1559762933779
Content-Type: text/plain; charset="UTF-8"
On Wednesday, June 5, 2019 at 7:49:25 AM UTC-7, Jasper Elzinga | Alexion
Software wrote:
>
> Hello,
>
> I'm having trouble checking the destroyed state of wx.Dialogs. When I call
> '.Destroy()' and do a 'wx.Yield()' the dialog is not reported as destroyed:
>
>
> As far as I know this is the way it should be done according to a couple
> posts of people with similar questions.
>
> I've tried many other things like multiple yields, time.sleep(),
> self.Refresh(), self.Update(). I've found one thing: if i create a new
> dialog and call '.ShowModal()', the first (destroyed) dialog is correctly
> reported as destroyed
>
When top-level windows are destroyed they are not killed immediately but
are instead added to a list of windows to be destroyed later. What "later"
actually means in this case is a little nebulous. I don't remember for
sure, but I think it happens after EVT_IDLE events are sent and processed,
or as part of the wx.App's EVT_IDLE handler, or something like that. Also,
IIRC, the idle events are not sent during a wx.Yield, because the
application is not idle at that point in time. (There are the pending
events that need processed, if any, and then there is the code after the
call to Yield that is waiting to run.
If you allow control to return to the event loop and then check the state
of the dialog a little later, then most likely it has been destroyed by
then. It's not guaranteed however, because if the app is really busy then
there may not have been a chance to process the idle events.
def OnButton(self, event):
dialog = wx.Dialog(self, -1, "ssss")
result = dialog.ShowModal()
dialog.Destroy()
wx.Yield()
wx.CallLater(100, self._later, dialog)
def _later(self, dialog):
print(self.GetChildren())
print( "wx version", wx.version())
print("is child", dialog in self.GetChildren())
print("is being deleted", dialog.IsBeingDeleted())
print("not yet destroyed", bool(dialog))
--
Robin
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxPython-dev/300ba12a-93fa-40e0-85c8-3fd902a50a4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
------=_Part_42_1864146471.1559762933779
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br>On Wednesday, June 5, 2019 at 7:49:25 AM UTC-7, Jasper=
Elzinga | Alexion Software wrote:<blockquote class=3D"gmail_quote" style=
=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: =
1ex;"><div dir=3D"ltr">Hello,<br><br><div>I'm having trouble checking t=
he destroyed state of wx.Dialogs. When I call '.Destroy()' and do a=
'wx.Yield()' the dialog is not reported as destroyed:</div><div><b=
r></div></div></blockquote><div>=C2=A0</div><div>=C2=A0<br></div><blockquot=
e class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: =
1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>As far as I know t=
his is the way it should be done according to a couple posts of people with=
similar questions.<br></div><div><br></div><div>I've tried many other =
things like multiple yields, time.sleep(), self.Refresh(), self.Update(). I=
've found one thing: if i create a new dialog and call '.ShowModal(=
)', the first (destroyed) dialog is correctly reported as destroyed</di=
v></div></blockquote><div><br></div><div>When top-level windows are destroy=
ed they are not killed immediately but are instead added to a list of windo=
ws to be destroyed later. What "later" actually means in this cas=
e is a little=C2=A0nebulous. I don't remember for sure, but I think it =
happens after EVT_IDLE events are sent and processed, or as part of the wx.=
App's EVT_IDLE handler, or something like that. Also, IIRC, the idle ev=
ents are not sent during a wx.Yield, because the application is not idle at=
that point in time. (There are the pending events that need processed, if =
any, and then there is the code after the call to Yield that is waiting to =
run.</div><div><br></div><div>If you allow control to return to the event l=
oop and then check the state of the dialog a little later, then most likely=
it has been destroyed by then.=C2=A0 It's not guaranteed however, beca=
use if the app is really busy then there may not have been a chance to proc=
ess the idle events.</div><div>=C2=A0</div><div><div><font face=3D"courier =
new, monospace">=C2=A0 =C2=A0 def OnButton(self, event):</font></div><div><=
font face=3D"courier new, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 dialog =3D=
wx.Dialog(self, -1, "ssss")</font></div><div><font face=3D"couri=
er new, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 result =3D dialog.ShowModal(=
)</font></div><div><font face=3D"courier new, monospace">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 dialog.Destroy()</font></div><div><font face=3D"courier new, mon=
ospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 wx.Yield()</font></div><div><font face=
=3D"courier new, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 wx.CallLater(100, s=
elf._later, dialog)</font></div><div><font face=3D"courier new, monospace">=
<br></font></div><div><font face=3D"courier new, monospace">=C2=A0 =C2=A0 d=
ef _later(self, dialog):</font></div><div><font face=3D"courier new, monosp=
ace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 print(self.GetChildren())</font></div><div=
><font face=3D"courier new, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 print( &=
quot;wx version", wx.version())</font></div><div><font face=3D"courier=
new, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 print("is child", di=
alog in=C2=A0 self.GetChildren())</font></div><div><font face=3D"courier ne=
w, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 print("is being deleted"=
;, dialog.IsBeingDeleted())</font></div><div><font face=3D"courier new, mon=
ospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 print("not yet destroyed", bo=
ol(dialog))</font></div></div><div><font face=3D"courier new, monospace"><b=
r></font></div><div>--</div><div>Robin</div><div><br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;wxPython-dev" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">wxPyth=
[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/wxPython-dev/300ba12a-93fa-40e0-85c8-3fd902a50a4c%40googlegroups=
.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/ms=
gid/wxPython-dev/300ba12a-93fa-40e0-85c8-3fd902a50a4c%40googlegroups.com</a=
>.<br />
For more options, visit <a href=3D"https://groups.google.com/d/optout">http=
s://groups.google.com/d/optout</a>.<br />
------=_Part_42_1864146471.1559762933779--
------=_Part_41_1798114816.1559762933779--