boxsizers problem

Instead of adding the windows at
         vertical_sizer.Add(self.Subwindow, 1, wx.EXPAND)
         vertical_sizer.Add(self.Nextsubwindow, 1, wx.EXPAND)
add the sizer that holds them instead.

Phil Mayes

···

At 04:03 PM 9/9/2006, you wrote:

Hi!

I am running into a dead end while trying to combine several widgets
containing their own sizers into sizers of higher-level widgets.

Precisely: I have a topwidget, inherited from wx.Frame, which
contains two subwidgets. One of these widgets is a wx.Window, the
other one is a widget inherited from wx.Window, which intself contains two
wx.Windows. The latter two wx.Windows are placed by a wx.BoxSizer, as
well as the two medium-level widgets are within the toplevel widget.

This doesn't work: the lowest-level widgets are stacked on top of each
other. What is my mistake?
Greetings!

               Moritz

The code looks like this (colors added in order to see the placement):

import wx

class MainWindow(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None,-1,"Trainer")
        self.SetBackgroundColour(wx.CYAN)
        self.Subwindow = Subwindow(self)
        self.Nextsubwindow = wx.Window(self, -1, size=(100,100))
        self.Nextsubwindow.SetBackgroundColour(wx.RED)
        vertical_sizer = wx.BoxSizer(wx.VERTICAL)
        vertical_sizer.Add(self.Subwindow, 1, wx.EXPAND)
        vertical_sizer.Add(self.Nextsubwindow, 1, wx.EXPAND)
        self.SetSizer(vertical_sizer)
        self.SetAutoLayout(1)
        vertical_sizer.Fit(self)

class Subwindow(wx.Window):
    def __init__(self, mother_widget):
        wx.Window.__init__(self, mother_widget,-1)
        self.SetBackgroundColour(wx.BLACK)
        self.FirstWidget = wx.Window(self,-1, size=(50,50))
        self.FirstWidget.SetBackgroundColour(wx.BLUE)
        self.SecondWidget = wx.Window(self,-1, size=(50,50))
        self.FirstWidget.SetBackgroundColour(wx.GREEN)
        horizontal_sizer = wx.BoxSizer(wx.HORIZONTAL)
        horizontal_sizer.Add(self.FirstWidget, 1, wx.EXPAND)
        horizontal_sizer.Add(self.SecondWidget, 1, wx.EXPAND)
        self.SetSizer(horizontal_sizer)
        self.SetAutoLayout(1)
        horizontal_sizer.Fit(self)

Or use xrced? I found that helped a lot when I was trying to do windows and sizers choreography, especially initially when learning wxPython.

Lee <- Not that I've stopped learning wxPython...

P.S. xrced is here: http://xrced.sourceforge.net/

···

----- Original Message ----- From: "Phil Mayes" <phil@philmayes.com>
To: <wxPython-users@lists.wxwidgets.org>
Sent: Saturday, September 09, 2006 7:12 PM
Subject: Re: [wxPython-users] boxsizers problem

At 04:03 PM 9/9/2006, you wrote:

Hi!

I am running into a dead end while trying to combine several widgets
containing their own sizers into sizers of higher-level widgets.

Instead of adding the windows at
        vertical_sizer.Add(self.Subwindow, 1, wx.EXPAND)
        vertical_sizer.Add(self.Nextsubwindow, 1, wx.EXPAND)
add the sizer that holds them instead.

Phil Mayes

Phil Mayes wrote:

Instead of adding the windows at
        vertical_sizer.Add(self.Subwindow, 1, wx.EXPAND)
        vertical_sizer.Add(self.Nextsubwindow, 1, wx.EXPAND)
add the sizer that holds them instead.

No, don't do this. The sizer that belongs to some window P should only have items added to it that are children of P, or sizers that also hold children of P. If you add the sizer that belongs to the child window to P's sizer then it could result in a rip of the fabric of the universe and the exotic particles generated in a parallel universe could leak in and cause all kinds of havoc. :wink:

···

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