|
2 | 2 |
|
3 | 3 | import platform |
4 | 4 | if platform.architecture()[0] != "32bit": |
5 | | - raise Exception("Architecture not supported: %s" % platform.architecture()[0]) |
| 5 | + raise Exception("Architecture not supported: %s" % ( |
| 6 | + platform.architecture()[0])) |
6 | 7 |
|
7 | 8 | import sys |
8 | 9 | if sys.hexversion >= 0x02070000 and sys.hexversion < 0x03000000: |
|
15 | 16 | import wx |
16 | 17 |
|
17 | 18 | class MainFrame(wx.Frame): |
18 | | - |
19 | 19 | browser = None |
20 | 20 |
|
21 | 21 | def __init__(self): |
22 | | - |
23 | | - wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, title='wxPython example', size=(600,400)) |
| 22 | + wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, |
| 23 | + title='wxPython example', size=(600,400)) |
24 | 24 | self.CreateMenu() |
| 25 | + |
25 | 26 | windowInfo = cefpython.WindowInfo() |
26 | 27 | windowInfo.SetAsChild(self.GetHandle()) |
27 | | - self.browser = cefpython.CreateBrowserSync(windowInfo, browserSettings={}, navigateURL="cefsimple.html") |
| 28 | + self.browser = cefpython.CreateBrowserSync(windowInfo, |
| 29 | + browserSettings={}, navigateURL="cefsimple.html") |
28 | 30 |
|
29 | 31 | self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) |
30 | 32 | self.Bind(wx.EVT_SIZE, self.OnSize) |
31 | 33 | self.Bind(wx.EVT_CLOSE, self.OnClose) |
32 | | - """self.Bind(wx.EVT_IDLE, self.OnIdle)""" |
| 34 | + self.Bind(wx.EVT_IDLE, self.OnIdle) |
33 | 35 |
|
34 | 36 | def CreateMenu(self): |
35 | | - |
36 | 37 | filemenu = wx.Menu() |
37 | 38 | filemenu.Append(1, "Open") |
38 | 39 | filemenu.Append(2, "Exit") |
39 | | - |
40 | 40 | aboutmenu = wx.Menu() |
41 | 41 | aboutmenu.Append(1, "CEF Python") |
42 | | - |
43 | 42 | menubar = wx.MenuBar() |
44 | 43 | menubar.Append(filemenu,"&File") |
45 | 44 | menubar.Append(aboutmenu, "&About") |
46 | | - |
47 | 45 | self.SetMenuBar(menubar) |
48 | 46 |
|
49 | 47 | def OnSetFocus(self, event): |
50 | | - |
51 | 48 | cefpython.WindowUtils.OnSetFocus(self.GetHandle(), 0, 0, 0) |
52 | 49 |
|
53 | 50 | def OnSize(self, event): |
54 | | - |
55 | 51 | cefpython.WindowUtils.OnSize(self.GetHandle(), 0, 0, 0) |
56 | 52 |
|
57 | 53 | def OnClose(self, event): |
58 | | - |
59 | 54 | self.browser.CloseBrowser() |
60 | 55 | self.Destroy() |
61 | 56 |
|
62 | | - """def OnIdle(self, event): |
63 | | - cefpython.SingleMessageLoop()""" |
| 57 | + def OnIdle(self, event): |
| 58 | + cefpython.SingleMessageLoop() |
64 | 59 |
|
65 | 60 | class MyApp(wx.App): |
66 | 61 |
|
67 | | - timer = None |
68 | | - timerID = 1 |
69 | | - |
70 | 62 | def OnInit(self): |
71 | | - |
72 | | - self.CreateTimer() |
73 | 63 | frame = MainFrame() |
74 | 64 | self.SetTopWindow(frame) |
75 | 65 | frame.Show() |
76 | 66 | return True |
77 | 67 |
|
78 | | - def CreateTimer(self): |
79 | | - |
80 | | - # See "Making a render loop": http://wiki.wxwidgets.org/Making_a_render_loop |
81 | | - # Another approach is to use EVT_IDLE in MainFrame, see which one fits you better. |
82 | | - self.timer = wx.Timer(self, self.timerID) |
83 | | - self.timer.Start(10) # 10ms |
84 | | - wx.EVT_TIMER(self, self.timerID, self.OnTimer) |
85 | | - |
86 | | - def OnTimer(self, event): |
87 | | - |
88 | | - cefpython.SingleMessageLoop() |
89 | | - |
90 | | - def OnExit(self): |
91 | | - |
92 | | - # When app.MainLoop() returns, SingleMessageLoop() should not be called anymore. |
93 | | - self.timer.Stop() |
94 | | - |
95 | 68 | if __name__ == '__main__': |
96 | | - |
97 | 69 | sys.excepthook = cefpython.ExceptHook |
98 | 70 | settings = { |
99 | 71 | # Change to LOGSEVERITY_INFO if you want less debug output. |
100 | 72 | "log_severity": cefpython.LOGSEVERITY_VERBOSE, |
101 | 73 | "release_dcheck_enabled": True |
102 | 74 | } |
103 | | - cefpython.Initialize(settings) # Initialize cefpython before wx. |
| 75 | + cefpython.Initialize(settings) |
104 | 76 |
|
105 | 77 | print('wx.version=%s' % wx.version()) |
106 | 78 | app = MyApp(False) |
|
0 commit comments