Page layout issues

I'm fairly new to wxPython and am having some issues Trying to layout the page
how I want.

What I'm after is a Notebook taking up most of the window with 5px borders, with
a band at the bottom with OK, Cancel, Apply right aligned all with px borders.

I've posted what I have so far, it seems almost right although I've had to
manually set exactly the right positions and sizes in quite a few places which
I'm sure there's a better way of doing (on the page __init__s, notebook
constructor). Also all the border areas are all dark grey because you can see
behind to the frame, how can I get the panel to show here in the nice light
grey? Also the second panel with the second sizer in is up in the top left
corner and I'm not sure why!
Also I just noticed the notebook goes off the edge of the viewable area on the
right, probably due to the size I gave it is too wide.
There's also not a 5px gap between the buttons either

Any help would be greatly appreciated, I've tried so many different thing now-
I'm hoping this will be easy for someone with more experience!

import wx

class TestPage(wx.Panel):
  def __init__(self,parent):
    wx.Panel.__init__(self,parent,size=(-1,300))
    t= wx.StaticText(self,-1,"Blahhh")

class MainFrame(wx.Frame):
  def __init__(self):
    wx.Frame.__init__(self, None, title="Settings", style=wx.DEFAULT_FRAME_STYLE
^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX ^ wx.MINIMIZE_BOX, size=wx.Size(550,370))
    p1= wx.Panel(self)
    p2= wx.Panel(self)
    nb= wx.Notebook(p1,pos=(5,5),size=(539,295))
    #p= wx.Panel(self,size=wx.Size(550,370))
    
## sizer= wx.BoxSizer(wx.HORIZONTAL)
## sizer.Add(p)
## self.SetSizer(sizer)

···

##

    # create the page windows as children of the notebook
    page1= TestPage(nb)
    page2= TestPage(nb)
    page3= TestPage(nb)
    page4= TestPage(nb)
    page5= TestPage(nb)
    
    # add the pages to the notebook with the label to show on the tab
    nb.AddPage(page1, "Page 1")
    nb.AddPage(page2, "Page 2")
    nb.AddPage(page3, "Page 3")
    nb.AddPage(page4, "Page 4")
    nb.AddPage(page5, "Page 5")
    
    self.sizer2= wx.BoxSizer(wx.HORIZONTAL)
    
    self.ok_btn= wx.Button(self,wx.ID_OK)
    self.cancel_btn= wx.Button(self,wx.ID_CANCEL)
    
    self.sizer2.Add(self.ok_btn,0,wx.EXPAND)
    self.sizer2.Add(self.cancel_btn,1,wx.EXPAND)
    
    self.sizer= wx.BoxSizer(wx.VERTICAL)
    self.sizer.Add(p1,1,wx.ALL^wx.BOTTOM|wx.EXPAND,5)
    #self.sizer.Add(self.panel,0)
    self.sizer.Add(self.sizer2,0,wx.ALL|wx.ALIGN_RIGHT,5)
    
    self.SetSizer(self.sizer)

if __name__ == "__main__":
  app = wx.App(False)
  MainFrame().Show()
  app.MainLoop()

The problem with the second panel is that it’s not added to any sizer, so it just defaults to going up in the corner. I went and created a simple demo that shows how this can be done. It’s attached. Hopefully it will make sense to you and you can use it as a model for your program. You might find the following tutorials helpful too: http://www.blog.pythonlibrary.org/2010/09/15/wxpython-a-simple-notebook-example/ or http://www.blog.pythonlibrary.org/2009/12/03/the-book-controls-of-wxpython-part-1-of-2/

notebook2.py (1.83 KB)

···

Mike Driscoll

Blog: http://blog.pythonlibrary.org

Paul,

pagelayout.py (1.69 KB)

···

On 10/03/2011 02:29 PM, Paul wrote:

I'm fairly new to wxPython and am having some issues Trying to layout the page
how I want.

What I'm after is a Notebook taking up most of the window with 5px borders, with
a band at the bottom with OK, Cancel, Apply right aligned all with px borders.

I've posted what I have so far, it seems almost right although I've had to
manually set exactly the right positions and sizes in quite a few places which
I'm sure there's a better way of doing (on the page __init__s, notebook
constructor). Also all the border areas are all dark grey because you can see
behind to the frame, how can I get the panel to show here in the nice light
grey? Also the second panel with the second sizer in is up in the top left
corner and I'm not sure why!
Also I just noticed the notebook goes off the edge of the viewable area on the
right, probably due to the size I gave it is too wide.
There's also not a 5px gap between the buttons either

Any help would be greatly appreciated, I've tried so many different thing now-
I'm hoping this will be easy for someone with more experience!

I am newly fan of wx.lib.sized_controls (others might slowly but surely get sick of me pushing them:-) ).

Anyhow it is alternative way of getting sizer controlled layouts and they automatically apply platform specific HIG's (borders).

I also added in the WIT which I am sure you will sooner or later need to debug to find out why your sizer code isn't doing what you want it to do.

Thank you both! I had a few misunderstanding of panels and sizers but I've
learnt a lot, thanks!

Also the InspectionMixin is really useful, I never knew it existed!