~brian-sidebotham/wxwidgets-cmake/wxpython-2.9.4

« back to all changes in this revision

Viewing changes to wxPython/demo/MDIDemo.py

  • Committer: Brian Sidebotham
  • Date: 2013-08-03 14:30:08 UTC
  • Revision ID: brian.sidebotham@gmail.com-20130803143008-c7806tkych1tp6fc
Initial import into Bazaar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.GridBG.GetBitmap()
 
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
        # tile the background bitmap
 
57
        sz = self.GetClientSize()
 
58
        w = self.bg_bmp.GetWidth()
 
59
        h = self.bg_bmp.GetHeight()
 
60
        x = 0
 
61
        
 
62
        while x < sz.width:
 
63
            y = 0
 
64
 
 
65
            while y < sz.height:
 
66
                dc.DrawBitmap(self.bg_bmp, x, y)
 
67
                y = y + h
 
68
 
 
69
            x = x + w
 
70
 
 
71
 
 
72
#----------------------------------------------------------------------
 
73
 
 
74
if __name__ == '__main__':
 
75
    class MyApp(wx.App):
 
76
        def OnInit(self):
 
77
            wx.InitAllImageHandlers()
 
78
            frame = MyParentFrame()
 
79
            frame.Show(True)
 
80
            self.SetTopWindow(frame)
 
81
            return True
 
82
 
 
83
 
 
84
    app = MyApp(False)
 
85
    app.MainLoop()
 
86
 
 
87
 
 
88