wx.Controls without parents

Hi all,

I’ve run into a cross-platform inconsistency involving Controls and their need for parents. I want to clarify that this behavior is expected, so I can update the unit test suite accordingly.

Running the following at an interactive prompt:

import wx
app = wx.PySimpleApp()
b = wx.Button(None)

does different things depending on your platform. Apparently, wxGtk will instantiate a parentless Button with no problems. On Windows, we get

b = wx.Button(None)
Traceback (most recent call last):
File “”, line 1, in
File “C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx_controls.py”, line

86, in init
controls.Button_swiginit(self,controls.new_Button(*args, **kwargs))
wx._core.PyAssertionError: C++ assertion “parent” failed at …..\src\common\ctr
lcmn.cpp(79) in wxControlBase::CreateControl(): all controls must have parents

and the same type of thing on Mac (see the results at the bottom of http://wiki.wxpython.org/Test_Suite_Results?action=show).
Example:

testAllControlsNeedParents (testRadioBox.RadioBoxTest)

Traceback (most recent call last):
  File "/Users/cody/Desktop/Python/wx_stuff/unittest/unittest/testControl.py", line 31, in testAllControlsNeedParents

    class_under_test(None)
  File "//Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/wx-2.8-mac-unicode
/wx/_controls.py", line 2356, in __init__
    _controls_.RadioBox_swiginit(self,_controls_.new_RadioBox(*args, **kwargs))
PyAssertionError: C++ assertion "parent" failed at /BUILD/wxPython-
src-2.8.4.0/src/mac/carbon/window.cpp(1090) in Create(): can't create wxWindowMac without parent

Additionally, trying to instantiate other wx.Windows without parents will also fail on Windows and Mac but not Gtk. Can anyone clarify what causes these discrepancies, and whether or not they are the correct behavior? Thanks.

-Frank

I assume that the wxGtk implementation doesn't perform the assert and
that Gtk does magical parent escalation even for controls similar to
what Qt does (you can show any control in Qt without a parent and it
will magically get a frame).

This isn't supported under wxWidgets though and I'd consider it a
(nominal) bug that it works on wxGtk. I know I've certainly written
code that assumes that any control must have a parent.

···

On 7/19/07, Frank Tobia <frank.tobia@gmail.com> wrote:

Hi all,

I've run into a cross-platform inconsistency involving Controls and their
need for parents. I want to clarify that this behavior is expected, so I
can update the unit test suite accordingly.

Running the following at an interactive prompt:

import wx
app = wx.PySimpleApp()
b = wx.Button(None)

does different things depending on your platform. Apparently, wxGtk will
instantiate a parentless Button with no problems. On Windows, we get

>>> b = wx.Button(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File
"C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py",
line
86, in __init__

_controls_.Button_swiginit(self,_controls_.new_Button(*args,
**kwargs))
wx._core.PyAssertionError: C++ assertion "parent" failed at
..\..\src\common\ctr
lcmn.cpp(79) in wxControlBase::CreateControl(): all controls must have
parents

and the same type of thing on Mac (see the results at the bottom of
Test Suite Results - wxPyWiki).
Example:

testAllControlsNeedParents (testRadioBox.RadioBoxTest) Traceback (most
recent call last):
File
"/Users/cody/Desktop/Python/wx_stuff/unittest/unittest/testControl.py",
line 31, in testAllControlsNeedParents

class_under_test(None)
File
"//Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/wx-2.8-mac-unicode
/wx/_controls.py", line 2356, in __init__
_controls_.RadioBox_swiginit(self,_controls_.new_RadioBox(*args,
**kwargs))
PyAssertionError: C++ assertion "parent" failed at /BUILD/wxPython-
src-2.8.4.0/src/mac/carbon/window.cpp(1090) in Create():
can't create wxWindowMac without parent

Additionally, trying to instantiate other wx.Windows without parents will
also fail on Windows and Mac but not Gtk. Can anyone clarify what causes
these discrepancies, and whether or not they are the correct behavior?
Thanks.

Chris Mellon wrote:

I assume that the wxGtk implementation doesn't perform the assert and
that Gtk does magical parent escalation even for controls similar to
what Qt does (you can show any control in Qt without a parent and it
will magically get a frame).

Not quite. I think that GTK requires that a widget have a parent, it just doesn't have to have one at creation time like the other platforms do. I think this fact is used internally in wxWidgets in a few places, which is probably why there isn't an assert, but I would just consider that an implementation detail. wxWidgets does require that non top-level windows have a parent, it's just not enforced in debug mode on wxGTK like the others do.

···

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