X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3bdec81e147765682eda34adb84288a5eb9ab6c2..d63f7562cf9ccad9c430d4c2e2a8bd416a016d89:/wxPython/demo/SizedControls.py diff --git a/wxPython/demo/SizedControls.py b/wxPython/demo/SizedControls.py index bd8a7628cf..857e88f4a7 100644 --- a/wxPython/demo/SizedControls.py +++ b/wxPython/demo/SizedControls.py @@ -2,30 +2,35 @@ import wx import wxaddons.sized_controls as sc overview = """\ -SizedControls is an addon library that attempts to simplify the creation of -sizer-based layouts. It adds the following classes: - -<b>SizedPanel</b> - -This class automatically creates its own sizer (a vertical box sizer -by default) and automatically adds its children to the sizer. You can change the -SizedPanel's sizer type by calling panel.SetSizerType("type", [args]), where valid types are -"horizontal", "vertical", "form" (a 2-col flex grid sizer), and "grid". Args include -"cols" and "rows" attributes for grids. This class also applies control borders -that adhere to the native platform's Human Interface Guidelines (HIG) on Win, GTK and Mac. - -<b>SizedFrame and SizedDialog</b> - -These classes automatically setup a SizedPanel which -is appropriately positioned and given appropriate borders in accordance with the +<html><body><h2>Sized Controls</h2> +SizedControls is an addon library that attempts to simplify the +creation of sizer-based layouts. It adds the following classes: + +<h3>SizedPanel</h3> + +This class automatically creates its own sizer (a vertical box sizer +by default) and automatically adds its children to the sizer. You can +change the SizedPanel's sizer type by calling +panel.SetSizerType(\"type\", [args]), where valid types are +\"horizontal\", \"vertical\", \"form\" (a 2-col flex grid sizer), and +\"grid\". Args include \"cols\" and \"rows\" attributes for +grids. This class also applies control borders that adhere to the +native platform's Human Interface Guidelines (HIG) on Win, GTK and +Mac. + +<h3>SizedFrame and SizedDialog</h3> + +These classes automatically setup a SizedPanel which is appropriately +positioned and given appropriate borders in accordance with the platform's HIGs. -Since controls are added to the parent's sizer upon creation, you don't need to -use sizer.Add or even create sizers yourself. You just use SetSizerType() to -change the sizer you want to use, and control.SetSizerProps() to change the -sizer properties of the control. So as a result, code that used to look like this: +<p>Since controls are added to the parent's sizer upon creation, you +don't need to use sizer.Add or even create sizers yourself. You just +use SetSizerType() to change the sizer you want to use, and +control.SetSizerProps() to change the sizer properties of the +control. So as a result, code that used to look like this: -<table bgcolor="#EFEFEF"><tr><td><code> +<table bgcolor=\"#EFEFEF\"><tr><td><pre> ... wx.Dialog init code... panel = wx.Panel(self, -1) @@ -46,16 +51,16 @@ dlgSizer.Add(panel, 1, wx.EXPAND) self.SetSizer(dlgSizer) self.SetAutoLayout(True) -... rest of dialog ...</code> +... rest of dialog ...</pre> </td></tr></table> would now look like this: -<table bgcolor="#EFEFEF"><tr><td><code> +<table bgcolor=\"#EFEFEF\"><tr><td><pre> ... wx.Dialog init code... panel = self.GetContentsPane() -panel.SetSizerType("horizontal") +panel.SetSizerType(\"horizontal\") b1 = wx.Button(panel, -1) b2 = wx.Button(panel, -1) @@ -65,13 +70,60 @@ t1.SetSizerProps(expand=True) b3 = wx.Button(panel, -1) -... rest of dialog ...</code> +... rest of dialog ...</pre> </td></tr></table> -and the latter example will adhere to HIG spacing guidelines on all platforms, -unlike the former example. -Please check the demos for more complete and sophisticated examples of SizedControls +and the latter example will adhere to HIG spacing guidelines on all platforms, +unlike the former example. Please check the demos for more complete and sophisticated examples of SizedControls in action. + +<h3>wx.Window.SetSizerProps Quick Reference</h3> + +<p><pre>wx.Window.SetSizerProps(<props>)</pre> + +<p> +<table bgcolor=\"#EFEFEF\"> +<tr> +<td valign="middle" width="90"><b>Parameter</b></td> <td valign="middle"><b>Values</b></td> <td valign="middle"><b>Summary</b></td> +</tr> + +<tr> +<td><i>expand</i></td> <td>True/False</td> +<td>Whether or not the control should grow to fill free space if +free space is available.</td> +</tr> + +<tr> +<td><i>proportion</i></td> <td>Number (typically 0-10)</td> +<td>How much of the free space the control should take up. Note that this value is +<i>relative</i> to other controls, so a proportion of 2 means take up +'twice as much' space as controls with a proportion of 1.</td> +</tr> + +<tr> +<td><i>halign</i> <td>"left", "center", "centre", "right"</td> +<td>Determines horizontal alignment of control.</td> +</tr> + +<tr> +<td><i>valign</i> <td>"top", "center", "centre", "bottom"</td> +<td>Determines vertical alignment of control.</td> +</tr> + +<tr> +<td><i>border</i> <td>Tuple: ([<i>dirs</i>], integer)</td> +<td>Specifies amount of border padding to apply to specified directions. </br> +Example: (["left", "right"], 6) would add six pixels to left and right borders. </br> +Note that, unfortunately, +it is not currently possible to assign different border sizes to each direction.</td> +</tr> + +<tr> +<td><i>minsize</i> <td>One of the following string values: "fixed", "adjust"</td> +<td>Determines whether or not the minsize can be updated when the control's best size changes.</td> +</tr> + +</table> """ class FormDialog(sc.SizedDialog): @@ -170,6 +222,35 @@ class ErrorDialog(sc.SizedDialog): self.listCtrl.SetColumnWidth(0, 100) self.listCtrl.SetColumnWidth(1, 280) + +class GridFrame(sc.SizedFrame): + def __init__(self, parent, id): + sc.SizedFrame.__init__(self, parent, id, "Grid Layout Demo Frame") + + pane = self.GetContentsPane() + pane.SetSizerType("grid", {"cols":3}) # 3-column grid layout + + # row 1 + wx.TextCtrl(pane, -1).SetSizerProps(halign="left") + wx.TextCtrl(pane, -1).SetSizerProps(halign="center") + wx.TextCtrl(pane, -1).SetSizerProps(halign="right") + + # row 2 + wx.TextCtrl(pane, -1).SetSizerProps(valign="center") + wx.TextCtrl(pane, -1).SetSizerProps(expand=True, proportion=1) + wx.TextCtrl(pane, -1).SetSizerProps(valign="center") + + # row 3 + wx.TextCtrl(pane, -1).SetSizerProps(halign="left") + wx.TextCtrl(pane, -1).SetSizerProps(halign="center") + wx.TextCtrl(pane, -1).SetSizerProps(halign="right") + + self.CreateStatusBar() # should always do this when there's a resize border + + self.Fit() + self.SetMinSize(self.GetSize()) + + #--------------------------------------------------------------------------- class TestPanel(wx.Panel): @@ -182,7 +263,10 @@ class TestPanel(wx.Panel): self.Bind(wx.EVT_BUTTON, self.OnFormButton, b) b2 = wx.Button(self, -1, "Sized Controls Error Dialog", (50,90)) - self.Bind(wx.EVT_BUTTON, self.OnErrorButton, b2) + self.Bind(wx.EVT_BUTTON, self.OnErrorButton, b2) + + b3 = wx.Button(self, -1, "Sized Controls Grid Layout Demo", (50,130)) + self.Bind(wx.EVT_BUTTON, self.OnGridButton, b3) def OnFormButton(self, evt): @@ -215,11 +299,20 @@ class TestPanel(wx.Panel): dlg.Destroy() + def OnGridButton(self, evt): + + dlg = GridFrame(self, -1) + dlg.CenterOnScreen() + + dlg.Show() + def runTest(frame, nb, log): win = TestPanel(nb, log) return win -if __name__ == "__main__": - app = wx.PySimpleApp() - dlg = FormDialog() - dlg.ShowModal() \ No newline at end of file + +if __name__ == '__main__': + import sys,os + import run + run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) +