]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxSashWindow.py
1 # 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o Updated for wx namespace
4 # o Should be renamed to wxSashLayoutWindow.py
9 #---------------------------------------------------------------------------
11 class TestSashWindow(wx
.Panel
):
13 ID_WINDOW_LEFT1
= 5101
14 ID_WINDOW_LEFT2
= 5102
15 ID_WINDOW_BOTTOM
= 5103
18 def __init__(self
, parent
, log
):
19 wx
.Panel
.__init
__(self
, parent
, -1)
23 # will occupy the space not used by the Layout Algorithm
24 self
.remainingSpace
= wx
.Panel(self
, -1, style
=wx
.SUNKEN_BORDER
)
27 wx
.EVT_SASH_DRAGGED_RANGE
, self
.OnSashDrag
,
28 id=self
.ID_WINDOW_TOP
, id2
=self
.ID_WINDOW_BOTTOM
,
31 self
.Bind(wx
.EVT_SIZE
, self
.OnSize
)
34 # Create some layout windows
35 # A window like a toolbar
36 win
= wx
.SashLayoutWindow(
37 self
, self
.ID_WINDOW_TOP
, wx
.DefaultPosition
, (200, 30),
41 win
.SetDefaultSize((1000, 30))
42 win
.SetOrientation(wx
.LAYOUT_HORIZONTAL
)
43 win
.SetAlignment(wx
.LAYOUT_TOP
)
44 win
.SetBackgroundColour(wx
.Colour(255, 0, 0))
45 win
.SetSashVisible(wx
.SASH_BOTTOM
, True)
50 # A window like a statusbar
51 win
= wx
.SashLayoutWindow(
52 self
, self
.ID_WINDOW_BOTTOM
, wx
.DefaultPosition
, (200, 30),
56 win
.SetDefaultSize((1000, 30))
57 win
.SetOrientation(wx
.LAYOUT_HORIZONTAL
)
58 win
.SetAlignment(wx
.LAYOUT_BOTTOM
)
59 win
.SetBackgroundColour(wx
.Colour(0, 0, 255))
60 win
.SetSashVisible(wx
.SASH_TOP
, True)
62 self
.bottomWindow
= win
64 # A window to the left of the client window
65 win
= wx
.SashLayoutWindow(
66 self
, self
.ID_WINDOW_LEFT1
, wx
.DefaultPosition
, (200, 30),
70 win
.SetDefaultSize((120, 1000))
71 win
.SetOrientation(wx
.LAYOUT_VERTICAL
)
72 win
.SetAlignment(wx
.LAYOUT_LEFT
)
73 win
.SetBackgroundColour(wx
.Colour(0, 255, 0))
74 win
.SetSashVisible(wx
.SASH_RIGHT
, True)
75 win
.SetExtraBorderSize(10)
76 textWindow
= wx
.TextCtrl(
77 win
, -1, "", wx
.DefaultPosition
, wx
.DefaultSize
,
78 wx
.TE_MULTILINE|wx
.SUNKEN_BORDER
81 textWindow
.SetValue("A sub window")
83 self
.leftWindow1
= win
86 # Another window to the left of the client window
87 win
= wx
.SashLayoutWindow(
88 self
, self
.ID_WINDOW_LEFT2
, wx
.DefaultPosition
, (200, 30),
92 win
.SetDefaultSize((120, 1000))
93 win
.SetOrientation(wx
.LAYOUT_VERTICAL
)
94 win
.SetAlignment(wx
.LAYOUT_LEFT
)
95 win
.SetBackgroundColour(wx
.Colour(0, 255, 255))
96 win
.SetSashVisible(wx
.SASH_RIGHT
, True)
98 self
.leftWindow2
= win
101 def OnSashDrag(self
, event
):
102 if event
.GetDragStatus() == wx
.SASH_STATUS_OUT_OF_RANGE
:
107 if eID
== self
.ID_WINDOW_TOP
:
108 self
.topWindow
.SetDefaultSize((1000, event
.GetDragRect().height
))
110 elif eID
== self
.ID_WINDOW_LEFT1
:
111 self
.leftWindow1
.SetDefaultSize((event
.GetDragRect().width
, 1000))
114 elif eID
== self
.ID_WINDOW_LEFT2
:
115 self
.leftWindow2
.SetDefaultSize((event
.GetDragRect().width
, 1000))
117 elif eID
== self
.ID_WINDOW_BOTTOM
:
118 self
.bottomWindow
.SetDefaultSize((1000, event
.GetDragRect().height
))
120 wx
.LayoutAlgorithm().LayoutWindow(self
, self
.remainingSpace
)
121 self
.remainingSpace
.Refresh()
123 def OnSize(self
, event
):
124 wx
.LayoutAlgorithm().LayoutWindow(self
, self
.remainingSpace
)
126 #---------------------------------------------------------------------------
128 def runTest(frame
, nb
, log
):
129 win
= TestSashWindow(nb
, log
)
132 #---------------------------------------------------------------------------
136 wxSashLayoutWindow responds to OnCalculateLayout events generated by
137 wxLayoutAlgorithm. It allows the application to use simple accessors to
138 specify how the window should be laid out, rather than having to respond
139 to events. The fact that the class derives from wxSashWindow allows sashes
140 to be used if required, to allow the windows to be user-resizable.
142 The documentation for wxLayoutAlgorithm explains the purpose of this class
148 if __name__
== '__main__':
151 run
.main(['', os
.path
.basename(sys
.argv
[0])])