]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | import wx | |
3 | ||
4 | # Importing ScrolledWindow demo to make use of the MyCanvas | |
5 | # class defined within. | |
6 | import ScrolledWindow | |
7 | import images | |
8 | ||
9 | SHOW_BACKGROUND = 1 | |
10 | ||
11 | #---------------------------------------------------------------------- | |
12 | ID_New = wx.NewId() | |
13 | ID_Exit = wx.NewId() | |
14 | #---------------------------------------------------------------------- | |
15 | ||
16 | class MyParentFrame(wx.MDIParentFrame): | |
17 | def __init__(self): | |
18 | wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent", size=(600,400)) | |
19 | ||
20 | self.winCount = 0 | |
21 | menu = wx.Menu() | |
22 | menu.Append(ID_New, "&New Window") | |
23 | menu.AppendSeparator() | |
24 | menu.Append(ID_Exit, "E&xit") | |
25 | ||
26 | menubar = wx.MenuBar() | |
27 | menubar.Append(menu, "&File") | |
28 | self.SetMenuBar(menubar) | |
29 | ||
30 | self.CreateStatusBar() | |
31 | ||
32 | self.Bind(wx.EVT_MENU, self.OnNewWindow, id=ID_New) | |
33 | self.Bind(wx.EVT_MENU, self.OnExit, id=ID_Exit) | |
34 | ||
35 | if SHOW_BACKGROUND: | |
36 | self.bg_bmp = images.getGridBGBitmap() | |
37 | self.GetClientWindow().Bind( | |
38 | wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground | |
39 | ) | |
40 | ||
41 | ||
42 | def OnExit(self, evt): | |
43 | self.Close(True) | |
44 | ||
45 | ||
46 | def OnNewWindow(self, evt): | |
47 | self.winCount = self.winCount + 1 | |
48 | win = wx.MDIChildFrame(self, -1, "Child Window: %d" % self.winCount) | |
49 | canvas = ScrolledWindow.MyCanvas(win) | |
50 | win.Show(True) | |
51 | ||
52 | ||
53 | def OnEraseBackground(self, evt): | |
54 | dc = evt.GetDC() | |
55 | ||
56 | if not dc: | |
57 | dc = wx.ClientDC(self.GetClientWindow()) | |
58 | ||
59 | # tile the background bitmap | |
60 | sz = self.GetClientSize() | |
61 | w = self.bg_bmp.GetWidth() | |
62 | h = self.bg_bmp.GetHeight() | |
63 | x = 0 | |
64 | ||
65 | while x < sz.width: | |
66 | y = 0 | |
67 | ||
68 | while y < sz.height: | |
69 | dc.DrawBitmap(self.bg_bmp, x, y) | |
70 | y = y + h | |
71 | ||
72 | x = x + w | |
73 | ||
74 | ||
75 | #---------------------------------------------------------------------- | |
76 | ||
77 | if __name__ == '__main__': | |
78 | class MyApp(wx.App): | |
79 | def OnInit(self): | |
80 | wx.InitAllImageHandlers() | |
81 | frame = MyParentFrame() | |
82 | frame.Show(True) | |
83 | self.SetTopWindow(frame) | |
84 | return True | |
85 | ||
86 | ||
87 | app = MyApp(False) | |
88 | app.MainLoop() | |
89 | ||
90 | ||
91 |