]>
Commit | Line | Data |
---|---|---|
de20db99 RD |
1 | #!/usr/bin/env python |
2 | ||
8fa876ca RD |
3 | # 11/6/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
4 | # | |
5 | # o Updated for wx namespace | |
6 | # | |
7 | ||
8 | import wx | |
9 | ||
10 | import wxScrolledWindow | |
de20db99 RD |
11 | |
12 | #---------------------------------------------------------------------- | |
8fa876ca RD |
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. | |
de20db99 | 16 | |
8fa876ca RD |
17 | ID_Menu_New = 5004 |
18 | ID_Menu_Exit = 5005 | |
de20db99 | 19 | |
8fa876ca RD |
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): | |
de20db99 | 28 | def __init__(self): |
8fa876ca RD |
29 | wx.MDIParentFrame.__init__( |
30 | self, None, -1, "MDI Parent", size=(600,400), | |
31 | style = wx.DEFAULT_FRAME_STYLE | wx.HSCROLL | wx.VSCROLL | |
32 | ) | |
de20db99 RD |
33 | |
34 | self.winCount = 0 | |
8fa876ca RD |
35 | menu = wx.Menu() |
36 | menu.Append(ID_Menu_New, "&New Window") | |
de20db99 | 37 | menu.AppendSeparator() |
8fa876ca | 38 | menu.Append(ID_Menu_Exit, "E&xit") |
de20db99 | 39 | |
8fa876ca | 40 | menubar = wx.MenuBar() |
de20db99 RD |
41 | menubar.Append(menu, "&File") |
42 | self.SetMenuBar(menubar) | |
43 | ||
44 | #self.CreateStatusBar() | |
45 | ||
8fa876ca RD |
46 | self.Bind(wx.EVT_MENU, self.OnNewWindow, id=ID_Menu_New) |
47 | self.Bind(wx.EVT_MENU, self.OnExit, id=ID_Menu_Exit) | |
de20db99 | 48 | |
8fa876ca RD |
49 | self.Bind( |
50 | wx.EVT_SASH_DRAGGED_RANGE, self.OnSashDrag, id=ID_WINDOW_TOP, | |
51 | id2=ID_WINDOW_BOTTOM | |
52 | ) | |
de20db99 | 53 | |
8fa876ca | 54 | self.Bind(wx.EVT_SIZE, self.OnSize) |
de20db99 RD |
55 | |
56 | ||
57 | # Create some layout windows | |
58 | # A window like a toolbar | |
8fa876ca | 59 | win = wx.SashLayoutWindow(self, ID_WINDOW_TOP, style=wx.NO_BORDER|wx.SW_3D) |
de20db99 | 60 | win.SetDefaultSize((1000, 30)) |
8fa876ca RD |
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) | |
de20db99 RD |
65 | |
66 | self.topWindow = win | |
67 | ||
68 | ||
69 | # A window like a statusbar | |
8fa876ca | 70 | win = wx.SashLayoutWindow(self, ID_WINDOW_BOTTOM, style=wx.NO_BORDER|wx.SW_3D) |
de20db99 | 71 | win.SetDefaultSize((1000, 30)) |
8fa876ca RD |
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) | |
de20db99 RD |
76 | |
77 | self.bottomWindow = win | |
78 | ||
79 | ||
80 | # A window to the left of the client window | |
8fa876ca | 81 | win = wx.SashLayoutWindow(self, ID_WINDOW_LEFT1, style=wx.NO_BORDER|wx.SW_3D) |
de20db99 | 82 | win.SetDefaultSize((120, 1000)) |
8fa876ca RD |
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) | |
de20db99 | 87 | win.SetExtraBorderSize(10) |
8fa876ca | 88 | textWindow = wx.TextCtrl(win, -1, "", style=wx.TE_MULTILINE|wx.SUNKEN_BORDER) |
de20db99 RD |
89 | textWindow.SetValue("A sub window") |
90 | ||
91 | self.leftWindow1 = win | |
92 | ||
93 | ||
94 | # Another window to the left of the client window | |
8fa876ca | 95 | win = wx.SashLayoutWindow(self, ID_WINDOW_LEFT2, style=wx.NO_BORDER|wx.SW_3D) |
de20db99 | 96 | win.SetDefaultSize((120, 1000)) |
8fa876ca RD |
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) | |
de20db99 RD |
101 | |
102 | self.leftWindow2 = win | |
103 | ||
104 | ||
105 | def OnSashDrag(self, event): | |
8fa876ca | 106 | if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE: |
de20db99 RD |
107 | return |
108 | ||
109 | eID = event.GetId() | |
8fa876ca RD |
110 | |
111 | if eID == ID_WINDOW_TOP: | |
112 | self.topWindow.SetDefaultSize((1000, event.GetDragRect().height)) | |
de20db99 | 113 | |
8fa876ca RD |
114 | elif eID == ID_WINDOW_LEFT1: |
115 | self.leftWindow1.SetDefaultSize((event.GetDragRect().width, 1000)) | |
de20db99 | 116 | |
8fa876ca RD |
117 | elif eID == ID_WINDOW_LEFT2: |
118 | self.leftWindow2.SetDefaultSize((event.GetDragRect().width, 1000)) | |
de20db99 | 119 | |
8fa876ca RD |
120 | elif eID == ID_WINDOW_BOTTOM: |
121 | self.bottomWindow.SetDefaultSize((1000, event.GetDragRect().height)) | |
de20db99 | 122 | |
8fa876ca | 123 | wx.LayoutAlgorithm().LayoutMDIFrame(self) |
de20db99 RD |
124 | self.GetClientWindow().Refresh() |
125 | ||
126 | ||
127 | def OnSize(self, event): | |
8fa876ca | 128 | wx.LayoutAlgorithm().LayoutMDIFrame(self) |
de20db99 RD |
129 | |
130 | ||
131 | def OnExit(self, evt): | |
1e4a197e | 132 | self.Close(True) |
de20db99 RD |
133 | |
134 | ||
135 | def OnNewWindow(self, evt): | |
136 | self.winCount = self.winCount + 1 | |
8fa876ca RD |
137 | win = wx.MDIChildFrame(self, -1, "Child Window: %d" % self.winCount) |
138 | canvas = wxScrolledWindow.MyCanvas(win) | |
1e4a197e | 139 | win.Show(True) |
de20db99 RD |
140 | |
141 | ||
142 | #---------------------------------------------------------------------- | |
143 | ||
9c67cbec | 144 | if __name__ == '__main__': |
8fa876ca | 145 | class MyApp(wx.App): |
9c67cbec | 146 | def OnInit(self): |
8fa876ca | 147 | wx.InitAllImageHandlers() |
9c67cbec | 148 | frame = MyParentFrame() |
1e4a197e | 149 | frame.Show(True) |
9c67cbec | 150 | self.SetTopWindow(frame) |
1e4a197e | 151 | return True |
de20db99 | 152 | |
8fa876ca | 153 | app = MyApp(False) |
9c67cbec | 154 | app.MainLoop() |
de20db99 RD |
155 | |
156 | ||
157 |