Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
g_browserSettings = {
# "plugins_disabled": True,
# "file_access_from_file_urls_allowed": True,
# "universal_access_from_file_urls_allowed": True,
}
# Command line switches set programmatically
g_commandLineSwitches = {
# "proxy-server": "socks5://127.0.0.1:8888",
# "no-proxy-server": "",
# "enable-media-stream": "",
# "disable-gpu": "",
}
cefpython.Initialize(g_applicationSettings, g_commandLineSwitches)
app = MyApp(False)
app.MainLoop()
# Let wx.App destructor do the cleanup before calling
# cefpython.Shutdown(). This is to ensure reliable CEF shutdown.
del app
cefpython.Shutdown()
self.test_case.assertFalse(browser.IsPopup())
else:
# Second call for implicit popup browser opened via js.
# Should execute only for main test.
# Should not execute for DevTools window.
assert "main_test" in self.test_case.id()
assert not self.OnAfterCreatedPopup_True
self.OnAfterCreatedPopup_True = True
self.test_case.assertEqual(browser.GetIdentifier(),
POPUP_BROWSER_ID)
# browser.GetUrl() returns empty at this moment.
self.test_case.assertTrue(browser.IsPopup())
if WINDOWS:
cef.WindowUtils.SetTitle(browser, "Popup test")
# Close the popup browser after 250 ms
cef.PostDelayedTask(cef.TID_UI, 250, close_popup, self, browser)
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("[pygtk_.py]: 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)
# Destroy wx frame, this will complete the destruction of CEF browser
self.Destroy()
# In wx.chromectrl calling browser.CloseBrowser and/or self.Destroy
# may cause crashes when embedding multiple browsers in tab
# (Issue 107). In such case instead of calling CloseBrowser/Destroy
# try this code:
# | self.browser.ParentWindowWillClose()
# | event.Skip()
global g_countWindows
g_countWindows -= 1
if g_countWindows == 0:
# On Win/Linux the call to cefpython.Shutdown() is after
# app.MainLoop() returns, but on Mac it needs to be here.
cefpython.Shutdown()
print("[wxpython.py] OnClose: Exiting")
wx.GetApp().Exit()
wx.Window.__init__(self, parent, id=wx.ID_ANY, size=size,
*args, **kwargs)
# This timer is not used anymore, but creating it for backwards
# compatibility. In one of external projects ChromeWindow.timer.Stop()
# is being called during browser destruction.
self.timer = wx.Timer()
# On Linux absolute file urls need to start with "file://"
# otherwise a path of "/home/some" is converted to "http://home/some".
if platform.system() in ["Linux", "Darwin"]:
if url.startswith("/"):
url = "file://" + url
self.url = url
windowInfo = cefpython.WindowInfo()
if platform.system() == "Windows":
windowInfo.SetAsChild(self.GetHandle())
elif platform.system() == "Linux":
windowInfo.SetAsChild(self.GetGtkWidget())
elif platform.system() == "Darwin":
(width, height) = self.GetClientSizeTuple()
windowInfo.SetAsChild(self.GetHandle(),
[0, 0, width, height])
else:
raise Exception("Unsupported OS")
if not browserSettings:
browserSettings = {}
# Disable plugins:
# | browserSettings["plugins_disabled"] = True
def OnSetFocus(self, event):
"""OS_WIN only."""
cefpython.WindowUtils.OnSetFocus(self.GetHandle(), 0, 0, 0)
event.Skip()
def create_browser(window_info, settings, url):
assert(cef.IsThread(cef.TID_UI))
cef.CreateBrowserSync(window_info=window_info,
settings=settings,
url=url)
# entry widget otherwise keyboard focus is lost (Issue #255
# and Issue #284).
from cefpython3 import cefpython as cef
import ctypes
try:
import tkinter as tk
except ImportError:
import Tkinter as tk
import sys
import os
import platform
import logging as _logging
# Fix for PyCharm hints warnings
WindowUtils = cef.WindowUtils()
# Platforms
WINDOWS = (platform.system() == "Windows")
LINUX = (platform.system() == "Linux")
MAC = (platform.system() == "Darwin")
# Globals
logger = _logging.getLogger("tkinter_.py")
# Constants
# Tk 8.5 doesn't support png images
IMAGE_EXT = ".png" if tk.TkVersion > 8.5 else ".gif"
def main():
logger.setLevel(_logging.INFO)
# Application settings
g_applicationSettings = {
# Disk cache
# "cache_path": "webcache/",
# CEF Python debug messages in console and in log_file
"debug": True,
# Set it to LOGSEVERITY_VERBOSE for more details
"log_severity": cefpython.LOGSEVERITY_INFO,
# Set to "" to disable logging to a file
"log_file": GetApplicationPath("debug.log"),
# "resources_dir_path" must be set on Mac, "locales_dir_path" not.
# You must also set "locale_pak" using command line switch.
"resources_dir_path": cefpython.GetModuleDirectory()+"/Resources",
# The "subprocess" executable that launches the Renderer
# and GPU processes among others. You may rename that
# executable if you like.
"browser_subprocess_path": "%s/%s" % (
cefpython.GetModuleDirectory(), "subprocess"),
# This option is required for the GetCookieManager callback
# to work. It affects renderer processes, when this option
# is set to True. It will force a separate renderer process
# for each browser created using CreateBrowserSync.
"unique_request_context_per_browser": True,
# Downloads are handled automatically. A default SaveAs file
# dialog provided by OS will be displayed.
"downloads_enabled": True,