Skip to content

Commit 97712b3

Browse files
committed
Fix crashes in unit tests and examples on Windows with v55+ (cztomczak#294)...
Fixes to wxpython.py example, works great. The hello_world.py example also works good. Unit tests are working fine now. When not providing parent window handle (NULL) during browser creation, so that CEF creates top-level window itself, in such case must call SetAsPopup on Windows. Fixes to build.py tool to run all examples smoothly.
1 parent 60ebfb8 commit 97712b3

6 files changed

Lines changed: 63 additions & 47 deletions

File tree

‎examples/wxpython.py‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
# To install wxPython on Linux type "sudo apt-get install python-wxtools".
55

6-
# Tested with wxPython 2.8 on Linux, wxPython 3.0 on Windows/Mac
7-
# and CEF Python v55.3+.
6+
# Tested configurations:
7+
# - wxPython 2.8 on Linux
8+
# - wxPython 3.0.2.0 msw (classic) on Windows
9+
# - wxPython 3.0 on Mac
10+
# - CEF Python v55.3+
811

912
import wx
1013
from cefpython3 import cefpython as cef
@@ -28,7 +31,7 @@ def main():
2831
settings["auto_zooming"] = "system_dpi"
2932
# Embed DPI awareness xml manifest inside .exe (recommended,
3033
# most reliable) or call the SetProcessDpiAware function.
31-
# noinspection PyUnresolvedReferences
34+
# noinspection PyUnresolvedReferences, PyArgumentList
3235
cef.DpiAware.SetProcessDpiAware()
3336
cef.Initialize(settings=settings)
3437
app = CefApp(False)
@@ -40,7 +43,7 @@ def main():
4043
def check_versions():
4144
print("[wxpython.py] CEF Python {ver}".format(ver=cef.__version__))
4245
print("[wxpython.py] Python {ver}".format(ver=sys.version[:6]))
43-
print("[wxpython.py] wx {ver}".format(ver=wx.version()))
46+
print("[wxpython.py] wxPython {ver}".format(ver=wx.version()))
4447
# CEF Python version requirement
4548
assert cef.__version__ >= "55.3", "CEF Python v55.3+ required to run this"
4649

@@ -75,11 +78,10 @@ def setup_icon(self):
7578

7679
def create_menu(self):
7780
filemenu = wx.Menu()
78-
filemenu.Append(1, "Open")
79-
exit_ = filemenu.Append(2, "Exit")
80-
self.Bind(wx.EVT_MENU, self.OnClose, exit_)
81+
filemenu.Append(1, "Some option")
82+
exit_ = filemenu.Append(2, "Another option")
8183
aboutmenu = wx.Menu()
82-
aboutmenu.Append(1, "CEF Python")
84+
aboutmenu.Append(1, "Yet another option")
8385
menubar = wx.MenuBar()
8486
menubar.Append(filemenu, "&File")
8587
menubar.Append(aboutmenu, "&About")
@@ -93,23 +95,24 @@ def embed_browser(self):
9395
self.browser.SetClientHandler(FocusHandler())
9496

9597
def OnSetFocus(self, _):
96-
if not self.brower:
98+
if not self.browser:
9799
return
98100
if WINDOWS:
99101
# noinspection PyUnresolvedReferences
100-
cef.WindowUtils.OnSetFocus(self.GetHandleForBrowser(), 0, 0, 0)
102+
cef.WindowUtils.OnSetFocus(self.browser_panel.GetHandle(),
103+
0, 0, 0)
101104
self.browser.SetFocus(True)
102105

103106
def OnSize(self, _):
104107
if not self.browser:
105108
return
106109
if WINDOWS:
107110
# noinspection PyUnresolvedReferences
108-
cef.WindowUtils.OnSize(self.GetHandleForBrowser(), 0, 0, 0)
111+
cef.WindowUtils.OnSize(self.browser_panel.GetHandle(),
112+
0, 0, 0)
109113
elif LINUX:
110114
(x, y) = (0, 0)
111115
(width, height) = self.browser_panel.GetSizeTuple()
112-
# noinspection PyUnresolvedReferences
113116
self.browser.SetBounds(x, y, width, height)
114117
self.browser.NotifyMoveOrResizeStarted()
115118

@@ -154,9 +157,10 @@ def OnGotFocus(self, browser, **_):
154157
# window (alt+tab) and then back to this example, keyboard
155158
# focus becomes broken, you can't type anything, even
156159
# though a type cursor blinks in web view.
157-
print("[wxpython.py] FocusHandler.OnGotFocus:"
158-
" keyboard focus fix (#284)")
159-
browser.SetFocus(True)
160+
if LINUX:
161+
print("[wxpython.py] FocusHandler.OnGotFocus:"
162+
" keyboard focus fix (#284)")
163+
browser.SetFocus(True)
160164

161165

162166
class CefApp(wx.App):

‎src/window_info.pyx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ cdef class WindowInfo:
8787
# On Windows when parent window handle is 0 then SetAsPopup()
8888
# must be called instead.
8989
if parentWindowHandle == 0:
90-
self.SetAsPopup(parentWindowHandle, "Popup")
90+
self.SetAsPopup(parentWindowHandle, "")
9191
return
9292
if parentWindowHandle != 0\
9393
and not WindowUtils.IsWindowHandle(parentWindowHandle):

‎tools/build.py‎

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -648,16 +648,22 @@ def install_and_run():
648648
# Make setup installer
649649
print("[build.py] Make setup installer")
650650
make_tool = os.path.join(TOOLS_DIR, "make_installer.py")
651-
os.system("{python} {make_tool} --version {version}"
652-
.format(python=sys.executable,
653-
make_tool=make_tool,
654-
version=VERSION))
651+
ret = os.system("{python} {make_tool} --version {version}"
652+
.format(python=sys.executable,
653+
make_tool=make_tool,
654+
version=VERSION))
655+
if ret != 0:
656+
print("[build.py] ERROR while making installer package")
657+
sys.exit(ret)
655658

656659
# Install
657660
print("[build.py] Install the cefpython package")
658661
os.chdir(setup_installer_dir)
659-
os.system("{sudo} {python} setup.py install"
660-
.format(sudo=get_sudo(), python=sys.executable))
662+
ret = os.system("{sudo} {python} setup.py install"
663+
.format(sudo=get_sudo(), python=sys.executable))
664+
if ret != 0:
665+
print("[build.py] ERROR while installing package")
666+
sys.exit(ret)
661667
os.chdir(BUILD_DIR)
662668

663669
# Run unittests
@@ -666,32 +672,36 @@ def install_and_run():
666672
ret = os.system("{python} {test_runner}"
667673
.format(python=sys.executable, test_runner=test_runner))
668674
if ret != 0:
675+
print("[build.py] ERROR while running unit tests")
669676
sys.exit(ret)
670677

671678
# Run examples
672679
print("[build.py] Run examples")
673-
if KIVY_FLAG:
674-
run_examples = "{python} {linux_dir}/deprecated_64bit/kivy_.py"
675-
else:
676-
run_examples = ("cd {examples_dir}"
677-
" && {python} hello_world.py"
678-
" && {python} wxpython.py"
679-
" && {python} gtk2.py"
680-
" && {python} gtk2.py --message-loop-timer"
681-
# " && {python} gtk3.py"
682-
" && {python} tkinter_.py"
683-
" && {python} qt.py pyqt"
684-
" && {python} qt.py pyside")
685-
if LINUX:
686-
run_examples += (" && {python}"
687-
" {linux_dir}/deprecated_64bit/kivy_.py")
688-
run_examples.format(
689-
python=sys.executable,
690-
linux_dir=LINUX_DIR,
691-
examples_dir=EXAMPLES_DIR)
692-
os.system(run_examples)
693-
694-
print("[build.py] DONE")
680+
os.chdir(EXAMPLES_DIR)
681+
examples = list()
682+
if not KIVY_FLAG:
683+
examples.extend([
684+
"hello_world.py",
685+
"wxpython.py",
686+
"gtk2.py",
687+
"gtk2.py --message-loop-timer",
688+
"gtk3.py",
689+
"tkinter_.py",
690+
"qt.py pyqt",
691+
"qt.py pyside",
692+
])
693+
if LINUX:
694+
examples.append("{linux_dir}/deprecated_64bit/kivy_.py"
695+
.format(linux_dir=LINUX_DIR))
696+
for example in examples:
697+
ret = os.system("{python} {example}"
698+
.format(python=sys.executable, example=example))
699+
if ret != 0:
700+
print("[build.py] ERROR while running example: {example}"
701+
.format(example=example))
702+
sys.exit(1)
703+
704+
print("[build.py] Everything OK")
695705

696706

697707
def get_sudo():

‎tools/installer/cefpython3.__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# Licensed under BSD 3-clause license.
33

44
# NOTE: Template variables like {{VERSION}} are replaced with actual
5-
# values when make.py tool generates this package installer.
5+
# values when make_installer.py tool generates this package
6+
# installer.
67

78
import os
89
import sys

‎tools/installer/cefpython3.setup.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"""
1717

1818
# NOTE: Template variables like {{VERSION}} are replaced with actual
19-
# values when make.py tool generates this package installer.
19+
# values when make_installer.py tool generates this package
20+
# installer.
2021

2122
import copy
2223
import os

‎tools/make_installer.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Create setup.py package installer.
66
77
Usage:
8-
make.py VERSION
8+
make_installer.py VERSION
99
1010
Options:
1111
VERSION Version number eg. 50.0

0 commit comments

Comments
 (0)