How to create a GUI that changes layout dynamically?

`Hi,

I’m trying to create a GUI with a lot of different controls, which
should all be minimizeable. So that when one control minimizes the
other controls in the layout can resize to use the freed space.

Does anyone know how to do this in wxPython, or just point me in the
right direction? Are there any programs that does this that I can look
at? Any pages in the wiki that could be useful?

I’ve been looking all around.

`

···

`The
appropriate wx-controls I found are wxFoldPanelBar and
wxCollapsiblePane. FoldPanelBar did minimize, but couldn’t resize to
acquire the cleared space. CollapsiblePane worked but resized the whole
frame upon Collapse/Expand if not major workarounds were used.

This is my last try with CollapsiblePane:


I’ve created a simple GUI with two CollapsiblePanes on top of each
other in a vertical BoxSizer. When I minimize one pane I want all other

panes to resize and increase height to cover the newly aquired space.

I got this result with the code example below. But with that program,
the user can’t resize the frame. It will pop back to its original,
hardcoded, size when a CollapsiblePane is collapsed/expanded.

Does anyone know a way around this problem?

If I don’t force the frame to a specified size it will resize totally
and behave strange. Look at ## (1) ## and ## (2) ## in this example:

import wx

class MainFrame(wx.Frame):

def __init__(self):

    wx.Frame.__init__(self, parent = None, size = (500,500))

    self.frameZ = frameZ = wx.BoxSizer(wx.VERTICAL) # Create main

sizer

    ## (1) ## If this SetMinSize() is omitted, the frame will

resize totally

    frameZ.SetMinSize((500,500)) # Lock the size of the frame

    self.SetSizer(frameZ)

   

    # Create CollapsePane wrapper objects, pass frame as arg

    cp1 = ColPaneWrapper(self)

    cp2 = ColPaneWrapper(self)

   

    # Do Layout() and SetSizeHints() for main frame

    frameZ.Layout()

    frameZ.SetSizeHints(self)

class ColPaneWrapper:

def __init__(self, frame):

    self.cp = cp = wx.CollapsiblePane(frame) # Create CollapsePane

object, frame as parent

    self.frameZ = frameZ = frame.frameZ # Get frame sizer

    self.frame = frame # Get frame

    frame.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnCollapse, cp)

Bind OnCollapse event

    cp_pane = cp.GetPane() # Get pane to use as parent for controls

and sizer

    self.cpZ = cpZ = wx.BoxSizer(wx.VERTICAL) # Create CP sizer

    cp_pane.SetSizer(cpZ) # Assign sizer to CPs pane

   

    button = wx.Button(cp_pane, label = 'SomePlaceholderControl') #

Create button, use CPs pane as parent

    cpZ.Add(button, 1, wx.EXPAND | wx.ALL, 0) # Add button to CP

sizer

    frameZ.Add(cp, 1, wx.EXPAND | wx.ALL, 0) # Add CP to frame sizer

   

    # Do OnCollapse to refresh the state of the panes

    self.OnCollapse()

def OnCollapse(self, evt = None):

# OnCollapse:

# Change the Sizer-Proportion-state of the CP to match the

Expanded/Collapsed state

    if self.cp.IsCollapsed():

        self.frameZ.GetItem(self.cp).SetProportion(0)

    else:

        self.frameZ.GetItem(self.cp).SetProportion(1)

   

    # Do Layout() for CPs sizer

    self.cpZ.Layout()

   

    ## (2) ## If this SetSizeHints() is omitted, the frame will

resize totally.

    self.frameZ.SetSizeHints(self.frame) # SetSizeHints for frame

sizer

if name == “main”:

app = wx.App()

MainFrame().Show()

app.MainLoop()

`

Robin Dunn wrote:

Anton Blomberg wrote:

Hi,
I'm trying to create a GUI with a lot of different controls, which
should all be minimizeable. So that when one control minimizes the
other controls in the layout can resize to use the freed space.

Does anyone know how to do this in wxPython, or just point me in the
right direction? Are there any programs that does this that I can
look at? Any pages in the wiki that could be useful?
I've been looking all around.

The appropriate wx-controls I found are wxFoldPanelBar and
wxCollapsiblePane. FoldPanelBar did minimize, but couldn't resize to
acquire the cleared space. CollapsiblePane worked but resized the
whole frame upon Collapse/Expand if not major workarounds were used.

You should be able to prevent that by using the wx.CP_NO_TLW_RESIZE
style flag.

I did try that. But if I use wx.CP_NO_TLW_RESIZE style flag the
wx.EVT_COLLAPSIBLEPANE_CHANGED event never gets fired.
So the OnCollapse() function never runs, and the panes don't resize. Is
there any other event that could be useful instead of the PANE_CHANGED?

Footnote:
I forgot to say that I develop on Ubuntu, and the example my first post
doesn't work on Windows.