From 7b027848295930ad4dfaefca752aba5b5b4212e0 Mon Sep 17 00:00:00 2001 From: kollivier Date: Fri, 8 Sep 2017 14:21:31 -0700 Subject: [PATCH] SizedControls null sizer check for AUI support. --- wx/lib/sized_controls.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/wx/lib/sized_controls.py b/wx/lib/sized_controls.py index d0d53878..755ccd10 100644 --- a/wx/lib/sized_controls.py +++ b/wx/lib/sized_controls.py @@ -599,29 +599,33 @@ class SizedParent: """ def AddChild(self, child): """ - Add a child to sizer + This extends the default wx.Window behavior to also add the child + to its parent's sizer, if one exists, and set default properties. + When an entire UI layout is managed via Sizers, this helps reduce + the amount of sizer boilerplate code that needs to be written. :param `child`: child (window or another sizer) to be added to sizer. :type `child`: :class:`wx.Window` or :class:`wx.Sizer` """ - # Note: The wx.LogNull is used here to suppress a log message - # on wxMSW that happens because when AddChild is called the - # widget's hwnd hasn't been set yet, so the GetWindowRect that - # happens as a result of sizer.Add (in wxSizerItem::SetWindow) - # fails. A better fix would be to defer this code somehow - # until after the child widget is fully constructed. sizer = self.GetSizer() - nolog = wx.LogNull() - item = sizer.Add(child) - del nolog - item.SetUserData({"HGrow":0, "VGrow":0}) + if sizer: + # Note: The wx.LogNull is used here to suppress a log message + # on wxMSW that happens because when AddChild is called the + # widget's hwnd hasn't been set yet, so the GetWindowRect that + # happens as a result of sizer.Add (in wxSizerItem::SetWindow) + # fails. A better fix would be to defer this code somehow + # until after the child widget is fully constructed. + nolog = wx.LogNull() + item = sizer.Add(child) + del nolog + item.SetUserData({"HGrow": 0, "VGrow": 0}) - # Note: One problem is that the child class given to AddChild - # is the underlying wxWidgets control, not its Python subclass. So if - # you derive your own class, and override that class' GetDefaultBorder(), - # etc. methods, it will have no effect. - child.SetDefaultSizerProps() + # Note: One problem is that the child class given to AddChild + # is the underlying wxWidgets control, not its Python subclass. So if + # you derive your own class, and override that class' GetDefaultBorder(), + # etc. methods, it will have no effect. + child.SetDefaultSizerProps() def GetSizerType(self): """