[wxpython-users] How to create a GUI that changes
layout dynamically?
Stef Mientki
s.mientki at ru.nl
Thu Apr 3 10:30:40 PDT 2008
maybe AUI might give you a solution for your problem.
cheers,
Stef Mientki
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.
>
> 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()
> ------------------------------------------------------------------------
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users at lists.wxwidgets.org
> http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
>
More information about the wxpython-users
mailing list