sizer alignment, scrolledpanel

Sample app below. There are two problems:

  1. The inner scrolledpanel starts off with a size of (0,0). I could call SetMinSize, and in fact that’s the workaround I ended up using in my app, and it doesn’t stop the frame from being resized to less than the minimum panel size unless I call SetMinSize on the frame too. This ends up working, I guess, but it’s messy.

  2. Those buttons are supposed to be aligned to the right, and stay on the right as the window is resized. I have no idea why this isn’t happening, but leaving out the scrolledpanel makes no difference, FWIW.

Any suggestions?

thanks,

Nat

import wx, wx.lib.scrolledpanel

class MyFrame (wx.Frame) :

def init (self, *args, **kwds) :

wx.Frame.init(self, *args, **kwds)

frame_sizer = wx.BoxSizer(wx.VERTICAL)

self.SetSizer(frame_sizer)

top_panel = wx.Panel(self)

top_sizer = wx.BoxSizer(wx.VERTICAL)

top_panel.SetSizer(top_sizer)

frame_sizer.Add(top_panel, 1, wx.ALL|wx.EXPAND|wx.ALIGN_RIGHT)

panel = wx.lib.scrolledpanel.ScrolledPanel(top_panel, -1, style=wx.SUNKEN_BORDER)

top_sizer.Add(panel, 1, wx.ALL|wx.EXPAND)

panel_sizer = wx.BoxSizer(wx.VERTICAL)

panel.SetSizer(panel_sizer)

for i in range(20) :

panel_sizer.Add(wx.StaticText(panel, -1, “Hello, world!”), 0, wx.ALL, 5)

btn_sizer = wx.BoxSizer(wx.HORIZONTAL)

btn_sizer.Add(wx.Button(top_panel, wx.ID_CANCEL), 0, wx.ALL|wx.ALIGN_RIGHT, 5)

btn_sizer.Add(wx.Button(top_panel, wx.ID_OK), 0, wx.ALL|wx.ALIGN_RIGHT, 5)

top_sizer.Add(btn_sizer, 0, wx.ALL|wx.EXPAND|wx.ALIGN_RIGHT, 5)

panel_sizer.Fit(panel)

top_sizer.Fit(top_panel)

panel.SetupScrolling(scrollToTop=False)

self.Fit()

if name == “main” :

app = wx.App(0)

frame = MyFrame(None, -1, “Test”)

frame.Show()

app.MainLoop()

Sample app below. There are two problems:
1) The inner scrolledpanel starts off with a size of (0,0). I could call
SetMinSize, and in fact that's the workaround I ended up using in my app,
and it doesn't stop the frame from being resized to less than the minimum
panel size unless I call SetMinSize on the frame too. This ends up working,
I guess, but it's messy.

I did a rewrite of the code (attached) in which I just gave the
scrolled panel a size
in its constructor, and kept the Fit() methods, and it seems fine now. Is
it OK to hard code an initial size just for this one panel?

2) Those buttons are supposed to be aligned to the right, and stay on the
right as the window is resized. I have no idea why this isn't happening,
but leaving out the scrolledpanel makes no difference, FWIW.

I think the problem was that you set wx.EXPAND and wx.ALIGN_RIGHT
at the same time...removing wx.EXPAND allowed it to work. Btw, you only
have to set ALIGN_RIGHT on the add of the btn_sizer, not on each button
itself; in other words, it is the whole sizer that is aligned to the right, not
the two individual buttons within that sizer.

Any suggestions?

My edit of your code is attached. In addition to what I mentioned above,
I made a few changes as suggestions:

1. You didn't need a sizer on the frame itself--the first panel will
automatically
fill the frame. So I cut that.

2. I grouped like things together and used some blank lines/comments to
make it more readable (and one other suggestion).

4. Gave one of the panels a different color to help distinguish it easily.

HTH,
Che

sizer_alignment.py (1.39 KB)

Sample app below. There are two problems:

  1. The inner scrolledpanel starts off with a size of (0,0). I could call

SetMinSize, and in fact that’s the workaround I ended up using in my app,

and it doesn’t stop the frame from being resized to less than the minimum

panel size unless I call SetMinSize on the frame too. This ends up working,

I guess, but it’s messy.

I did a rewrite of the code (attached) in which I just gave the

scrolled panel a size

in its constructor, and kept the Fit() methods, and it seems fine now. Is

it OK to hard code an initial size just for this one panel?

Maybe. I’m automatically generating controls based on a configuration file, and the virtual size of one of these panels could easily be taller than my screen. Will passing the size in the constructor prevent it from expanding as needed to accommodate those controls?

  1. Those buttons are supposed to be aligned to the right, and stay on the

right as the window is resized. I have no idea why this isn’t happening,

but leaving out the scrolledpanel makes no difference, FWIW.

I think the problem was that you set wx.EXPAND and wx.ALIGN_RIGHT

at the same time…removing wx.EXPAND allowed it to work. Btw, you only

have to set ALIGN_RIGHT on the add of the btn_sizer, not on each button

itself; in other words, it is the whole sizer that is aligned to the right, not

the two individual buttons within that sizer.

Huh. I don’t understand why this works, but problem solved - thanks!

  1. You didn’t need a sizer on the frame itself–the first panel will

automatically fill the frame. So I cut that.

Okay - I may have misunderstood the examples in the book.

···

On Thu, Nov 12, 2009 at 6:55 PM, C M cmpython@gmail.com wrote: