]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/MDISashDemo.py
fix test code
[wxWidgets.git] / wxPython / demo / MDISashDemo.py
1 #!/usr/bin/env python
2
3 import wx
4
5 import ScrolledWindow
6
7 #----------------------------------------------------------------------
8 # There are better ways to do IDs, but this demo requires that the window
9 # IDs be in a specific range. There are better ways to do that, too, but
10 # this will do for purposes of this demo.
11
12 ID_Menu_New = 5004
13 ID_Menu_Exit = 5005
14
15 ID_WINDOW_TOP = 5000
16 ID_WINDOW_LEFT1 = 5001
17 ID_WINDOW_LEFT2 = 5002
18 ID_WINDOW_BOTTOM = 5003
19
20 #----------------------------------------------------------------------
21
22 class MyParentFrame(wx.MDIParentFrame):
23 def __init__(self):
24 wx.MDIParentFrame.__init__(
25 self, None, -1, "MDI Parent", size=(600,400),
26 style = wx.DEFAULT_FRAME_STYLE | wx.HSCROLL | wx.VSCROLL
27 )
28
29 self.winCount = 0
30 menu = wx.Menu()
31 menu.Append(ID_Menu_New, "&New Window")
32 menu.AppendSeparator()
33 menu.Append(ID_Menu_Exit, "E&xit")
34
35 menubar = wx.MenuBar()
36 menubar.Append(menu, "&File")
37 self.SetMenuBar(menubar)
38
39 #self.CreateStatusBar()
40
41 self.Bind(wx.EVT_MENU, self.OnNewWindow, id=ID_Menu_New)
42 self.Bind(wx.EVT_MENU, self.OnExit, id=ID_Menu_Exit)
43
44 self.Bind(
45 wx.EVT_SASH_DRAGGED_RANGE, self.OnSashDrag, id=ID_WINDOW_TOP,
46 id2=ID_WINDOW_BOTTOM
47 )
48
49 self.Bind(wx.EVT_SIZE, self.OnSize)
50
51
52 # Create some layout windows
53 # A window like a toolbar
54 win = wx.SashLayoutWindow(self, ID_WINDOW_TOP, style=wx.NO_BORDER|wx.SW_3D)
55 win.SetDefaultSize((1000, 30))
56 win.SetOrientation(wx.LAYOUT_HORIZONTAL)
57 win.SetAlignment(wx.LAYOUT_TOP)
58 win.SetBackgroundColour(wx.Colour(255, 0, 0))
59 win.SetSashVisible(wx.SASH_BOTTOM, True)
60
61 self.topWindow = win
62
63
64 # A window like a statusbar
65 win = wx.SashLayoutWindow(self, ID_WINDOW_BOTTOM, style=wx.NO_BORDER|wx.SW_3D)
66 win.SetDefaultSize((1000, 30))
67 win.SetOrientation(wx.LAYOUT_HORIZONTAL)
68 win.SetAlignment(wx.LAYOUT_BOTTOM)
69 win.SetBackgroundColour(wx.Colour(0, 0, 255))
70 win.SetSashVisible(wx.SASH_TOP, True)
71
72 self.bottomWindow = win
73
74
75 # A window to the left of the client window
76 win = wx.SashLayoutWindow(self, ID_WINDOW_LEFT1, style=wx.NO_BORDER|wx.SW_3D)
77 win.SetDefaultSize((120, 1000))
78 win.SetOrientation(wx.LAYOUT_VERTICAL)
79 win.SetAlignment(wx.LAYOUT_LEFT)
80 win.SetBackgroundColour(wx.Colour(0, 255, 0))
81 win.SetSashVisible(wx.SASH_RIGHT, True)
82 win.SetExtraBorderSize(10)
83 textWindow = wx.TextCtrl(win, -1, "", style=wx.TE_MULTILINE|wx.SUNKEN_BORDER)
84 textWindow.SetValue("A sub window")
85
86 self.leftWindow1 = win
87
88
89 # Another window to the left of the client window
90 win = wx.SashLayoutWindow(self, ID_WINDOW_LEFT2, style=wx.NO_BORDER|wx.SW_3D)
91 win.SetDefaultSize((120, 1000))
92 win.SetOrientation(wx.LAYOUT_VERTICAL)
93 win.SetAlignment(wx.LAYOUT_LEFT)
94 win.SetBackgroundColour(wx.Colour(0, 255, 255))
95 win.SetSashVisible(wx.SASH_RIGHT, True)
96
97 self.leftWindow2 = win
98
99
100 def OnSashDrag(self, event):
101 if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE:
102 return
103
104 eID = event.GetId()
105
106 if eID == ID_WINDOW_TOP:
107 self.topWindow.SetDefaultSize((1000, event.GetDragRect().height))
108
109 elif eID == ID_WINDOW_LEFT1:
110 self.leftWindow1.SetDefaultSize((event.GetDragRect().width, 1000))
111
112 elif eID == ID_WINDOW_LEFT2:
113 self.leftWindow2.SetDefaultSize((event.GetDragRect().width, 1000))
114
115 elif eID == ID_WINDOW_BOTTOM:
116 self.bottomWindow.SetDefaultSize((1000, event.GetDragRect().height))
117
118 wx.LayoutAlgorithm().LayoutMDIFrame(self)
119 self.GetClientWindow().Refresh()
120
121
122 def OnSize(self, event):
123 wx.LayoutAlgorithm().LayoutMDIFrame(self)
124
125
126 def OnExit(self, evt):
127 self.Close(True)
128
129
130 def OnNewWindow(self, evt):
131 self.winCount = self.winCount + 1
132 win = wx.MDIChildFrame(self, -1, "Child Window: %d" % self.winCount)
133 canvas = ScrolledWindow.MyCanvas(win)
134 win.Show(True)
135
136
137 #----------------------------------------------------------------------
138
139 if __name__ == '__main__':
140 class MyApp(wx.App):
141 def OnInit(self):
142 wx.InitAllImageHandlers()
143 frame = MyParentFrame()
144 frame.Show(True)
145 self.SetTopWindow(frame)
146 return True
147
148 app = MyApp(False)
149 app.MainLoop()
150
151
152