Skip to content

Commit 491324c

Browse files
committed
When the running process is detected to be DPI Aware, the
ApplicationSettings."auto_zooming" option will be set to "system_dpi" automatically. Added DpiAware.`IsProcessDpiAware`. Fixed error in pywin32 example when icon file was not found. Fixes to Inno setup uninstaller (Issue 67). Embedded VERSIONINFO resource in the .pyd module.
1 parent 1f4a929 commit 491324c

File tree

14 files changed

+232
-66
lines changed

14 files changed

+232
-66
lines changed

cefpython/cef3/client_handler/dpi_aware.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
const int DEFAULT_DPIX = 96;
1515

16-
/*
1716
bool IsProcessDpiAware() {
1817
typedef BOOL(WINAPI *IsProcessDPIAwarePtr)(VOID);
1918
IsProcessDPIAwarePtr is_process_dpi_aware_func =
@@ -60,7 +59,6 @@ PROCESS_DPI_AWARENESS GetProcessDpiAwareness() {
6059
}
6160
return PROCESS_DPI_UNAWARE;
6261
}
63-
*/
6462

6563
void SetProcessDpiAware() {
6664
// Win8.1 supports monitor-specific DPI scaling, so it is

cefpython/cef3/client_handler/dpi_aware.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ typedef enum PROCESS_DPI_AWARENESS {
1717
PROCESS_PER_MONITOR_DPI_AWARE = 2
1818
} PROCESS_DPI_AWARENESS;
1919

20-
/*
2120
bool IsProcessDpiAware();
2221
PROCESS_DPI_AWARENESS GetProcessDpiAwareness();
23-
*/
2422
void SetProcessDpiAware();
2523
void GetSystemDpi(int* outx, int* outy);
2624
void GetDpiAwareWindowSize(int* width, int* height);

cefpython/cef3/windows/binaries/example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<meta charset=utf-8>
55
<title>CEF Python 3 example (utf-8: ąś)</title>
66
<style>
7-
body { font: 13px Segoe UI, Arial; line-height: 1.4em; }
8-
pre { background: #ddd; font: 12px Consolas, Courier New; }
7+
body { font: 13px Tahoma; line-height: 1.4em; }
8+
pre { background: #ddd; font: 12px Lucida Console, Courier New; }
99
</style>
1010
</head>
1111
<body>

cefpython/cef3/windows/binaries/example.py renamed to cefpython/cef3/windows/binaries/pywin32.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
1-
# CEF Python 3 example application.
1+
# Example of embedding CEF browser using the PyWin32 extension.
2+
# Tested with pywin32 version 218.
23

3-
# Checking whether python architecture and version are valid, otherwise an obfuscated error
4-
# will be thrown when trying to load cefpython.pyd with a message "DLL load failed".
54
import platform
65
if platform.architecture()[0] != "32bit":
7-
raise Exception("Architecture not supported: %s" % platform.architecture()[0])
6+
raise Exception("Architecture not supported: %s" \
7+
% platform.architecture()[0])
88

99
import os, sys
1010
libcef_dll = os.path.join(os.path.dirname(os.path.abspath(__file__)),
1111
'libcef.dll')
1212
if os.path.exists(libcef_dll):
13-
# Import the local module.
13+
# Import a local module
1414
if 0x02070000 <= sys.hexversion < 0x03000000:
1515
import cefpython_py27 as cefpython
1616
elif 0x03000000 <= sys.hexversion < 0x04000000:
1717
import cefpython_py32 as cefpython
1818
else:
1919
raise Exception("Unsupported python version: %s" % sys.version)
2020
else:
21-
# Import the package.
21+
# Import an installed package
2222
from cefpython3 import cefpython
2323

2424
import cefwindow
2525
import win32con
2626
import win32gui
27+
import win32api
2728
import time
2829

2930
DEBUG = True
3031

32+
# -----------------------------------------------------------------------------
33+
# Helper functions.
34+
35+
def Log(msg):
36+
print("[pywin32.py] %s" % str(msg))
37+
3138
def GetApplicationPath(file=None):
32-
import re, os
39+
import re, os, platform
3340
# If file is None return current directory without trailing slash.
3441
if file is None:
3542
file = ""
@@ -43,7 +50,8 @@ def GetApplicationPath(file=None):
4350
else:
4451
path = os.getcwd()
4552
path = path + os.sep + file
46-
path = re.sub(r"[/\\]+", re.escape(os.sep), path)
53+
if platform.system() == "Windows":
54+
path = re.sub(r"[/\\]+", re.escape(os.sep), path)
4755
path = re.sub(r"[/\\]+$", "", path)
4856
return path
4957
return str(file)
@@ -52,7 +60,7 @@ def ExceptHook(excType, excValue, traceObject):
5260
import traceback, os, time, codecs
5361
# This hook does the following: in case of exception write it to
5462
# the "error.log" file, display it to the console, shutdown CEF
55-
# and exit application immediately by ignoring "finally" (_exit()).
63+
# and exit application immediately by ignoring "finally" (os._exit()).
5664
errorMsg = "\n".join(traceback.format_exception(excType, excValue,
5765
traceObject))
5866
errorFile = GetApplicationPath("error.log")
@@ -67,7 +75,7 @@ def ExceptHook(excType, excValue, traceObject):
6775
fp.write("\n[%s] %s\n" % (
6876
time.strftime("%Y-%m-%d %H:%M:%S"), errorMsg))
6977
except:
70-
print("cefpython: WARNING: failed writing to error file: %s" % (
78+
print("[pywin32.py] WARNING: failed writing to error file: %s" % (
7179
errorFile))
7280
# Convert error message to ascii before printing, otherwise
7381
# you may get error like this:
@@ -79,6 +87,8 @@ def ExceptHook(excType, excValue, traceObject):
7987
cefpython.Shutdown()
8088
os._exit(1)
8189

90+
# -----------------------------------------------------------------------------
91+
8292
def CefAdvanced():
8393
sys.excepthook = ExceptHook
8494

@@ -106,9 +116,14 @@ def CefAdvanced():
106116
browserSettings["universal_access_from_file_urls_allowed"] = True
107117
browserSettings["file_access_from_file_urls_allowed"] = True
108118

109-
windowHandle = cefwindow.CreateWindow(title="CEF Python 3 example",
110-
className="cefpython3_example", width=800, height=600,
111-
icon="icon.ico", windowProc=wndproc)
119+
if os.path.exists("icon.ico"):
120+
icon = os.path.abspath("icon.ico")
121+
else:
122+
icon = ""
123+
124+
windowHandle = cefwindow.CreateWindow(title="pywin32 example",
125+
className="cefpython3_example", width=1024, height=768,
126+
icon=icon, windowProc=wndproc)
112127
windowInfo = cefpython.WindowInfo()
113128
windowInfo.SetAsChild(windowHandle)
114129
browser = cefpython.CreateBrowserSync(windowInfo, browserSettings,
@@ -125,5 +140,10 @@ def QuitApplication(windowHandle, message, wparam, lparam):
125140
win32gui.PostQuitMessage(0)
126141
return 0
127142

143+
def GetPywin32Version():
144+
fixed_file_info = win32api.GetFileVersionInfo(win32api.__file__, '\\')
145+
return fixed_file_info['FileVersionLS'] >> 16
146+
128147
if __name__ == "__main__":
148+
Log("pywin32 version = %s" % GetPywin32Version())
129149
CefAdvanced()
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
22
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
3+
34
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
45
<security>
56
<requestedPrivileges>
6-
<requestedExecutionLevel level='asInvoker' uiAccess='false' />
7+
<requestedExecutionLevel
8+
level='asInvoker'
9+
uiAccess='false'
10+
/>
711
</requestedPrivileges>
812
</security>
913
</trustInfo>
14+
1015
<dependency>
1116
<dependentAssembly>
12-
<assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
17+
<assemblyIdentity
18+
type='win32'
19+
name='Microsoft.VC90.CRT'
20+
version='9.0.21022.8'
21+
processorArchitecture='x86'
22+
publicKeyToken='1fc8b3b9a1e18e3b'
23+
/>
1324
</dependentAssembly>
1425
</dependency>
26+
1527
</assembly>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
1 VERSIONINFO
2+
FILEVERSION 31,1,0,0
3+
PRODUCTVERSION 31,1,0,0
4+
FILEFLAGSMASK 0x3FL
5+
FILEFLAGS 0x0L
6+
FILEOS 0x4L
7+
FILETYPE 0x2L
8+
FILESUBTYPE 0x0L
9+
BEGIN
10+
BLOCK "StringFileInfo"
11+
BEGIN
12+
BLOCK "040904E4"
13+
BEGIN
14+
VALUE "CompanyName", "CEF Python"
15+
VALUE "FileDescription", "CEF Python DLL"
16+
VALUE "FileVersion", "31.1.0.0"
17+
VALUE "InternalName", "cefpython"
18+
VALUE "LegalCopyright", "(c) 2012-2014 The CEF Python authors"
19+
VALUE "LegalTrademarks", ""
20+
VALUE "OriginalFilename", "cefpython_py27.pyd"
21+
VALUE "ProductName", "CEF Python 3"
22+
VALUE "ProductVersion", "31.1.0.0"
23+
VALUE "Comments", "Licensed under BSD 3-clause license"
24+
VALUE "Aditional Notes", ""
25+
END
26+
END
27+
BLOCK "VarFileInfo"
28+
BEGIN
29+
VALUE "Translation", 0x409, 1252
30+
END
31+
END

cefpython/cef3/windows/compile.bat

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,52 @@
1-
for /f %%i in ('python -c "import sys; print(str(sys.version_info[0])+str(sys.version_info[1]));"') do set PYVERSION=%%i
1+
@echo on
22

3-
del "binaries\cefpython_py%PYVERSION%.pyd"
4-
del "setup\cefpython_py%PYVERSION%.pyd"
3+
@if [%1] == [] (
4+
@echo Version not provided. Example usage: compile.bat 31.0
5+
goto EOF
6+
)
57

6-
for /R %~dp0setup\ %%f in (*.pyx) do @del "%%f"
8+
for /f %%i in ('python -c "import sys; print(str(sys.version_info[0])+str(sys.version_info[1]));"') do set PYVERSION=%%i
79

10+
del "%~dp0binaries\cefpython_py%PYVERSION%.pyd"
11+
del "%~dp0setup\cefpython_py%PYVERSION%.pyd"
12+
for /R %~dp0setup\ %%f in (*.pyx) do @del "%%f"
813
rmdir /S /Q "%dp0setup\build\"
914

10-
cd "setup"
15+
@rem Compile .rc file to a .res object.
16+
cd %~dp0setup\
17+
call python compile_rc.py -v %1
18+
@if %errorlevel% neq 0 goto EOF
1119

20+
cd %~dp0setup
1221
call python "fix_includes.py"
22+
@if %errorlevel% neq 0 goto EOF
1323

14-
@if %ERRORLEVEL% neq 0 goto EOF
15-
24+
cd %~dp0setup
1625
call python "setup.py" build_ext --inplace
17-
18-
REM -- the setup above has disabled ECHO for commands, turning it back on.
19-
ECHO ON
20-
21-
@if %ERRORLEVEL% neq 0 for /R %~dp0setup\ %%f in (*.pyx) do @del "%%f"
22-
@if %ERRORLEVEL% neq 0 goto EOF
23-
26+
@rem setup.py disabled echo
27+
@echo on
28+
@if %errorlevel% neq 0 for /R %~dp0setup\ %%f in (*.pyx) do @del "%%f"
29+
@if %errorlevel% neq 0 for /R %~dp0setup\ %%f in (*.res) do @del "%%f"
30+
@if %errorlevel% neq 0 goto EOF
2431
for /R %~dp0setup\ %%f in (*.pyx) do @del "%%f"
32+
for /R %~dp0setup\ %%f in (*.res) do @del "%%f"
2533

26-
rmdir /S /Q "build\"
27-
@if %ERRORLEVEL% neq 0 goto EOF
28-
29-
call "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\mt.exe" -nologo -manifest %~dp0\cefpython.pyd.manifest -outputresource:%~dp0\setup\cefpython_py%PYVERSION%.pyd;2
30-
@if %ERRORLEVEL% neq 0 goto EOF
34+
rmdir /S /Q "%~dp0setup\build\"
35+
@if %errorlevel% neq 0 goto EOF
3136

32-
move "cefpython_py%PYVERSION%.pyd" "../binaries/cefpython_py%PYVERSION%.pyd"
33-
@if %ERRORLEVEL% neq 0 goto EOF
37+
@rem Embed manifest file into .pyd module.
38+
call "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\mt.exe" -nologo -manifest %~dp0cefpython.pyd.manifest -outputresource:%~dp0setup\cefpython_py%PYVERSION%.pyd;2
39+
@if %errorlevel% neq 0 goto EOF
3440

35-
cd ..
41+
move "%~dp0setup\cefpython_py%PYVERSION%.pyd" "%~dp0binaries/cefpython_py%PYVERSION%.pyd"
42+
@if %errorlevel% neq 0 goto EOF
3643

3744
copy "%~dp0..\subprocess\Release\subprocess.exe" "%~dp0binaries\subprocess.exe"
38-
@if %ERRORLEVEL% neq 0 goto EOF
45+
@if %errorlevel% neq 0 goto EOF
3946

40-
cd binaries
47+
@echo Compilation succeeded. Running wxpython.py example..
4148

49+
cd %~dp0binaries\
4250
call python "wxpython.py"
4351

4452
:EOF

cefpython/cef3/windows/installer/README.txt.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
python pyqt.py
1111
python pyside.py
1212
python pygtk_.py
13-
python example.py
13+
python pywin32.py
1414

1515
cd wx/
1616
python sample1.py
@@ -19,4 +19,4 @@
1919

2020
Note:
2121
Examples directory can also be found in the cefpython3 package directory:
22-
C:/python/lib/site-packages/cefpython3/examples/
22+
C:/python27/lib/site-packages/cefpython3/examples/

cefpython/cef3/windows/installer/innosetup.template

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,33 +75,29 @@ Source: "%(WX_SUBPACKAGE_DIR)s\examples\*.png"; DestDir: "{app}\%(PACKAGE_NAME)s
7575
; examples
7676
; ------------------------------------------------------------------------------
7777

78-
Source: "cefwindow.py"; DestDir: "{app}\%(PACKAGE_NAME)s\examples"; Flags: ignoreversion;
79-
Source: "example.py"; DestDir: "{app}\%(PACKAGE_NAME)s\examples"; Flags: ignoreversion;
78+
Source: "*.py"; DestDir: "{app}\%(PACKAGE_NAME)s\examples"; Flags: ignoreversion;
8079
Source: "*.html"; DestDir: "{app}\%(PACKAGE_NAME)s\examples"; Flags: ignoreversion;
8180
Source: "*.css"; DestDir: "{app}\%(PACKAGE_NAME)s\examples"; Flags: ignoreversion;
8281
Source: "*.js"; DestDir: "{app}\%(PACKAGE_NAME)s\examples"; Flags: ignoreversion;
83-
Source: "icon.ico"; DestDir: "{app}\%(PACKAGE_NAME)s\examples"; Flags: ignoreversion;
84-
Source: "pygtk_.py"; DestDir: "{app}\%(PACKAGE_NAME)s\examples"; Flags: ignoreversion;
85-
Source: "pyqt.py"; DestDir: "{app}\%(PACKAGE_NAME)s\examples"; Flags: ignoreversion;
86-
Source: "pyside.py"; DestDir: "{app}\%(PACKAGE_NAME)s\examples"; Flags: ignoreversion;
87-
Source: "wxpython.py"; DestDir: "{app}\%(PACKAGE_NAME)s\examples"; Flags: ignoreversion;
82+
Source: "*.ico"; DestDir: "{app}\%(PACKAGE_NAME)s\examples"; Flags: ignoreversion;
8883

8984
[UninstallDelete]
9085

9186
Type: files; Name: "{app}\%(PACKAGE_NAME)s\*.pyc";
87+
Type: files; Name: "{app}\%(PACKAGE_NAME)s\*.log";
88+
Type: filesandordirs; Name: "{app}\%(PACKAGE_NAME)s\__pycache__"
89+
9290
Type: files; Name: "{app}\%(PACKAGE_NAME)s\examples\*.pyc";
9391
Type: files; Name: "{app}\%(PACKAGE_NAME)s\examples\*.log";
94-
Type: filesandordirs; Name: "{app}\%(PACKAGE_NAME)s\__pycache__"
92+
Type: filesandordirs; Name: "{app}\%(PACKAGE_NAME)s\examples\__pycache__"
93+
9594
Type: files; Name: "{app}\%(PACKAGE_NAME)s\examples\wx\*.pyc";
9695
Type: files; Name: "{app}\%(PACKAGE_NAME)s\examples\wx\*.log";
96+
Type: filesandordirs; Name: "{app}\%(PACKAGE_NAME)s\examples\wx\__pycache__"
97+
9798
Type: files; Name: "{app}\%(PACKAGE_NAME)s\wx\*.pyc";
9899
Type: files; Name: "{app}\%(PACKAGE_NAME)s\wx\*.log";
99-
100-
; Issue 67 - remaining files in the wx/ and examples/wx/ directories:
101-
; https://code.google.com/p/cefpython/issues/detail?id=67
102-
; Just delete them all:
103-
Type: filesandordirs; Name: "{app}\%(PACKAGE_NAME)s\examples\wx"
104-
Type: filesandordirs; Name: "{app}\%(PACKAGE_NAME)s\wx"
100+
Type: filesandordirs; Name: "{app}\%(PACKAGE_NAME)s\wx\__pycache__"
105101

106102
[Code]
107103

0 commit comments

Comments
 (0)