Proportionality together with minimum and/or maximum sizes.

Hi,

Would anyone know if it is possible to have a wx element with minimum
and maximum sizes set (SetMinSize() and SetMaxSize()), as well as
being proportional (Add(item, proportion=1)) when one of these
boundaries has not been encountered? Below is an example where I
would like the blue panel to have this property, while the other
elements below it are either fixed or proportional. Is there a way of
doing this without coming up with a custom layout algorithm? Any
suggestions would be much appreciated.

Cheers,

Edward

#!/usr/bin/env python

import wx

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        sizer = wx.BoxSizer(wx.VERTICAL)

        # Blue panel (min of 100, max of 300, and proportional).
        panel = wx.Panel(self, -1)
        panel.SetBackgroundColour("Blue")
        panel.SetMinSize((-1, 100))
        panel.SetMaxSize((-1, 300))
        sizer.Add(panel, 2, wx.ALL|wx.EXPAND, 0)

        # Red panel (fixed size).
        panel = wx.Panel(self, -1)
        panel.SetBackgroundColour("Red")
        panel.SetSize((-1, 50))
        sizer.Add(panel, 0, wx.ALL|wx.EXPAND, 0)

        # Green panel (proportional).
        panel = wx.Panel(self, -1)
        panel.SetBackgroundColour("Green")
        sizer.Add(panel, 1, wx.ALL|wx.EXPAND, 0)

        # Set the sizer.
        self.SetSizer(sizer)

if __name__ == '__main__':
     app = wx.App()
     frame = MyFrame(None, title="My App")
     frame.Show()
     app.MainLoop()

What are your goals for having “a wx element [ a control ?] with minimum
and maximum sizes… as well as being proportional[ly expandible]” ? What do you want to happen when the control reaches either its minimum or maximum ? What is supposed to happen with the other controls at these times ?

I think you probably want the Frame to have minimum and maximum sizes. Sizers and Windows have the method .SetMinSize() / MaxSize(), but I don’t think it is functional in Panels. You can call it like you already, but it doesn’t do anything.

You can try this approach: When the BLUE panel (I presume) reaches its minimum size, add in the widths and heights of the other 2 panels. This is the minimum Frame Client width. Do the same with the vertical / height dimensions. --> The ratio of the BLUE panel height to GREEN panel height is 2:1. The RED is fixed at 50. So, if you want BLUE to be a minimum of 100 pixels, the RED will always 50 and GREEN must be 25, This is 175 pixels, total height. So, set the minimum Frame height accordingly.

There is a method wx.Frame.SetMinSize(), but unfortunately, no wx.Frame.SetMinClientSize(). You can use a “trick” to get the Frame to do what you want it to: First, determine what you want the minimum horizontal size to be. Let’s use 200 pixels for now:

self.SetClientSize( (200, 175) )
selfFrameSize = self.GetSize()
self.SetMinSize ( (selfFrameSize) )

Do the same for the max Frame size. Remember to set the Frame size back to what you want its initial size to be.

By the way, you might want to give the 3 panels 3 different names, otherwise you give up the ability to reference the first two in the future.

Hope this helps.
Ray Pasco

Hi,

Would anyone know if it is possible to have a wx element with minimum
and maximum sizes set (SetMinSize() and SetMaxSize()),

Sizers currently do not look at the max size, although some windows will limit themselves based on the max size. But without the sizers also paying attention to it then the layouts using both will likely not be what you are expecting.

as well as
being proportional (Add(item, proportion=1)) when one of these
boundaries has not been encountered? Below is an example where I
would like the blue panel to have this property, while the other
elements below it are either fixed or proportional. Is there a way of
doing this without coming up with a custom layout algorithm? Any
suggestions would be much appreciated.

Box sizers in 2.9.2 (coming soon, preview builds are available) have been updated such that they ensure that items' min size needs are met first, (even for proportional items) and then the left over space is divided among the proportional items. Perhaps that will be closer to what you are looking for.

As always, using the WIT can be a very useful tool when designing or debugging layouts. http://wiki.wxpython.org/Widget_Inspection_Tool

···

On 7/22/11 12:43 AM, Edward d'Auvergne wrote:

--
Robin Dunn
Software Craftsman