]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/CollapsiblePane.py
fix building/running of tex2rtf
[wxWidgets.git] / wxPython / demo / CollapsiblePane.py
CommitLineData
73470a17
RD
1
2import wx
3
4#----------------------------------------------------------------------
5
6label1 = "Click here to show pane"
7label2 = "Click here to hide pane"
8
9btnlbl1 = "call Expand(True)"
10btnlbl2 = "call Expand(False)"
11
12
13class 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):
2a8d232e
RD
42 if evt:
43 self.log.write('wx.EVT_COLLAPSIBLEPANE_CHANGED: %s' % evt.Collapsed)
44
45 # redo the layout
73470a17 46 self.Layout()
2a8d232e
RD
47
48 # and also change the labels
73470a17
RD
49 if self.cp.IsExpanded():
50 self.cp.SetLabel(label2)
51 self.btn.SetLabel(btnlbl2)
52 else:
53 self.cp.SetLabel(label1)
54 self.btn.SetLabel(btnlbl1)
55 self.btn.SetInitialSize()
56
57
58 def MakePaneContent(self, pane):
59 '''Just make a few controls to put on the collapsible pane'''
60 nameLbl = wx.StaticText(pane, -1, "Name:")
61 name = wx.TextCtrl(pane, -1, "");
62
63 addrLbl = wx.StaticText(pane, -1, "Address:")
64 addr1 = wx.TextCtrl(pane, -1, "");
65 addr2 = wx.TextCtrl(pane, -1, "");
66
67 cstLbl = wx.StaticText(pane, -1, "City, State, Zip:")
68 city = wx.TextCtrl(pane, -1, "", size=(150,-1));
69 state = wx.TextCtrl(pane, -1, "", size=(50,-1));
70 zip = wx.TextCtrl(pane, -1, "", size=(70,-1));
71
72 addrSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
73470a17
RD
73 addrSizer.AddGrowableCol(1)
74 addrSizer.Add(nameLbl, 0,
75 wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
76 addrSizer.Add(name, 0, wx.EXPAND)
77 addrSizer.Add(addrLbl, 0,
78 wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
79 addrSizer.Add(addr1, 0, wx.EXPAND)
2a8d232e 80 addrSizer.Add((5,5))
73470a17
RD
81 addrSizer.Add(addr2, 0, wx.EXPAND)
82
83 addrSizer.Add(cstLbl, 0,
84 wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
85
86 cstSizer = wx.BoxSizer(wx.HORIZONTAL)
87 cstSizer.Add(city, 1)
88 cstSizer.Add(state, 0, wx.LEFT|wx.RIGHT, 5)
89 cstSizer.Add(zip)
90 addrSizer.Add(cstSizer, 0, wx.EXPAND)
91
2a8d232e
RD
92 border = wx.BoxSizer()
93 border.Add(addrSizer, 1, wx.EXPAND|wx.ALL, 5)
94 pane.SetSizer(border)
73470a17
RD
95
96
97
98#----------------------------------------------------------------------
99
100def runTest(frame, nb, log):
101 win = TestPanel(nb, log)
102 return win
103
104#----------------------------------------------------------------------
105
106
107
108overview = """<html><body>
109<h2><center>wx.CollapsiblePane</center></h2>
110
111A collapsable panel is a container with an embedded button-like
112control which can be used by the user to collapse or expand the pane's
113contents.
114
115</body></html>
116"""
117
118
119
120if __name__ == '__main__':
121 import sys,os
122 import run
123 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
124