]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/CollapsiblePane.py
corrected wrong change description: raw RGB support was already there
[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 style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE)
24 self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnPaneChanged, cp)
25 self.MakePaneContent(cp.GetPane())
26
27 sizer = wx.BoxSizer(wx.VERTICAL)
28 self.SetSizer(sizer)
29 sizer.Add(title, 0, wx.ALL, 25)
30 sizer.Add(cp, 0, wx.RIGHT|wx.LEFT|wx.EXPAND, 25)
31
32 self.btn = btn = wx.Button(self, label=btnlbl1)
33 self.Bind(wx.EVT_BUTTON, self.OnToggle, btn)
34 sizer.Add(btn, 0, wx.ALL, 25)
35
36
37 def OnToggle(self, evt):
38 self.cp.Collapse(self.cp.IsExpanded())
39 self.OnPaneChanged()
40
41
42 def OnPaneChanged(self, evt=None):
43 if evt:
44 self.log.write('wx.EVT_COLLAPSIBLEPANE_CHANGED: %s' % evt.Collapsed)
45
46 # redo the layout
47 self.Layout()
48
49 # and also change the labels
50 if self.cp.IsExpanded():
51 self.cp.SetLabel(label2)
52 self.btn.SetLabel(btnlbl2)
53 else:
54 self.cp.SetLabel(label1)
55 self.btn.SetLabel(btnlbl1)
56 self.btn.SetInitialSize()
57
58
59 def MakePaneContent(self, pane):
60 '''Just make a few controls to put on the collapsible pane'''
61 nameLbl = wx.StaticText(pane, -1, "Name:")
62 name = wx.TextCtrl(pane, -1, "");
63
64 addrLbl = wx.StaticText(pane, -1, "Address:")
65 addr1 = wx.TextCtrl(pane, -1, "");
66 addr2 = wx.TextCtrl(pane, -1, "");
67
68 cstLbl = wx.StaticText(pane, -1, "City, State, Zip:")
69 city = wx.TextCtrl(pane, -1, "", size=(150,-1));
70 state = wx.TextCtrl(pane, -1, "", size=(50,-1));
71 zip = wx.TextCtrl(pane, -1, "", size=(70,-1));
72
73 addrSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
74 addrSizer.AddGrowableCol(1)
75 addrSizer.Add(nameLbl, 0,
76 wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
77 addrSizer.Add(name, 0, wx.EXPAND)
78 addrSizer.Add(addrLbl, 0,
79 wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
80 addrSizer.Add(addr1, 0, wx.EXPAND)
81 addrSizer.Add((5,5))
82 addrSizer.Add(addr2, 0, wx.EXPAND)
83
84 addrSizer.Add(cstLbl, 0,
85 wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
86
87 cstSizer = wx.BoxSizer(wx.HORIZONTAL)
88 cstSizer.Add(city, 1)
89 cstSizer.Add(state, 0, wx.LEFT|wx.RIGHT, 5)
90 cstSizer.Add(zip)
91 addrSizer.Add(cstSizer, 0, wx.EXPAND)
92
93 border = wx.BoxSizer()
94 border.Add(addrSizer, 1, wx.EXPAND|wx.ALL, 5)
95 pane.SetSizer(border)
96
97
98
99 #----------------------------------------------------------------------
100
101 def runTest(frame, nb, log):
102 win = TestPanel(nb, log)
103 return win
104
105 #----------------------------------------------------------------------
106
107
108
109 overview = """<html><body>
110 <h2><center>wx.CollapsiblePane</center></h2>
111
112 A collapsable panel is a container with an embedded button-like
113 control which can be used by the user to collapse or expand the pane's
114 contents.
115
116 </body></html>
117 """
118
119
120
121 if __name__ == '__main__':
122 import sys,os
123 import run
124 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
125