468,107 Members | 1,302 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

wxPython: Fit() works on wxPanel, but not on surrounding wxFrame

Hello,
I am still struggling with a dynamic dialog box.
I have created a dialog box that will show a variable number of
controls depending on a selection made in a ComboBox also present in
the frame. The dialog box is not derived from wxDialog, but from a
wxFrame.
The dialog is initialized as follows:

class myDialog(wxFrame):
def __init__(self,parent,title):
wxFrame.__init__(self,parent,-1, title,
style=wxDEFAULT_FRAME_STYLE)
self.panel = wxPanel(self,-1)
The position of the controls on the wxPanel inside the frame is
controlled by sizers, which are initialized as follows:
self.MasterSizer=wxBoxSizer(wxVERTICAL)
self.panel.SetSizer(self.MasterSizer)
self.panel.SetAutoLayout(True)
self.MasterSizer.Fit(self.panel)
self.panel.Fit()
self.Fit()

To ensure that the size of the window and its layout always take into
account the number of the controls, every function that will change
the number of controls ends with the following threelines:
self.MasterSizer.RecalcSizes()
self.panel.Fit()
self.Fit()

For some reason, only the wxPanel changes its size as expected and
fits nicely around the controls placed on it. The surrounding wxFrame
is always (except at initialization time) slightly larger than the
panel, resulting in an ugly, dark grey border on the right and at the
bottom of the frame. How is that possible?
Thanks in advance for your help
Piet
Jul 18 '05 #1
1 5173
pi********@gmx.de (Piet) wrote:

[snip]
class myDialog(wxFrame):
def __init__(self,parent,title):
wxFrame.__init__(self,parent,-1, title, style=wxDEFAULT_FRAME_STYLE)
self.panel = wxPanel(self,-1)

The position of the controls on the wxPanel inside the frame is
controlled by sizers, which are initialized as follows:

self.MasterSizer=wxBoxSizer(wxVERTICAL)
self.panel.SetSizer(self.MasterSizer)
self.panel.SetAutoLayout(True)
self.MasterSizer.Fit(self.panel)
self.panel.Fit()
self.Fit()

To ensure that the size of the window and its layout always take into
account the number of the controls, every function that will change
the number of controls ends with the following threelines:

self.MasterSizer.RecalcSizes()
self.panel.Fit()
self.Fit()


I don't think Fit() is needed, it's implied by:

self.MasterSizer.SetSizeHints(self)

But you've not used that. You've also not added the panel to the
sizer:

self.MasterSizer.Add(self.panel, 1, wx.ALL|wx.EXPAND, 0)

Also, I think you need a self.Layout() at the end of those three
lines.

Finally, beware of scrollbars, they're not at all well handled by wx's
sizers.

To get past the initial layout differing from the resized layout, I
usually would call your EVT_SIZE handler to do the initial layout too,
then you can just fix one function....

It's a bit hard to debug with only a snippet of code.
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tom Plunket | last post: by
5 posts views Thread by Daniel Ehrenberg | last post: by
1 post views Thread by Curzio Basso | last post: by
3 posts views Thread by Piet | last post: by
2 posts views Thread by Emiliano Molina | last post: by
1 post views Thread by mdk.R | last post: by
2 posts views Thread by CYBER | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.