[wxPython] Sizing

I understand that a wxFrame with one child should automatically size that
child to fill it's client area. But I find I always have to do something
like

panel.SetSize(frame.GetCLientSize())

otherwise I get a 20x20 panel.

Perhaps some kind soul could tell me why my wxPanal is not automatically
getting sized to the client area in my wxFrame? (System=Linux Mandrake 7.0
wxPython 2.2.5)

#!/usr/bin/env python
from wxPython.wx import *

class MyFrame(wxFrame):
    def __init__(self, parent, id, title):
        wxFrame.__init__(self, parent, id, title,wxPoint(100, 100),
wxSize(600, 500))

# panel=wxPanel(self,-1,size=self.GetClientSize()) <-Why do I need to
do this?
        panel = wxPanel(self, -1)
        print self.GetClientSize()
        print panel.GetSize()
        self.tree=wxTreeCtrl(panel,-1)
# self.tree.SetSize(panel.GetClientSize()) <-Same here?
        self.root=self.tree.AddRoot("No database")
# self.tree.SetPyData(self.root,None)

class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame(NULL, -1, "Cell Designer")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

app= MyApp(0)
app.MainLoop()

Thanks
Jan

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

Perhaps some kind soul could tell me why my wxPanal is not automatically
getting sized to the client area in my wxFrame? (System=Linux Mandrake

7.0

wxPython 2.2.5)

#!/usr/bin/env python
from wxPython.wx import *

class MyFrame(wxFrame):
    def __init__(self, parent, id, title):
        wxFrame.__init__(self, parent, id, title,wxPoint(100, 100),
wxSize(600, 500))

# panel=wxPanel(self,-1,size=self.GetClientSize()) <-Why do I need

to

do this?
        panel = wxPanel(self, -1)
        print self.GetClientSize()
        print panel.GetSize()

At this point the frame has not yet had a size event, and so it hasn't
resized the panel yet. When the frame is shown then it will have a size
event and at that point the panel will be resized to fill the frame.

        self.tree=wxTreeCtrl(panel,-1)
# self.tree.SetSize(panel.GetClientSize()) <-Same here?

On the other hand, the panel does not automatically resize children to fill
the available space, so unless told otherwise the tree will use a default
size of 20,20. There are a few alternatives you can use. 1. Give the panel
an EVT_SIZE handler that does something like this:

    def OnPanelSize(self, evt):
        self.tree.SetSize(evt.GetSize())

2. Use sizers or layout constraints to do autolayout. See the docs and the
demo for samples.

···

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

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users