]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/CollapsiblePane.py
Added wx.CollapsiblePane
[wxWidgets.git] / wxPython / demo / CollapsiblePane.py
1
2 import wx
3
4 #----------------------------------------------------------------------
5
6 label1 = "Click here to show pane"
7 label2 = "Click here to hide pane"
8
9 btnlbl1 = "call Expand(True)"
10 btnlbl2 = "call Expand(False)"
11
12
13 class TestPanel(wx.Panel):
14 def __init__(self, parent, log):
15 self.log = log
16 wx.Panel.__init__(self, parent, -1)
17
18 title = wx.StaticText(self, label="wx.CollapsiblePane")
19 title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
20 title.SetForegroundColour("blue")
21
22 self.cp = cp = wx.CollapsiblePane(self, label=label1)
23 self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnPaneChanged, cp)
24 self.MakePaneContent(cp.GetPane())
25
26 sizer = wx.BoxSizer(wx.VERTICAL)
27 self.SetSizer(sizer)
28 sizer.Add(title, 0, wx.ALL, 25)
29 sizer.Add(cp, 0, wx.RIGHT|wx.LEFT|wx.EXPAND, 25)
30
31 self.btn = btn = wx.Button(self, label=btnlbl1)
32 self.Bind(wx.EVT_BUTTON, self.OnToggle, btn)
33 sizer.Add(btn, 0, wx.ALL, 25)
34
35
36 def OnToggle(self, evt):
37 self.cp.Collapse(self.cp.IsExpanded())
38 self.OnPaneChanged()
39
40
41 def OnPaneChanged(self, evt=None):
42 self.log.write('wx.EVT_COLLAPSIBLEPANE_CHANGED')
43 self.Layout()
44 if self.cp.IsExpanded():
45 self.cp.SetLabel(label2)
46 self.btn.SetLabel(btnlbl2)
47 else:
48 self.cp.SetLabel(label1)
49 self.btn.SetLabel(btnlbl1)
50 self.btn.SetInitialSize()
51
52
53 def MakePaneContent(self, pane):
54 '''Just make a few controls to put on the collapsible pane'''
55 nameLbl = wx.StaticText(pane, -1, "Name:")
56 name = wx.TextCtrl(pane, -1, "");
57
58 addrLbl = wx.StaticText(pane, -1, "Address:")
59 addr1 = wx.TextCtrl(pane, -1, "");
60 addr2 = wx.TextCtrl(pane, -1, "");
61
62 cstLbl = wx.StaticText(pane, -1, "City, State, Zip:")
63 city = wx.TextCtrl(pane, -1, "", size=(150,-1));
64 state = wx.TextCtrl(pane, -1, "", size=(50,-1));
65 zip = wx.TextCtrl(pane, -1, "", size=(70,-1));
66
67 addrSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
68 addrSizer.Add((10,10))
69 addrSizer.Add((10,10))
70 addrSizer.AddGrowableCol(1)
71 addrSizer.Add(nameLbl, 0,
72 wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
73 addrSizer.Add(name, 0, wx.EXPAND)
74 addrSizer.Add(addrLbl, 0,
75 wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
76 addrSizer.Add(addr1, 0, wx.EXPAND)
77 addrSizer.Add((10,10))
78 addrSizer.Add(addr2, 0, wx.EXPAND)
79
80 addrSizer.Add(cstLbl, 0,
81 wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
82
83 cstSizer = wx.BoxSizer(wx.HORIZONTAL)
84 cstSizer.Add(city, 1)
85 cstSizer.Add(state, 0, wx.LEFT|wx.RIGHT, 5)
86 cstSizer.Add(zip)
87 addrSizer.Add(cstSizer, 0, wx.EXPAND)
88
89 pane.SetSizer(addrSizer)
90
91
92
93 #----------------------------------------------------------------------
94
95 def runTest(frame, nb, log):
96 win = TestPanel(nb, log)
97 return win
98
99 #----------------------------------------------------------------------
100
101
102
103 overview = """<html><body>
104 <h2><center>wx.CollapsiblePane</center></h2>
105
106 A collapsable panel is a container with an embedded button-like
107 control which can be used by the user to collapse or expand the pane's
108 contents.
109
110 </body></html>
111 """
112
113
114
115 if __name__ == '__main__':
116 import sys,os
117 import run
118 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
119