]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/SashWindow.py
add support for wxCONTROL_ISDEFAULT to wxRendererMSW::DrawPushButton() (modified...
[wxWidgets.git] / wxPython / demo / SashWindow.py
CommitLineData
cf694132 1
8fa876ca 2import wx
cf694132
RD
3
4#---------------------------------------------------------------------------
5
8fa876ca 6class TestSashWindow(wx.Panel):
cf694132
RD
7
8 def __init__(self, parent, log):
8fa876ca 9 wx.Panel.__init__(self, parent, -1)
cf694132
RD
10
11 self.log = log
6f016d54 12 winids = []
cf694132
RD
13
14 # Create some layout windows
15 # A window like a toolbar
6f016d54
RD
16 topwin = wx.SashLayoutWindow(
17 self, -1, wx.DefaultPosition, (200, 30),
8fa876ca
RD
18 wx.NO_BORDER|wx.SW_3D
19 )
20
6f016d54
RD
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)
cf694132 26
6f016d54
RD
27 self.topWindow = topwin
28 winids.append(topwin.GetId())
cf694132
RD
29
30 # A window like a statusbar
6f016d54
RD
31 bottomwin = wx.SashLayoutWindow(
32 self, -1, wx.DefaultPosition, (200, 30),
8fa876ca
RD
33 wx.NO_BORDER|wx.SW_3D
34 )
cf694132 35
6f016d54
RD
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)
cf694132 41
6f016d54
RD
42 self.bottomWindow = bottomwin
43 winids.append(bottomwin.GetId())
cf694132
RD
44
45 # A window to the left of the client window
6f016d54
RD
46 leftwin1 = wx.SashLayoutWindow(
47 self, -1, wx.DefaultPosition, (200, 30),
8fa876ca
RD
48 wx.NO_BORDER|wx.SW_3D
49 )
50
6f016d54
RD
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)
8fa876ca 57 textWindow = wx.TextCtrl(
6f016d54 58 leftwin1, -1, "", wx.DefaultPosition, wx.DefaultSize,
8fa876ca
RD
59 wx.TE_MULTILINE|wx.SUNKEN_BORDER
60 )
61
de20db99 62 textWindow.SetValue("A sub window")
cf694132 63
6f016d54
RD
64 self.leftWindow1 = leftwin1
65 winids.append(leftwin1.GetId())
cf694132
RD
66
67
68 # Another window to the left of the client window
6f016d54
RD
69 leftwin2 = wx.SashLayoutWindow(
70 self, -1, wx.DefaultPosition, (200, 30),
8fa876ca
RD
71 wx.NO_BORDER|wx.SW_3D
72 )
73
6f016d54
RD
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 )
cf694132 90
6f016d54 91 self.Bind(wx.EVT_SIZE, self.OnSize)
cf694132
RD
92
93
94 def OnSashDrag(self, event):
8fa876ca 95 if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE:
6f016d54 96 self.log.write('drag is out of range')
cf694132
RD
97 return
98
6f016d54 99 eobj = event.GetEventObject()
8fa876ca 100
6f016d54
RD
101 if eobj is self.topWindow:
102 self.log.write('topwin received drag event')
8fa876ca 103 self.topWindow.SetDefaultSize((1000, event.GetDragRect().height))
cf694132 104
6f016d54
RD
105 elif eobj is self.leftWindow1:
106 self.log.write('leftwin1 received drag event')
8fa876ca 107 self.leftWindow1.SetDefaultSize((event.GetDragRect().width, 1000))
cf694132
RD
108
109
6f016d54
RD
110 elif eobj is self.leftWindow2:
111 self.log.write('leftwin2 received drag event')
8fa876ca 112 self.leftWindow2.SetDefaultSize((event.GetDragRect().width, 1000))
cf694132 113
6f016d54
RD
114 elif eobj is self.bottomWindow:
115 self.log.write('bottomwin received drag event')
8fa876ca 116 self.bottomWindow.SetDefaultSize((1000, event.GetDragRect().height))
cf694132 117
8fa876ca 118 wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
de20db99 119 self.remainingSpace.Refresh()
cf694132
RD
120
121 def OnSize(self, event):
8fa876ca 122 wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
cf694132
RD
123
124#---------------------------------------------------------------------------
125
126def runTest(frame, nb, log):
127 win = TestSashWindow(nb, log)
128 return win
129
130#---------------------------------------------------------------------------
131
132
1fded56b 133overview = """\
95bfd958 134wx.SashLayoutWindow responds to OnCalculateLayout events generated by
8fa876ca
RD
135wxLayoutAlgorithm. It allows the application to use simple accessors to
136specify how the window should be laid out, rather than having to respond
95bfd958 137to events. The fact that the class derives from wx.SashWindow allows sashes
8fa876ca 138to be used if required, to allow the windows to be user-resizable.
cf694132 139
95bfd958 140The documentation for wx.LayoutAlgorithm explains the purpose of this class
8fa876ca 141in more detail.
cf694132 142
8fa876ca 143"""
cf694132
RD
144
145
1fded56b
RD
146if __name__ == '__main__':
147 import sys,os
148 import run
8eca4fef 149 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])