]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/MultiSplitterWindow.py
Include "xrc" support properly for OpenVMS
[wxWidgets.git] / wxPython / demo / MultiSplitterWindow.py
1
2 import wx
3 from wx.lib.splitter import MultiSplitterWindow
4
5 #----------------------------------------------------------------------
6
7 class SamplePane(wx.Panel):
8 """
9 Just a simple test window to put into the splitter.
10 """
11 def __init__(self, parent, colour, label):
12 wx.Panel.__init__(self, parent, style=wx.BORDER_SUNKEN)
13 self.SetBackgroundColour(colour)
14 wx.StaticText(self, -1, label, (5,5))
15
16 def SetOtherLabel(self, label):
17 wx.StaticText(self, -1, label, (5, 30))
18
19
20
21 class ControlPane(wx.Panel):
22 def __init__(self, parent):
23 wx.Panel.__init__(self, parent)
24
25 hvBox = wx.RadioBox(self, -1, "Orientation",
26 choices=["Horizontal", "Vertical"],
27 style=wx.RA_SPECIFY_COLS,
28 majorDimension=1)
29 hvBox.SetSelection(0)
30 self.Bind(wx.EVT_RADIOBOX, self.OnSetHV, hvBox)
31
32 luCheck = wx.CheckBox(self, -1, "Live Update")
33 luCheck.SetValue(True)
34 self.Bind(wx.EVT_CHECKBOX, self.OnSetLiveUpdate, luCheck)
35
36 btn = wx.Button(self, -1, "Swap 2 && 4")
37 self.Bind(wx.EVT_BUTTON, self.OnSwapButton, btn)
38
39 sizer = wx.BoxSizer(wx.VERTICAL)
40 sizer.Add(hvBox)
41 sizer.Add(luCheck, 0, wx.TOP, 5)
42 sizer.Add(btn, 0, wx.TOP, 5)
43 border = wx.BoxSizer()
44 border.Add(sizer, 1, wx.EXPAND|wx.ALL, 5)
45 self.SetSizer(border)
46
47
48 def OnSetHV(self, evt):
49 rb = evt.GetEventObject()
50 self.GetParent().SetOrientation(rb.GetSelection())
51
52
53 def OnSetLiveUpdate(self, evt):
54 check = evt.GetEventObject()
55 self.GetParent().SetLiveUpdate(check.GetValue())
56
57
58 def OnSwapButton(self, evt):
59 self.GetParent().Swap2and4()
60
61
62
63 class TestPanel(wx.Panel):
64 def __init__(self, parent, log):
65 self.log = log
66 wx.Panel.__init__(self, parent, -1)
67
68 cp = ControlPane(self)
69
70 splitter = MultiSplitterWindow(self, style=wx.SP_LIVE_UPDATE)
71 self.splitter = splitter
72 sizer = wx.BoxSizer(wx.HORIZONTAL)
73 sizer.Add(cp)
74 sizer.Add(splitter, 1, wx.EXPAND)
75 self.SetSizer(sizer)
76
77
78 p1 = SamplePane(splitter, "pink", "Panel One")
79 p1.SetOtherLabel(
80 "There are two sash\n"
81 "drag modes. Try\n"
82 "dragging with and\n"
83 "without the Shift\n"
84 "key held down."
85 )
86 splitter.AppendWindow(p1, 140)
87
88 p2 = SamplePane(splitter, "sky blue", "Panel Two")
89 p2.SetOtherLabel("This window\nhas a\nminsize.")
90 p2.SetMinSize(p2.GetBestSize())
91 splitter.AppendWindow(p2, 150)
92
93 p3 = SamplePane(splitter, "yellow", "Panel Three")
94 splitter.AppendWindow(p3, 125)
95
96 p4 = SamplePane(splitter, "Lime Green", "Panel Four")
97 splitter.AppendWindow(p4)
98
99 self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnChanged)
100 self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGING, self.OnChanging)
101
102
103 def OnChanging(self, evt):
104 self.log.write( "Changing sash:%d %s\n" %
105 (evt.GetSashIdx(), evt.GetSashPosition()))
106 # This is one way to control the sash limits
107 #if evt.GetSashPosition() < 50:
108 # evt.Veto()
109
110 # Or you can reset the sash position to whatever you want
111 #if evt.GetSashPosition() < 5:
112 # evt.SetSashPosition(25)
113
114
115 def OnChanged(self, evt):
116 self.log.write( "Changed sash:%d %s\n" %
117 (evt.GetSashIdx(), evt.GetSashPosition()))
118
119
120 def SetOrientation(self, value):
121 if value:
122 self.splitter.SetOrientation(wx.VERTICAL)
123 else:
124 self.splitter.SetOrientation(wx.HORIZONTAL)
125 self.splitter.SizeWindows()
126
127
128 def SetLiveUpdate(self, enable):
129 if enable:
130 self.splitter.SetWindowStyle(wx.SP_LIVE_UPDATE)
131 else:
132 self.splitter.SetWindowStyle(0)
133
134
135 def Swap2and4(self):
136 win2 = self.splitter.GetWindow(1)
137 win4 = self.splitter.GetWindow(3)
138 self.splitter.ExchangeWindows(win2, win4)
139
140 #----------------------------------------------------------------------
141
142 def runTest(frame, nb, log):
143 win = TestPanel(nb, log)
144 return win
145
146 #----------------------------------------------------------------------
147
148
149
150 overview = """<html><body>
151 <h2><center>MultiSplitterWindow</center></h2>
152
153 This class is very similar to wx.SplitterWindow except that it
154 allows for more than two windows and more than one sash. Many of
155 the same styles, constants, and methods behave the same as in
156 wx.SplitterWindow.
157
158 </body></html>
159 """
160
161
162
163 if __name__ == '__main__':
164 import sys,os
165 import run
166 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
167