wxPython和CEF Python 3
查看Windows上CEF Python 3中的示例文件 运行Python示例脚本时,它会在Windows命令提示符下打开一个调试窗口 我想知道怎样才能不显示这一点 我只想说一句显而易见的话: DEBUG=True——没有什么区别,它只是在该窗口内停止调试,但窗口仍然显示。 这是example.py文件:wxPython和CEF Python 3,python,wxpython,chromium-embedded,cefpython,Python,Wxpython,Chromium Embedded,Cefpython,查看Windows上CEF Python 3中的示例文件 运行Python示例脚本时,它会在Windows命令提示符下打开一个调试窗口 我想知道怎样才能不显示这一点 我只想说一句显而易见的话: DEBUG=True——没有什么区别,它只是在该窗口内停止调试,但窗口仍然显示。 这是example.py文件: # CEF Python 3 example application. # Checking whether python architecture and version are vali
# CEF Python 3 example application.
# Checking whether python architecture and version are valid, otherwise an obfuscated
# error will be thrown when trying to load cefpython.pyd with a message "DLL load failed".
import platform
if platform.architecture()[0] != "32bit":
raise Exception("Architecture not supported: %s" % platform.architecture()[0])
import os, sys
libcef_dll = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'libcef.dll')
if os.path.exists(libcef_dll):
# Import the local module.
if 0x02070000 <= sys.hexversion < 0x03000000:
import cefpython_py27 as cefpython
elif 0x03000000 <= sys.hexversion < 0x04000000:
import cefpython_py32 as cefpython
else:
raise Exception("Unsupported python version: %s" % sys.version)
else:
# Import the package.
from cefpython3 import cefpython
import cefwindow
import win32con
import win32gui
import time
DEBUG = True
def GetApplicationPath(file=None):
import re, os
# If file is None return current directory without trailing slash.
if file is None:
file = ""
# Only when relative path.
if not file.startswith("/") and not file.startswith("\\") and (
not re.search(r"^[\w-]+:", file)):
if hasattr(sys, "frozen"):
path = os.path.dirname(sys.executable)
elif "__file__" in globals():
path = os.path.dirname(os.path.realpath(__file__))
else:
path = os.getcwd()
path = path + os.sep + file
path = re.sub(r"[/\\]+", re.escape(os.sep), path)
path = re.sub(r"[/\\]+$", "", path)
return path
return str(file)
def ExceptHook(excType, excValue, traceObject):
import traceback, os, time, codecs
# This hook does the following: in case of exception write it to
# the "error.log" file, display it to the console, shutdown CEF
# and exit application immediately by ignoring "finally" (_exit()).
errorMsg = "\n".join(traceback.format_exception(excType, excValue,
traceObject))
errorFile = GetApplicationPath("error.log")
try:
appEncoding = cefpython.g_applicationSettings["string_encoding"]
except:
appEncoding = "utf-8"
if type(errorMsg) == bytes:
errorMsg = errorMsg.decode(encoding=appEncoding, errors="replace")
try:
with codecs.open(errorFile, mode="a", encoding=appEncoding) as fp:
fp.write("\n[%s] %s\n" % (
time.strftime("%Y-%m-%d %H:%M:%S"), errorMsg))
except:
print("cefpython: WARNING: failed writing to error file: %s" % (
errorFile))
# Convert error message to ascii before printing, otherwise
# you may get error like this:
# | UnicodeEncodeError: 'charmap' codec can't encode characters
errorMsg = errorMsg.encode("ascii", errors="replace")
errorMsg = errorMsg.decode("ascii", errors="replace")
print("\n"+errorMsg+"\n")
cefpython.QuitMessageLoop()
cefpython.Shutdown()
os._exit(1)
def InitDebugging():
# Whether to print & log debug messages
if DEBUG:
cefpython.g_debug = True
cefpython.g_debugFile = GetApplicationPath("debug.log")
cefwindow.g_debug = True
def CefAdvanced():
sys.excepthook = ExceptHook
InitDebugging()
appSettings = dict()
appSettings["log_file"] = GetApplicationPath("debug.log")
appSettings["log_severity"] = cefpython.LOGSEVERITY_INFO
appSettings["release_dcheck_enabled"] = True # Enable only when debugging
appSettings["browser_subprocess_path"] = "%s/%s" % (
cefpython.GetModuleDirectory(), "subprocess")
cefpython.Initialize(appSettings)
wndproc = {
win32con.WM_CLOSE: CloseWindow,
win32con.WM_DESTROY: QuitApplication,
win32con.WM_SIZE: cefpython.WindowUtils.OnSize,
win32con.WM_SETFOCUS: cefpython.WindowUtils.OnSetFocus,
win32con.WM_ERASEBKGND: cefpython.WindowUtils.OnEraseBackground
}
browserSettings = dict()
browserSettings["universal_access_from_file_urls_allowed"] = True
browserSettings["file_access_from_file_urls_allowed"] = True
windowHandle = cefwindow.CreateWindow(title="CEF Python 3 example",
className="cefpython3_example", width=800, height=600,
icon="icon.ico", windowProc=wndproc)
windowInfo = cefpython.WindowInfo()
windowInfo.SetAsChild(windowHandle)
browser = cefpython.CreateBrowserSync(windowInfo, browserSettings,
navigateUrl=GetApplicationPath("example.html"))
cefpython.MessageLoop()
cefpython.Shutdown()
def CloseWindow(windowHandle, message, wparam, lparam):
browser = cefpython.GetBrowserByWindowHandle(windowHandle)
browser.CloseBrowser()
return win32gui.DefWindowProc(windowHandle, message, wparam, lparam)
def QuitApplication(windowHandle, message, wparam, lparam):
win32gui.PostQuitMessage(0)
return 0
if __name__ == "__main__":
CefAdvanced()
#CEF Python 3示例应用程序。
#检查python体系结构和版本是否有效,否则会出现混淆
#尝试加载cefpython.pyd时将抛出错误,并显示消息“DLL加载失败”。
导入平台
if platform.architecture()[0]!=“32位”:
引发异常(“不支持体系结构:%s”%platform.Architecture()[0])
导入操作系统,系统
libcef_dll=os.path.join(os.path.dirname(os.path.abspath(u文件_u)),
'libcef.dll')
如果os.path.exists(libcef_dll):
#导入本地模块。
如果0x02070000我做对了,但实际上这是我使用py2exe的方式
在setup.py文件中,我必须更改:
setup(
console=['wxwindow.py']
,data_files = get_data_files()
,options={"py2exe":{"dll_excludes":dll_excludes, 'optimize': 2}}
,zipfile = "shared.lib"
)
setup(
window=['wxwindow.py']
,data_files = get_data_files()
,options={"py2exe":{"dll_excludes":dll_excludes, 'optimize': 2}}
,zipfile = "shared.lib"
)
因此:
对我来说,我必须让它成为windows(注:复数)
window=['wxwindow.py']