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