Sizer Problem

I have been experimenting with Mike’s AUI notebook examples, and tried to add a set of sizers to a panel. It worked before adding sizers, but now it gives an error.

I am also curious why top_sizer becomes a wxPyDeadObject, while bottom_sizer and panel_sizer are BoxSizer types?

Thanks in advance,

MarkL

Traceback (most recent call last):

('top_sizer type is ', <class ‘wx._core._wxPyDeadObject’>)

File “/Users/marklivingstone/Google Drive/Mark Livingstone PhD content/Code/learning_framework.py”, line 207, in

('bottom_sizer type is ', <class ‘wx._core.BoxSizer’>)

app = OSXApp(False)

('panel_sizer type is ', <class ‘wx._core.BoxSizer’>)

File “/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx/_core.py”, line 8631, in init

self._BootstrapApp()

File “/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx/_core.py”, line 8196, in _BootstrapApp

return core.PyApp__BootstrapApp(*args, **kwargs)

File “/Users/marklivingstone/Google Drive/Mark Livingstone PhD content/Code/learning_framework.py”, line 27, in OnInit

self.frame = OSXFrame(None, title=“Bioinformatics Pipeline Framework”, size=(600, 480))

File “/Users/marklivingstone/Google Drive/Mark Livingstone PhD content/Code/learning_framework.py”, line 165, in init

self.panel = MyPanel(self)

File “/Users/marklivingstone/Google Drive/Mark Livingstone PhD content/Code/learning_framework.py”, line 126, in init

self.nb = MyAuiNotebook(self)

File “/Users/marklivingstone/Google Drive/Mark Livingstone PhD content/Code/learning_framework.py”, line 49, in init

self.AddPage(panelTwo.TabPanel(self), “Transferred Result”, False)

File “/Users/marklivingstone/Google Drive/Mark Livingstone PhD content/Code/panelTwo.py”, line 73, in init

self.panel_sizer.Add(self.top_sizer, 0, wx.ALL, 5) # <------ traceback problem line

File “/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx/_core.py”, line 14460, in Add

return core.Sizer_Add(*args, **kwargs)

TypeError: wx.Window, wx.Sizer, wx.Size, or (w,h) expected for item

Process finished with exit code 1

panelTwo.py (2.92 KB)

I think the problem is that you are calling self.SetSizer() three times,
once with self.top_sizer, then self.bottom_sizer, and finally with
self.panel_sizer. But this should only be called once. Here "self" = the
TabPanel wxPanel, and the call to self.SetSizer() says "set the sizer that
manages the various objects on TabPanel." Every time you call it, you are
erasing the previous setting. Apparently--and I didn't know this--that
also causes the object, perhaps the C++ part of the object--to get deleted,
too? (Robin will chime in, but I wanted to try to puzzle it out as an
exercise).

So just figure out which sizer you want--probably panel_sizer, and call
SetSizer with that *once*.

Che

···

On Wed, Feb 19, 2014 at 9:45 PM, Mark Livingstone <livingstonemark@gmail.com > wrote:

I have been experimenting with Mike's AUI notebook examples, and tried to
add a set of sizers to a panel. It worked before adding sizers, but now it
gives an error.

I am also curious why top_sizer becomes a wxPyDeadObject, while
bottom_sizer and panel_sizer are BoxSizer types?

Thanks in advance,

MarkL

Hi Che,

Removing the extraneous SetSizer calls cleared it up perfectly!

It was worth getting up today, I learned something :slight_smile:

···

Cheers,

MarkL

On 20 February 2014 13:44, C M cmpython@gmail.com wrote:

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

On Wed, Feb 19, 2014 at 9:45 PM, Mark Livingstone livingstonemark@gmail.com wrote:

I have been experimenting with Mike’s AUI notebook examples, and tried to add a set of sizers to a panel. It worked before adding sizers, but now it gives an error.

I am also curious why top_sizer becomes a wxPyDeadObject, while bottom_sizer and panel_sizer are BoxSizer types?

Thanks in advance,

MarkL

I think the problem is that you are calling self.SetSizer() three times, once with self.top_sizer, then self.bottom_sizer, and finally with self.panel_sizer. But this should only be called once. Here “self” = the TabPanel wxPanel, and the call to self.SetSizer() says “set the sizer that manages the various objects on TabPanel.” Every time you call it, you are erasing the previous setting. Apparently–and I didn’t know this–that also causes the object, perhaps the C++ part of the object–to get deleted, too? (Robin will chime in, but I wanted to try to puzzle it out as an exercise).

So just figure out which sizer you want–probably panel_sizer, and call SetSizer with that once.

Che

C M wrote:

Apparently--and I didn't
know this--that also causes the object, perhaps the C++ part of the
object--to get deleted, too? (Robin will chime in, but I wanted to try
to puzzle it out as an exercise).

Yes, you are correct. Ownership of the sizer is given to the window that you call SetSizer for, (or to a parent sizer if it's nested) so it is the window's responsibility to get rid of the sizer when it's done with it. When you call SetSizer on a window that already has one then it assumes that you are done with the old one and destroys it for you.

If you want to keep the old sizer for some reason then you can pass False as a second parameter of SetSizer.

···

--
Robin Dunn
Software Craftsman