A couple of sizing questions

A couple of sizing questions, O Helpful Ones:

(1) How do I get the panel in each of the four windows to fill the
window?

(2) How do I get the four windows to fill the frame again when the user
resizes the frame?

···

`import wx

class MainFrame(wx.Frame):

def __init__(self, parent, id, title):

    wx.Frame.__init__(self,

parent, -1, title)

    pnl = wx.Panel(self,-1)

    gbs =

wx.GridBagSizer(1,1)

    win00 =

gbs.Add(ChildWindow0(pnl, -1)
,(0,0),flag=wx.EXPAND)

    win01 =

gbs.Add(ChildWindow1(pnl, -1,‘win01’),(0,1),flag=wx.EXPAND)

    win10 =

gbs.Add(ChildWindow1(pnl, -1,‘win10’),(1,0),flag=wx.EXPAND)

    win11 =

gbs.Add(ChildWindow1(pnl, -1,‘win11’),(1,1),flag=wx.EXPAND)

    pnl.SetSizerAndFit(gbs)

self.SetClientSize(pnl.GetSize())

class ChildWindow0(wx.Window):

def __init__(self, parent, id):

    wx.Window.__init__(self,

parent, -1, size=(300,300), style=wx.RAISED_BORDER)

    pnl = wx.Panel(self,-1)

self.SetClientSize(pnl.GetSize())

pnl.SetBackgroundColour(wx.BLUE)

class ChildWindow1(wx.Window):

def __init__(self, parent, id, title):

    wx.Window.__init__(self,

parent, -1, size=(300,300), style=wx.RAISED_BORDER)

    pnl = wx.Panel(self,-1)

pnl.SetBackgroundColour(wx.BLUE)

    st_ttl = wx.StaticText(pnl,

-1, “(window title)” , size=(300,20)

, style=wx.ALIGN_CENTER|wx.RAISED_BORDER|wx.ST_NO_AUTORESIZE)

st_ttl.SetBackgroundColour(wx.WHITE)

    bs =

wx.BoxSizer(wx.VERTICAL)

    bs.Add(st_ttl  , 0,

wx.EXPAND,0,0)

    bs.Add((100,50), 1,

wx.BORDER,0,0)

pnl.SetSizerAndFit(bs)

if name == ‘main’:

app = wx.App(redirect=False)

frame = MainFrame(None, -1, "Windows in panel in

frame test")

frame.Show()

app.MainLoop()

`

Bob

Hi Bob,

A couple of sizing questions, O Helpful Ones:

(1) How do I get the panel in each of the four windows to fill the window?
(2) How do I get the four windows to fill the frame again when the user
resizes the frame?

Let's see if the code I put at the end does somethins similar to what
you really need. Maybe I am missing something, and you may just
correct what is missing.

The code, with comments:

import wx

class MainFrame(wx.Frame):

    def __init__(self, parent, id, title):

        wx.Frame.__init__(self, parent, -1, title)

        pnl = wx.Panel(self,-1)

        # If you are going to do complex things inside a panel that lives
        # inside a frame, use also a BoxSizer for the main frame. The only
        # item in this mainsizer is pnl
        mainsizer = wx.BoxSizer(wx.VERTICAL)

        # It is sometimes very complicated to use correctly a GridBagSizer
        # so I may use a FlexGridSizer for the moment
        gbs = wx.FlexGridSizer(2, 2, 0, 0)

        # Tells the FlexGridSizer that all the windows inside should
be "growable"
        gbs.AddGrowableRow(0)
        gbs.AddGrowableRow(1)
        gbs.AddGrowableCol(0)
        gbs.AddGrowableCol(1)

        # add your windows to the FlexGridSizer
        win00 = gbs.Add(ChildWindow0(pnl, -1), flag=wx.EXPAND)
        win01 = gbs.Add(ChildWindow1(pnl, -1,'win01'), flag=wx.EXPAND)

        win10 = gbs.Add(ChildWindow1(pnl, -1,'win10'), flag=wx.EXPAND)
        win11 = gbs.Add(ChildWindow1(pnl, -1,'win11'), flag=wx.EXPAND)

        pnl.SetSizer(gbs)

        # Add the panel to the main sizer and assign the sizer to the frame
        mainsizer.Add(pnl, 1, wx.EXPAND)
        self.SetSizer(mainsizer)

        # calling Layout() on sizers is usually a good practice...
        gbs.Layout()
        mainsizer.Layout()

# Do not use wx.Window unless you are doing something
# complicated with Painting and so on. But also for these
# situations, use a wx.PyPanel instead of a wx.Window
class ChildWindow0(wx.Panel):

    def __init__(self, parent, id):

        wx.Panel.__init__(self, parent, -1, style=wx.RAISED_BORDER)
        self.SetBackgroundColour(wx.BLUE)

class ChildWindow1(wx.Panel):

    def __init__(self, parent, id, title):

        wx.Panel.__init__(self, parent, -1, style=wx.RAISED_BORDER)

        pnl = wx.Panel(self,-1)
        pnl.SetBackgroundColour(wx.BLUE)

        st_ttl = wx.StaticText(self, -1, "(window title)",

style=wx.ALIGN_CENTER|wx.RAISED_BORDER|wx.ST_NO_AUTORESIZE)
        st_ttl.SetBackgroundColour(wx.WHITE)

        bs = wx.BoxSizer(wx.VERTICAL)
        bs.Add(st_ttl, 0, wx.EXPAND)

        # I don't know what this spacer is meant to do...
        # so I commented it out
## bs.Add((100,50), 1, wx.BORDER,0,0)
        bs.Add(pnl, 1, wx.EXPAND)

        self.SetSizer(bs)
        bs.Layout()

if __name__ == '__main__':
    app = wx.App(redirect=False)
    frame = MainFrame(None, -1, "Windows in panel in frame test")
    frame.Show()
    app.MainLoop()

Hope this helps.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

Hi Bob,

    sorry if I didn't point out that, although the solution I posted
seems to work, it was not meant at all as a general approach. This is
how I would layout the panels if it were my task, but others may come
out with better/more efficient/nicer solutions.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

This helps A LOT, Andrea. Thank you very much!

I will have a good bit of dc code going on in each panel. My next task is to see if I can make that work using the above architecture.

Bob

P.S. I still have no idea why my own code was not sizing properly. If there's anything you can say about that, I'm sure it'll be quite educational. Trying to make that work was, as I've heard others here say, driving me nuts!

···

At 06:26 PM 10/26/2006, Andrea Gavana wrote:

Hi Bob,

A couple of sizing questions, O Helpful Ones:

(1) How do I get the panel in each of the four windows to fill the window?
(2) How do I get the four windows to fill the frame again when the user
resizes the frame?

Let's see if the code I put at the end does somethins similar to what
you really need. Maybe I am missing something, and you may just
correct what is missing.

The code, with comments:

import wx

class MainFrame(wx.Frame):

   def __init__(self, parent, id, title):

       wx.Frame.__init__(self, parent, -1, title)

       pnl = wx.Panel(self,-1)

       # If you are going to do complex things inside a panel that lives
       # inside a frame, use also a BoxSizer for the main frame. The only
       # item in this mainsizer is pnl
       mainsizer = wx.BoxSizer(wx.VERTICAL)

       # It is sometimes very complicated to use correctly a GridBagSizer
       # so I may use a FlexGridSizer for the moment
       gbs = wx.FlexGridSizer(2, 2, 0, 0)

       # Tells the FlexGridSizer that all the windows inside should be "growable"
       gbs.AddGrowableRow(0)
       gbs.AddGrowableRow(1)
       gbs.AddGrowableCol(0)
       gbs.AddGrowableCol(1)

       # add your windows to the FlexGridSizer
       win00 = gbs.Add(ChildWindow0(pnl, -1), flag=wx.EXPAND)
       win01 = gbs.Add(ChildWindow1(pnl, -1,'win01'), flag=wx.EXPAND)

       win10 = gbs.Add(ChildWindow1(pnl, -1,'win10'), flag=wx.EXPAND)
       win11 = gbs.Add(ChildWindow1(pnl, -1,'win11'), flag=wx.EXPAND)

       pnl.SetSizer(gbs)

       # Add the panel to the main sizer and assign the sizer to the frame
       mainsizer.Add(pnl, 1, wx.EXPAND)
       self.SetSizer(mainsizer)

       # calling Layout() on sizers is usually a good practice...
       gbs.Layout()
       mainsizer.Layout()

# Do not use wx.Window unless you are doing something
# complicated with Painting and so on. But also for these
# situations, use a wx.PyPanel instead of a wx.Window
class ChildWindow0(wx.Panel):

   def __init__(self, parent, id):

       wx.Panel.__init__(self, parent, -1, style=wx.RAISED_BORDER)
       self.SetBackgroundColour(wx.BLUE)

class ChildWindow1(wx.Panel):

   def __init__(self, parent, id, title):

       wx.Panel.__init__(self, parent, -1, style=wx.RAISED_BORDER)

       pnl = wx.Panel(self,-1)
       pnl.SetBackgroundColour(wx.BLUE)

       st_ttl = wx.StaticText(self, -1, "(window title)"
           ,style=wx.ALIGN_CENTER|wx.RAISED_BORDER|wx.ST_NO_AUTORESIZE)
       st_ttl.SetBackgroundColour(wx.WHITE)

       bs = wx.BoxSizer(wx.VERTICAL)
       bs.Add(st_ttl, 0, wx.EXPAND)

       # I don't know what this spacer is meant to do...
       # so I commented it out
## bs.Add((100,50), 1, wx.BORDER,0,0)
       bs.Add(pnl, 1, wx.EXPAND)

       self.SetSizer(bs)
       bs.Layout()

if __name__ == '__main__':
   app = wx.App(redirect=False)
   frame = MainFrame(None, -1, "Windows in panel in frame test")
   frame.Show()
   app.MainLoop()

Hope this helps.

Andrea.

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.0.408 / Virus Database: 268.13.14/501 - Release Date: 10/26/2006