]>
Commit | Line | Data |
---|---|---|
8fa876ca RD |
1 | # 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
2 | # | |
3 | # o Updated for wx namespace | |
4 | # o Should be renamed to wxSashLayoutWindow.py | |
5 | # | |
cf694132 | 6 | |
8fa876ca | 7 | import wx |
cf694132 RD |
8 | |
9 | #--------------------------------------------------------------------------- | |
10 | ||
8fa876ca | 11 | class TestSashWindow(wx.Panel): |
cf694132 RD |
12 | ID_WINDOW_TOP = 5100 |
13 | ID_WINDOW_LEFT1 = 5101 | |
14 | ID_WINDOW_LEFT2 = 5102 | |
15 | ID_WINDOW_BOTTOM = 5103 | |
16 | ||
17 | ||
18 | def __init__(self, parent, log): | |
8fa876ca | 19 | wx.Panel.__init__(self, parent, -1) |
cf694132 RD |
20 | |
21 | self.log = log | |
22 | ||
1b62f00d | 23 | # will occupy the space not used by the Layout Algorithm |
8fa876ca | 24 | self.remainingSpace = wx.Panel(self, -1, style=wx.SUNKEN_BORDER) |
de20db99 | 25 | |
8fa876ca RD |
26 | self.Bind( |
27 | wx.EVT_SASH_DRAGGED_RANGE, self.OnSashDrag, | |
28 | id=self.ID_WINDOW_TOP, id2=self.ID_WINDOW_BOTTOM, | |
29 | ) | |
30 | ||
31 | self.Bind(wx.EVT_SIZE, self.OnSize) | |
cf694132 RD |
32 | |
33 | ||
34 | # Create some layout windows | |
35 | # A window like a toolbar | |
8fa876ca RD |
36 | win = wx.SashLayoutWindow( |
37 | self, self.ID_WINDOW_TOP, wx.DefaultPosition, (200, 30), | |
38 | wx.NO_BORDER|wx.SW_3D | |
39 | ) | |
40 | ||
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) | |
cf694132 RD |
46 | |
47 | self.topWindow = win | |
48 | ||
49 | ||
50 | # A window like a statusbar | |
8fa876ca RD |
51 | win = wx.SashLayoutWindow( |
52 | self, self.ID_WINDOW_BOTTOM, wx.DefaultPosition, (200, 30), | |
53 | wx.NO_BORDER|wx.SW_3D | |
54 | ) | |
cf694132 | 55 | |
8fa876ca RD |
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) | |
cf694132 | 61 | |
8fa876ca | 62 | self.bottomWindow = win |
cf694132 RD |
63 | |
64 | # A window to the left of the client window | |
8fa876ca RD |
65 | win = wx.SashLayoutWindow( |
66 | self, self.ID_WINDOW_LEFT1, wx.DefaultPosition, (200, 30), | |
67 | wx.NO_BORDER|wx.SW_3D | |
68 | ) | |
69 | ||
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) | |
cf694132 | 75 | win.SetExtraBorderSize(10) |
8fa876ca RD |
76 | textWindow = wx.TextCtrl( |
77 | win, -1, "", wx.DefaultPosition, wx.DefaultSize, | |
78 | wx.TE_MULTILINE|wx.SUNKEN_BORDER | |
79 | ) | |
80 | ||
de20db99 | 81 | textWindow.SetValue("A sub window") |
cf694132 RD |
82 | |
83 | self.leftWindow1 = win | |
84 | ||
85 | ||
86 | # Another window to the left of the client window | |
8fa876ca RD |
87 | win = wx.SashLayoutWindow( |
88 | self, self.ID_WINDOW_LEFT2, wx.DefaultPosition, (200, 30), | |
89 | wx.NO_BORDER|wx.SW_3D | |
90 | ) | |
91 | ||
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) | |
cf694132 RD |
97 | |
98 | self.leftWindow2 = win | |
99 | ||
100 | ||
101 | def OnSashDrag(self, event): | |
8fa876ca | 102 | if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE: |
cf694132 RD |
103 | return |
104 | ||
105 | eID = event.GetId() | |
8fa876ca | 106 | |
cf694132 | 107 | if eID == self.ID_WINDOW_TOP: |
8fa876ca | 108 | self.topWindow.SetDefaultSize((1000, event.GetDragRect().height)) |
cf694132 RD |
109 | |
110 | elif eID == self.ID_WINDOW_LEFT1: | |
8fa876ca | 111 | self.leftWindow1.SetDefaultSize((event.GetDragRect().width, 1000)) |
cf694132 RD |
112 | |
113 | ||
114 | elif eID == self.ID_WINDOW_LEFT2: | |
8fa876ca | 115 | self.leftWindow2.SetDefaultSize((event.GetDragRect().width, 1000)) |
cf694132 RD |
116 | |
117 | elif eID == self.ID_WINDOW_BOTTOM: | |
8fa876ca | 118 | self.bottomWindow.SetDefaultSize((1000, event.GetDragRect().height)) |
cf694132 | 119 | |
8fa876ca | 120 | wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace) |
de20db99 | 121 | self.remainingSpace.Refresh() |
cf694132 RD |
122 | |
123 | def OnSize(self, event): | |
8fa876ca | 124 | wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace) |
cf694132 RD |
125 | |
126 | #--------------------------------------------------------------------------- | |
127 | ||
128 | def runTest(frame, nb, log): | |
129 | win = TestSashWindow(nb, log) | |
130 | return win | |
131 | ||
132 | #--------------------------------------------------------------------------- | |
133 | ||
134 | ||
1fded56b | 135 | overview = """\ |
8fa876ca RD |
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. | |
cf694132 | 141 | |
8fa876ca RD |
142 | The documentation for wxLayoutAlgorithm explains the purpose of this class |
143 | in more detail. | |
cf694132 | 144 | |
8fa876ca | 145 | """ |
cf694132 RD |
146 | |
147 | ||
1fded56b RD |
148 | if __name__ == '__main__': |
149 | import sys,os | |
150 | import run | |
151 | run.main(['', os.path.basename(sys.argv[0])]) |