1919
2020import wx
2121
22+ # Which method to use for message loop processing.
23+ # EVT_IDLE - wx application has priority (default)
24+ # EVT_TIMER - cef browser has priority
25+ # From the tests it seems that Flash content behaves
26+ # better when using a timer.
27+ USE_EVT_IDLE = True
28+
2229def GetApplicationPath (file = None ):
2330 import re , os
2431 # If file is None return current directory without trailing slash.
@@ -69,7 +76,9 @@ def __init__(self):
6976 self .Bind (wx .EVT_SET_FOCUS , self .OnSetFocus )
7077 self .Bind (wx .EVT_SIZE , self .OnSize )
7178 self .Bind (wx .EVT_CLOSE , self .OnClose )
72- self .Bind (wx .EVT_IDLE , self .OnIdle )
79+ if USE_EVT_IDLE :
80+ # Bind EVT_IDLE only for the main application frame.
81+ self .Bind (wx .EVT_IDLE , self .OnIdle )
7382
7483 def CreateMenu (self ):
7584 filemenu = wx .Menu ()
@@ -96,13 +105,35 @@ def OnIdle(self, event):
96105 cefpython .MessageLoopWork ()
97106
98107class MyApp (wx .App ):
108+ timer = None
109+ timerID = 1
99110
100111 def OnInit (self ):
112+ if not USE_EVT_IDLE :
113+ self .CreateTimer ()
101114 frame = MainFrame ()
102115 self .SetTopWindow (frame )
103116 frame .Show ()
104117 return True
105118
119+ def CreateTimer (self ):
120+ # See "Making a render loop":
121+ # http://wiki.wxwidgets.org/Making_a_render_loop
122+ # Another approach is to use EVT_IDLE in MainFrame,
123+ # see which one fits you better.
124+ self .timer = wx .Timer (self , self .timerID )
125+ self .timer .Start (10 ) # 10ms
126+ wx .EVT_TIMER (self , self .timerID , self .OnTimer )
127+
128+ def OnTimer (self , event ):
129+ cefpython .SingleMessageLoop ()
130+
131+ def OnExit (self ):
132+ # When app.MainLoop() returns, MessageLoopWork() should
133+ # not be called anymore.
134+ if not USE_EVT_IDLE :
135+ self .timer .Stop ()
136+
106137if __name__ == '__main__' :
107138 sys .excepthook = ExceptHook
108139 settings = {
0 commit comments