Skip to content

Commit c92b13b

Browse files
committed
Updated wxpython.py example to use EVT_IDLE instead
of timer to do message loop work.
1 parent 5c66015 commit c92b13b

2 files changed

Lines changed: 11 additions & 40 deletions

File tree

cefpython/cef1/windows/binaries/panda3d_.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# This will enable your copy of python to find the panda libraries.
1616

1717
# TODO: fix the blurriness of the browser when window is resized.
18-
# TODO: add keyboard handlers.
1918

2019
import platform
2120
if platform.architecture()[0] != "32bit":

cefpython/cef1/windows/binaries/wxpython.py

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import platform
44
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]))
67

78
import sys
89
if sys.hexversion >= 0x02070000 and sys.hexversion < 0x03000000:
@@ -15,92 +16,63 @@
1516
import wx
1617

1718
class MainFrame(wx.Frame):
18-
1919
browser = None
2020

2121
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))
2424
self.CreateMenu()
25+
2526
windowInfo = cefpython.WindowInfo()
2627
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")
2830

2931
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
3032
self.Bind(wx.EVT_SIZE, self.OnSize)
3133
self.Bind(wx.EVT_CLOSE, self.OnClose)
32-
"""self.Bind(wx.EVT_IDLE, self.OnIdle)"""
34+
self.Bind(wx.EVT_IDLE, self.OnIdle)
3335

3436
def CreateMenu(self):
35-
3637
filemenu = wx.Menu()
3738
filemenu.Append(1, "Open")
3839
filemenu.Append(2, "Exit")
39-
4040
aboutmenu = wx.Menu()
4141
aboutmenu.Append(1, "CEF Python")
42-
4342
menubar = wx.MenuBar()
4443
menubar.Append(filemenu,"&File")
4544
menubar.Append(aboutmenu, "&About")
46-
4745
self.SetMenuBar(menubar)
4846

4947
def OnSetFocus(self, event):
50-
5148
cefpython.WindowUtils.OnSetFocus(self.GetHandle(), 0, 0, 0)
5249

5350
def OnSize(self, event):
54-
5551
cefpython.WindowUtils.OnSize(self.GetHandle(), 0, 0, 0)
5652

5753
def OnClose(self, event):
58-
5954
self.browser.CloseBrowser()
6055
self.Destroy()
6156

62-
"""def OnIdle(self, event):
63-
cefpython.SingleMessageLoop()"""
57+
def OnIdle(self, event):
58+
cefpython.SingleMessageLoop()
6459

6560
class MyApp(wx.App):
6661

67-
timer = None
68-
timerID = 1
69-
7062
def OnInit(self):
71-
72-
self.CreateTimer()
7363
frame = MainFrame()
7464
self.SetTopWindow(frame)
7565
frame.Show()
7666
return True
7767

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-
9568
if __name__ == '__main__':
96-
9769
sys.excepthook = cefpython.ExceptHook
9870
settings = {
9971
# Change to LOGSEVERITY_INFO if you want less debug output.
10072
"log_severity": cefpython.LOGSEVERITY_VERBOSE,
10173
"release_dcheck_enabled": True
10274
}
103-
cefpython.Initialize(settings) # Initialize cefpython before wx.
75+
cefpython.Initialize(settings)
10476

10577
print('wx.version=%s' % wx.version())
10678
app = MyApp(False)

0 commit comments

Comments
 (0)