Skip to content

Commit 24e44d3

Browse files
committed
Fixes to the wx examples. Using Timer by default, instead of
EVT_IDLE. Changed the behavior of browser cleanup on close. Suppress msgbox in cefpython3 installer, it breaks installation when running installer from command line with the /SILENT flag. By default uninstall any previously installed cefpython package without asking.
1 parent 57caa5a commit 24e44d3

File tree

4 files changed

+42
-32
lines changed

4 files changed

+42
-32
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cef3-trunk
2+
svn-win32-1.8.5

cefpython/cef3/windows/binaries/wxpython.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,24 @@
2727
import platform
2828

2929
# Which method to use for message loop processing.
30-
# EVT_IDLE - wx application has priority (default)
31-
# EVT_TIMER - cef browser has priority
30+
# EVT_IDLE - wx application has priority
31+
# EVT_TIMER - cef browser has priority (default)
3232
# It seems that Flash content behaves better when using a timer.
33-
USE_EVT_IDLE = True
33+
# Not sure if using EVT_IDLE is correct, it doesn't work on Linux,
34+
# on Windows it works fine, but read the comment below.
35+
"""
36+
See comment by Robin Dunn:
37+
https://groups.google.com/d/msg/wxpython-users/hcNdMEx8u48/MD5Jgbm_k1kJ
38+
-------------------------------------------------------------------------------
39+
EVT_IDLE events are not sent continuously while the application is idle.
40+
They are sent (normally once) when the app *becomes* idle, which
41+
usually means when the event queue has just been emptied. If you want
42+
EVT_IDLE events to be sent continuously then you need to call
43+
event.RequestMore() from the handler. Be careful however as that will
44+
cause your application to consume 100% of the CPU if there is no limits.
45+
-------------------------------------------------------------------------------
46+
"""
47+
USE_EVT_IDLE = False # If False then Timer will be used.
3448

3549
TEST_EMBEDDING_IN_PANEL = True
3650

@@ -167,11 +181,14 @@ def OnSize(self, event):
167181
cefpython.WindowUtils.OnSize(self.GetHandleForBrowser(), 0, 0, 0)
168182

169183
def OnClose(self, event):
170-
self.browser.CloseBrowser()
184+
print("MainFrame.OnClose()")
185+
self.browser.ParentWindowWillClose()
171186
self.Destroy()
172187

173188
def OnIdle(self, event):
174189
cefpython.MessageLoopWork()
190+
# See the comment at the top of the file by Robin Dunn.
191+
# | event.RequestMore()
175192

176193
def PyPrint(message):
177194
print(message)

cefpython/cef3/windows/installer/innosetup.template

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ begin
129129

130130
MsgBox('No installation of Python %(PYTHON_VERSION)s '
131131
+ 'found in registry.' + #13 + 'Be sure to enter '
132-
+ 'a pathname that places CEF Python 3 on the '
132+
+ 'a pathname that places Python on the '
133133
+ 'PYTHONPATH',
134134
mbConfirmation, MB_OK);
135135
PythonDir := 'C:\Python';
@@ -154,14 +154,8 @@ begin
154154
Result := False;
155155
if FileExists(FileName) then begin
156156
Result := True;
157-
ResultCode := MsgBox('A prior CEF Python 3 installation was found in '
158-
+ 'this directory. It' + #13 + 'is recommended that it be '
159-
+ 'uninstalled first.' + #13#13 + 'Should I do it?',
160-
mbConfirmation, MB_YESNO);
161-
if ResultCode = IDYES then begin
162-
Exec(FileName, '/SILENT', WizardDirValue(), SW_SHOWNORMAL,
163-
ewWaitUntilTerminated, ResultCode);
164-
end;
157+
Exec(FileName, '/SILENT', WizardDirValue(), SW_SHOWNORMAL,
158+
ewWaitUntilTerminated, ResultCode);
165159
end;
166160
end;
167161

cefpython/cef3/wx-subpackage/chromectrl.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,9 @@ class ChromeWindow(wx.Window):
8989
Standalone CEF component. The class provides facilites for interacting
9090
with wx message loop
9191
"""
92-
def __init__(self, parent, url="", useTimer=None,
92+
def __init__(self, parent, url="", useTimer=True,
9393
timerMillis=DEFAULT_TIMER_MILLIS, browserSettings=None,
9494
size=(-1, -1), *args, **kwargs):
95-
if platform.system() == "Linux" and useTimer == None:
96-
# On Linux OnIdle does not work correctly, must use timer.
97-
useTimer = True
98-
useTimer = bool(useTimer)
99-
10095
wx.Window.__init__(self, parent, id=wx.ID_ANY, size=size,
10196
*args, **kwargs)
10297
# On Linux absolute file urls need to start with "file://"
@@ -126,22 +121,29 @@ def __init__(self, parent, url="", useTimer=None,
126121
if platform.system() == "Windows":
127122
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
128123
self.Bind(wx.EVT_SIZE, self.OnSize)
124+
129125
if useTimer:
130126
self.timerID = 1
131127
self._CreateTimer(timerMillis)
132128
else:
133129
self.Bind(wx.EVT_IDLE, self.OnIdle)
130+
131+
self.Bind(wx.EVT_CLOSE, self.OnClose)
134132
self._useTimer = useTimer
135133

136-
def __del__(self):
137-
'''cleanup stuff'''
134+
def OnClose(self, event):
138135
if self._useTimer:
139136
self.timer.Stop()
140-
# Calling Unbind() is unnecessary and will cause problems on Windows 8:
141-
# https://groups.google.com/d/topic/cefpython/iXE7e1ekArI/discussion
142-
# | self.Unbind(wx.EVT_IDLE)
143-
# CloseBrowser() parameter: forceClose=True
144-
self.browser.CloseBrowser(True)
137+
else:
138+
try:
139+
self.Unbind(wx.EVT_IDLE)
140+
except:
141+
# Calling Unbind() may cause problems on Windows 8:
142+
# https://groups.google.com/d/topic/cefpython/iXE7e1ekArI/discussion
143+
# (it was causing problems in __del__, this might not
144+
# be true anymore in OnClose, but still let's make sure)
145+
pass
146+
self.browser.ParentWindowWillClose()
145147

146148
def _CreateTimer(self, millis):
147149
self.timer = wx.Timer(self, self.timerID)
@@ -191,15 +193,10 @@ def LoadUrl(self, url, onLoadStart=None, onLoadEnd=None):
191193

192194

193195
class ChromeCtrl(wx.Panel):
194-
def __init__(self, parent, url="", useTimer=None,
196+
def __init__(self, parent, url="", useTimer=True,
195197
timerMillis=DEFAULT_TIMER_MILLIS,
196198
browserSettings=None, hasNavBar=True,
197199
*args, **kwargs):
198-
if platform.system() == "Linux" and useTimer == None:
199-
# On Linux OnIdle does not work correctly, must use timer.
200-
useTimer = True
201-
useTimer = bool(useTimer)
202-
203200
# You also have to set the wx.WANTS_CHARS style for
204201
# all parent panels/controls, if it's deeply embedded.
205202
wx.Panel.__init__(self, parent, style=wx.WANTS_CHARS, *args, **kwargs)

0 commit comments

Comments
 (0)