[wxPython] A Pre-4 Assert and a suggestion for wxAssert under wxPython

Aside:
聽聽Wondering if it would be possible to provide a hook so that a wxAssert could trigger Python code (such as starting the debugger to see what call is causing the assert).

The particular trigger :slight_smile: :
聽聽wincmn.cpp line 655,
聽聽聽聽聽wxASSERT_MSG( !GetChildren().Find(child), _T("AddChild() called twice") );

With a note above it stating it should never happen and will cause a crash if it does.

This is seen in a large application (room scheduler), and in the wxprop (with wxpycolours) demo using the wxColour chooser. Both cases involve the creation of a wxprop "transient dialog" (actually a frame), still working to track down where in that creation the error occurs (as you can see by my request above :o) ).

Note: the code work properly in preview release 3
Note: the text-control version of the transient frame works properly (doesn't cause an assert error)

I am assuming this is something to do with some change somewhere in the low-level wxPython support code. Alternately, there may be a problem with the use of the following function with new-grid code:

def findManagedParent( window ):
聽聽聽聽聽"""Find the nearest managed parent (dialog or frame) or NULL
聽聽聽聽聽if there is no managed parent available"""
聽聽聽聽聽current = window
聽聽聽聽聽while not (
聽聽聽聽聽聽聽聽聽isinstance(current, wxFramePtr) or
聽聽聽聽聽聽聽聽聽isinstance(current, wxDialogPtr) or
聽聽聽聽聽聽聽聽聽current == NULL or
聽聽聽聽聽聽聽聽聽current == None
聽聽聽聽聽):
聽聽聽聽聽聽聽聽聽current = current.GetParent()
聽聽聽聽聽return current

which allows the transient frames to be parented to the dialog/frame owning the grid, rather than the button/control in the grid cell (the "window" passed to findManagedParent). This doesn't seem likely, however, as the transient frame never uses the button as a parent... relevant code:

realParent = findManagedParent( parent )
self.buttonParent = weakref.ref( parent )
wxFrame.__init__( self, realParent, id, title, pos, size, style, name )

Anyone else getting this assert showing up, or should I be worried primarily about my own code?
Mike

路路路

_______________________________________
聽聽聽Mike C. Fletcher
聽聽聽http://members.rogers.com/mcfletch/

Argh. Found it seconds after sending.

It wasn't that something messed up, it was that the AddChild method is now wrapped (previously it wasn't I assume), and that it was causing a conflict with the wxpycolour AddChild method. Explicitly calling holder.Holder.AddChild works fine, and eliminates the Assert.

Next time I'll try the obvious... wait, that resolution never works... next time I'll try to wait a few more minutes before sending a message...

Suggestion of Python hook for assert still stands,
Mike

Mike C. Fletcher wrote:

Aside:
    Wondering if it would be possible to provide a hook so that a wxAssert could trigger Python code (such as starting the debugger to see what call is causing the assert).

<dumb problem elided>
...

路路路

_______________________________________
   Mike C. Fletcher
   http://members.rogers.com/mcfletch/

Suggestion of Python hook for assert still stands,

Yep. I've had an item on my todo list for a while to see if there is any
way to safely turn them into Python exceptions.

路路路

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

Robin Dunn wrote:

Suggestion of Python hook for assert still stands,

Yep. I've had an item on my todo list for a while to see if there is any
way to safely turn them into Python exceptions.

PyGame has something called parachute which handles unhandled exceptions .

HTH
Niki Spahiev