3 class SplitterExampleFrame(wx
.Frame
):
4 def __init__(self
, parent
, title
):
5 wx
.Frame
.__init
__(self
, parent
, title
=title
)
9 self
.sp
= wx
.SplitterWindow(self
)
10 self
.p1
= wx
.Panel(self
.sp
, style
=wx
.SUNKEN_BORDER
)
11 self
.p2
= wx
.Panel(self
.sp
, style
=wx
.SUNKEN_BORDER
)
12 self
.p1
.SetBackgroundColour("pink")
13 self
.p2
.SetBackgroundColour("sky blue")
17 self
.sp
.Initialize(self
.p1
)
19 self
.Bind(wx
.EVT_SPLITTER_SASH_POS_CHANGING
,
20 self
.OnSashChanging
, self
.sp
)
21 self
.Bind(wx
.EVT_SPLITTER_SASH_POS_CHANGED
,
22 self
.OnSashChanged
, self
.sp
)
25 def MakeMenuBar(self
):
27 item
= menu
.Append(-1, "Split horizontally")
28 self
.Bind(wx
.EVT_MENU
, self
.OnSplitH
, item
)
29 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnCheckCanSplit
, item
)
30 item
= menu
.Append(-1, "Split vertically")
31 self
.Bind(wx
.EVT_MENU
, self
.OnSplitV
, item
)
32 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnCheckCanSplit
, item
)
33 item
= menu
.Append(-1, "Unsplit")
34 self
.Bind(wx
.EVT_MENU
, self
.OnUnsplit
, item
)
35 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnCheckCanUnsplit
, item
)
37 menu
.AppendSeparator()
38 item
= menu
.Append(-1, "Set initial sash position")
39 self
.Bind(wx
.EVT_MENU
, self
.OnSetPos
, item
)
40 item
= menu
.Append(-1, "Set minimum pane size")
41 self
.Bind(wx
.EVT_MENU
, self
.OnSetMin
, item
)
43 menu
.AppendSeparator()
44 item
= menu
.Append(wx
.ID_EXIT
, "E&xit")
45 self
.Bind(wx
.EVT_MENU
, self
.OnExit
, item
)
48 mbar
.Append(menu
, "Splitter")
52 def OnSashChanging(self
, evt
):
53 print "OnSashChanging:", evt
.GetSashPosition()
55 def OnSashChanged(self
, evt
):
56 print "OnSashChanged:", evt
.GetSashPosition()
59 def OnSplitH(self
, evt
):
60 self
.sp
.SplitHorizontally(self
.p1
, self
.p2
, self
.initpos
)
62 def OnSplitV(self
, evt
):
63 self
.sp
.SplitVertically(self
.p1
, self
.p2
, self
.initpos
)
65 def OnCheckCanSplit(self
, evt
):
66 evt
.Enable(not self
.sp
.IsSplit())
68 def OnCheckCanUnsplit(self
, evt
):
69 evt
.Enable(self
.sp
.IsSplit())
71 def OnUnsplit(self
, evt
):
74 def OnSetMin(self
, evt
):
75 minpane
= wx
.GetNumberFromUser(
76 "Enter the minimum pane size",
77 "", "Minimum Pane Size", self
.minpane
,
80 self
.minpane
= minpane
81 self
.sp
.SetMinimumPaneSize(self
.minpane
)
83 def OnSetPos(self
, evt
):
84 initpos
= wx
.GetNumberFromUser(
85 "Enter the initial sash position (to be used in the Split call)",
86 "", "Initial Sash Position", self
.initpos
,
89 self
.initpos
= initpos
92 def OnExit(self
, evt
):
96 app
= wx
.PySimpleApp(redirect
=True)
97 frm
= SplitterExampleFrame(None, "Splitter Example")
98 frm
.SetSize((600,500))
100 app
.SetTopWindow(frm
)