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