]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-08/splitter.py
don't use invalid wxIconBundles, it results in asserts after recent changes
[wxWidgets.git] / wxPython / samples / wxPIA_book / Chapter-08 / splitter.py
1 import wx
2
3 class SplitterExampleFrame(wx.Frame):
4 def __init__(self, parent, title):
5 wx.Frame.__init__(self, parent, title=title)
6 self.MakeMenuBar()
7 self.minpane = 0
8 self.initpos = 0
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")
14 self.p1.Hide()
15 self.p2.Hide()
16
17 self.sp.Initialize(self.p1)
18
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)
23
24
25 def MakeMenuBar(self):
26 menu = wx.Menu()
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)
36
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)
42
43 menu.AppendSeparator()
44 item = menu.Append(wx.ID_EXIT, "E&xit")
45 self.Bind(wx.EVT_MENU, self.OnExit, item)
46
47 mbar = wx.MenuBar()
48 mbar.Append(menu, "Splitter")
49 self.SetMenuBar(mbar)
50
51
52 def OnSashChanging(self, evt):
53 print "OnSashChanging:", evt.GetSashPosition()
54
55 def OnSashChanged(self, evt):
56 print "OnSashChanged:", evt.GetSashPosition()
57
58
59 def OnSplitH(self, evt):
60 self.sp.SplitHorizontally(self.p1, self.p2, self.initpos)
61
62 def OnSplitV(self, evt):
63 self.sp.SplitVertically(self.p1, self.p2, self.initpos)
64
65 def OnCheckCanSplit(self, evt):
66 evt.Enable(not self.sp.IsSplit())
67
68 def OnCheckCanUnsplit(self, evt):
69 evt.Enable(self.sp.IsSplit())
70
71 def OnUnsplit(self, evt):
72 self.sp.Unsplit()
73
74 def OnSetMin(self, evt):
75 minpane = wx.GetNumberFromUser(
76 "Enter the minimum pane size",
77 "", "Minimum Pane Size", self.minpane,
78 0, 1000, self)
79 if minpane != -1:
80 self.minpane = minpane
81 self.sp.SetMinimumPaneSize(self.minpane)
82
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,
87 -1000, 1000, self)
88 if initpos != -1:
89 self.initpos = initpos
90
91
92 def OnExit(self, evt):
93 self.Close()
94
95
96 app = wx.PySimpleApp(redirect=True)
97 frm = SplitterExampleFrame(None, "Splitter Example")
98 frm.SetSize((600,500))
99 frm.Show()
100 app.SetTopWindow(frm)
101 app.MainLoop()