wx.EVT_ACTIVATE called on program exit - wx.PyDeadObjectError

Hi all,
I'd like to ask about the expected usage of of wx.EVT_ACTIVATE; I'm
trying to hide the custom PopupWindow (as a replacement of tooltips on
the aui titlebars), if the app is switched to the background. It
seems, that EVT_ACTIVATE of the main frame also handles this case, but
i get wx.PyDeadObjectError on program exit.
It's easy to silence this error via
try: hide_popup() ... except wx.PyDeadObjectError: pass
but I'm not quite sure, whether it doesn't signal an incorrect usage
of that event or another error somewhere else;
or is it the intended behaviour and the expected exit-handling in this case?

Thanks in advance
    Vlasta

Hi Vlasta,

Hi all,
I'd like to ask about the expected usage of of wx.EVT_ACTIVATE; I'm
trying to hide the custom PopupWindow (as a replacement of tooltips on
the aui titlebars), if the app is switched to the background. It
seems, that EVT_ACTIVATE of the main frame also handles this case, but
i get wx.PyDeadObjectError on program exit.
It's easy to silence this error via
try: hide_popup() ... except wx.PyDeadObjectError: pass
but I'm not quite sure, whether it doesn't signal an incorrect usage
of that event or another error somewhere else;
or is it the intended behaviour and the expected exit-handling in this case?

Thanks in advance
Vlasta

It sounds like your application is trying to access an object that is
already destroyed. You might just want to create some kind of flag you
can check to see if your frame is still alive or if it's closed. Then
if it is alive when you want to exit you can just close it. Or you
might just use wx.GetTopLevelWindows() to get a list of all the top
Windows and then loop over that and close each of them.

- Mike

···

On Aug 13, 3:34 am, Vlastimil Brom <vlastimil.b...@gmail.com> wrote:

Hello,

Hi Vlasta,

Hi all,
I'd like to ask about the expected usage of of wx.EVT_ACTIVATE; I'm
trying to hide the custom PopupWindow (as a replacement of tooltips on
the aui titlebars), if the app is switched to the background. It
seems, that EVT_ACTIVATE of the main frame also handles this case, but
i get wx.PyDeadObjectError on program exit.
It's easy to silence this error via
try: hide_popup() ... except wx.PyDeadObjectError: pass
but I'm not quite sure, whether it doesn't signal an incorrect usage
of that event or another error somewhere else;
or is it the intended behaviour and the expected exit-handling in this case?

No, your code is incorrectly trying to access an object that has
already been destroyed. Not sure how your using your popupwindow class
but it may have gotten destroyed somewhere else before this call in
your exit code.

It sounds like your application is trying to access an object that is
already destroyed. You might just want to create some kind of flag you
can check to see if your frame is still alive or if it's closed.

An easy way to check if a window has already been deleted is to use
the builtin isinstance method

if isinstance(myWindow, wx.Window):
    # Not destroyed yet
else:
    # Its already dead

Cody

···

On Thu, Aug 13, 2009 at 8:04 AM, Mike Driscoll<kyosohma@gmail.com> wrote:

On Aug 13, 3:34 am, Vlastimil Brom <vlastimil.b...@gmail.com> wrote:

I was trying to figure out how to use "isinstance" in this case, but I
wasn't sure what instance to compare the object to. Anyway, I'll tuck
this away and try to remember it for the next guy who asks this
question.

- Mike

···

On Aug 13, 8:14 am, Cody Precord <codyprec...@gmail.com> wrote:

Hello,

On Thu, Aug 13, 2009 at 8:04 AM, Mike Driscoll<kyoso...@gmail.com> wrote:

> Hi Vlasta,

> On Aug 13, 3:34 am, Vlastimil Brom <vlastimil.b...@gmail.com> wrote:
>> Hi all,
>> I'd like to ask about the expected usage of of wx.EVT_ACTIVATE; I'm
>> trying to hide the custom PopupWindow (as a replacement of tooltips on
>> the aui titlebars), if the app is switched to the background. It
>> seems, that EVT_ACTIVATE of the main frame also handles this case, but
>> i get wx.PyDeadObjectError on program exit.
>> It's easy to silence this error via
>> try: hide_popup() ... except wx.PyDeadObjectError: pass
>> but I'm not quite sure, whether it doesn't signal an incorrect usage
>> of that event or another error somewhere else;
>> or is it the intended behaviour and the expected exit-handling in this case?

No, your code is incorrectly trying to access an object that has
already been destroyed. Not sure how your using your popupwindow class
but it may have gotten destroyed somewhere else before this call in
your exit code.

> It sounds like your application is trying to access an object that is
> already destroyed. You might just want to create some kind of flag you
> can check to see if your frame is still alive or if it's closed.

An easy way to check if a window has already been deleted is to use
the builtin isinstance method

if isinstance(myWindow, wx.Window):
# Not destroyed yet
else:
# Its already dead

Cody

Cody Precord wrote:

Hello,

Hi Vlasta,

Hi all,
I'd like to ask about the expected usage of of wx.EVT_ACTIVATE; I'm
trying to hide the custom PopupWindow (as a replacement of tooltips on
the aui titlebars), if the app is switched to the background. It
seems, that EVT_ACTIVATE of the main frame also handles this case, but
i get wx.PyDeadObjectError on program exit.
It's easy to silence this error via
try: hide_popup() ... except wx.PyDeadObjectError: pass
but I'm not quite sure, whether it doesn't signal an incorrect usage
of that event or another error somewhere else;
or is it the intended behaviour and the expected exit-handling in this case?

No, your code is incorrectly trying to access an object that has
already been destroyed. Not sure how your using your popupwindow class
but it may have gotten destroyed somewhere else before this call in
your exit code.

Most likely it was destroyed automatically by wx as part of its normal shutdown process. It just happens to be being done before the frame with the EVT_ACTIVATE handler is processed.

It sounds like your application is trying to access an object that is
already destroyed. You might just want to create some kind of flag you
can check to see if your frame is still alive or if it's closed.

An easy way to check if a window has already been deleted is to use
the builtin isinstance method

if isinstance(myWindow, wx.Window):
    # Not destroyed yet
else:
    # Its already dead

Even easier, the _wxPyDeadObject class has a __nonzero__ magic method, so you can also just use an if statement that tests the window itself:

  if mywindow:
    # Not destroyed yet
  else:
    # It's already dead

···

On Thu, Aug 13, 2009 at 8:04 AM, Mike Driscoll<kyosohma@gmail.com> wrote:

On Aug 13, 3:34 am, Vlastimil Brom <vlastimil.b...@gmail.com> wrote:

--
Robin Dunn
Software Craftsman

Hi,
thanks for the explanations as well as the proposed solution!
The mentioned error appeared in my custom PopupWindow (for longer
captions on aui panes). I just create this popup (hidden) on program
start, it is only updated, shown and hidden as needed, it isn't
explicitly destroyed.
The wx.EVT_ACTIVATE is used to hide these "tooltips" when switching to
another window, but it also triggers on destroying the app on exit. I
somehow expected the event bindings to be disconnected at this time,
but the suggested check works ok here.

Thanks once again,
   Vlasta

···

2009/8/13 Cody Precord <codyprecord@gmail.com>:

Hello,

On Thu, Aug 13, 2009 at 8:04 AM, Mike Driscoll<kyosohma@gmail.com> wrote:

Hi Vlasta,

On Aug 13, 3:34 am, Vlastimil Brom <vlastimil.b...@gmail.com> wrote:

Hi all,
I'd like to ask about the expected usage of of wx.EVT_ACTIVATE; I'm
trying to hide the custom PopupWindow (as a replacement of tooltips on
the aui titlebars), if the app is switched to the background. It
seems, that EVT_ACTIVATE of the main frame also handles this case, but
i get wx.PyDeadObjectError on program exit.
It's easy to silence this error via
try: hide_popup() ... except wx.PyDeadObjectError: pass
but I'm not quite sure, whether it doesn't signal an incorrect usage
of that event or another error somewhere else;
or is it the intended behaviour and the expected exit-handling in this case?

No, your code is incorrectly trying to access an object that has
already been destroyed. Not sure how your using your popupwindow class
but it may have gotten destroyed somewhere else before this call in
your exit code.

It sounds like your application is trying to access an object that is
already destroyed. You might just want to create some kind of flag you
can check to see if your frame is still alive or if it's closed.

An easy way to check if a window has already been deleted is to use
the builtin isinstance method

if isinstance(myWindow, wx.Window):
# Not destroyed yet
else:
# Its already dead

Cody