]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/SashWindow.py
Ensure that runTest is not modal, even when a required module is not
[wxWidgets.git] / wxPython / demo / SashWindow.py
1
2 import wx
3
4 #---------------------------------------------------------------------------
5
6 class TestSashWindow(wx.Panel):
7 ID_WINDOW_TOP = 5100
8 ID_WINDOW_LEFT1 = 5101
9 ID_WINDOW_LEFT2 = 5102
10 ID_WINDOW_BOTTOM = 5103
11
12
13 def __init__(self, parent, log):
14 wx.Panel.__init__(self, parent, -1)
15
16 self.log = log
17
18 # will occupy the space not used by the Layout Algorithm
19 self.remainingSpace = wx.Panel(self, -1, style=wx.SUNKEN_BORDER)
20
21 self.Bind(
22 wx.EVT_SASH_DRAGGED_RANGE, self.OnSashDrag,
23 id=self.ID_WINDOW_TOP, id2=self.ID_WINDOW_BOTTOM,
24 )
25
26 self.Bind(wx.EVT_SIZE, self.OnSize)
27
28
29 # Create some layout windows
30 # A window like a toolbar
31 win = wx.SashLayoutWindow(
32 self, self.ID_WINDOW_TOP, wx.DefaultPosition, (200, 30),
33 wx.NO_BORDER|wx.SW_3D
34 )
35
36 win.SetDefaultSize((1000, 30))
37 win.SetOrientation(wx.LAYOUT_HORIZONTAL)
38 win.SetAlignment(wx.LAYOUT_TOP)
39 win.SetBackgroundColour(wx.Colour(255, 0, 0))
40 win.SetSashVisible(wx.SASH_BOTTOM, True)
41
42 self.topWindow = win
43
44
45 # A window like a statusbar
46 win = wx.SashLayoutWindow(
47 self, self.ID_WINDOW_BOTTOM, wx.DefaultPosition, (200, 30),
48 wx.NO_BORDER|wx.SW_3D
49 )
50
51 win.SetDefaultSize((1000, 30))
52 win.SetOrientation(wx.LAYOUT_HORIZONTAL)
53 win.SetAlignment(wx.LAYOUT_BOTTOM)
54 win.SetBackgroundColour(wx.Colour(0, 0, 255))
55 win.SetSashVisible(wx.SASH_TOP, True)
56
57 self.bottomWindow = win
58
59 # A window to the left of the client window
60 win = wx.SashLayoutWindow(
61 self, self.ID_WINDOW_LEFT1, wx.DefaultPosition, (200, 30),
62 wx.NO_BORDER|wx.SW_3D
63 )
64
65 win.SetDefaultSize((120, 1000))
66 win.SetOrientation(wx.LAYOUT_VERTICAL)
67 win.SetAlignment(wx.LAYOUT_LEFT)
68 win.SetBackgroundColour(wx.Colour(0, 255, 0))
69 win.SetSashVisible(wx.SASH_RIGHT, True)
70 win.SetExtraBorderSize(10)
71 textWindow = wx.TextCtrl(
72 win, -1, "", wx.DefaultPosition, wx.DefaultSize,
73 wx.TE_MULTILINE|wx.SUNKEN_BORDER
74 )
75
76 textWindow.SetValue("A sub window")
77
78 self.leftWindow1 = win
79
80
81 # Another window to the left of the client window
82 win = wx.SashLayoutWindow(
83 self, self.ID_WINDOW_LEFT2, wx.DefaultPosition, (200, 30),
84 wx.NO_BORDER|wx.SW_3D
85 )
86
87 win.SetDefaultSize((120, 1000))
88 win.SetOrientation(wx.LAYOUT_VERTICAL)
89 win.SetAlignment(wx.LAYOUT_LEFT)
90 win.SetBackgroundColour(wx.Colour(0, 255, 255))
91 win.SetSashVisible(wx.SASH_RIGHT, True)
92
93 self.leftWindow2 = win
94
95
96 def OnSashDrag(self, event):
97 if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE:
98 return
99
100 eID = event.GetId()
101
102 if eID == self.ID_WINDOW_TOP:
103 self.topWindow.SetDefaultSize((1000, event.GetDragRect().height))
104
105 elif eID == self.ID_WINDOW_LEFT1:
106 self.leftWindow1.SetDefaultSize((event.GetDragRect().width, 1000))
107
108
109 elif eID == self.ID_WINDOW_LEFT2:
110 self.leftWindow2.SetDefaultSize((event.GetDragRect().width, 1000))
111
112 elif eID == self.ID_WINDOW_BOTTOM:
113 self.bottomWindow.SetDefaultSize((1000, event.GetDragRect().height))
114
115 wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
116 self.remainingSpace.Refresh()
117
118 def OnSize(self, event):
119 wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
120
121 #---------------------------------------------------------------------------
122
123 def runTest(frame, nb, log):
124 win = TestSashWindow(nb, log)
125 return win
126
127 #---------------------------------------------------------------------------
128
129
130 overview = """\
131 wx.SashLayoutWindow responds to OnCalculateLayout events generated by
132 wxLayoutAlgorithm. It allows the application to use simple accessors to
133 specify how the window should be laid out, rather than having to respond
134 to events. The fact that the class derives from wx.SashWindow allows sashes
135 to be used if required, to allow the windows to be user-resizable.
136
137 The documentation for wx.LayoutAlgorithm explains the purpose of this class
138 in more detail.
139
140 """
141
142
143 if __name__ == '__main__':
144 import sys,os
145 import run
146 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])