Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cefpython.SetGlobalClientCallback("OnCertificateError",
clientHandler._OnCertificateError)
cefpython.SetGlobalClientCallback("OnBeforePluginLoad",
clientHandler._OnBeforePluginLoad)
cefpython.SetGlobalClientCallback("OnAfterCreated",
clientHandler._OnAfterCreated)
windowInfo = cefpython.WindowInfo()
# Must show window otherwise GetHandle() returns 0
self.Show()
cefpython.WindowUtils.InstallX11ErrorHandlers()
windowInfo.SetAsChild(self.mainPanel.GetHandle(),
[0,0,0,0])
# Linux requires adding "file://" for local files,
# otherwise /home/some will be replaced as http://home/some
self.browser = cefpython.CreateBrowserSync(
windowInfo,
# If there are problems with Flash you can disable it here,
# by disabling all plugins.
browserSettings=g_browserSettings,
navigateUrl=url)
clientHandler.mainBrowser = self.browser
self.browser.SetClientHandler(clientHandler)
jsBindings = cefpython.JavascriptBindings(
bindToFrames=False, bindToPopups=True)
jsBindings.SetFunction("PyPrint", PyPrint)
jsBindings.SetProperty("pyProperty", "This was set in Python")
jsBindings.SetProperty("pyConfig", ["This was set in Python",
{"name": "Nested dictionary", "isNested": True},
[1,"2", None]])
def main():
cef.Initialize()
browser = cef.CreateBrowserSync(
url="http://www.html-kit.com/tools/cookietester/",
window_title="Network cookies")
browser.SetClientHandler(RequestHandler())
cef.MessageLoop()
del browser
cef.Shutdown()
def run_cef_gui(url_target, title):
check_versions()
sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error
cef.Initialize()
cef.CreateBrowserSync(url=url_target,
window_title=title)
cef.MessageLoop()
cef.Shutdown()
def embed_browser(self):
window_info = cef.WindowInfo()
(width, height) = self.browser_panel.GetClientSize().Get()
assert self.browser_panel.GetHandle(), "Window handle not available yet"
window_info.SetAsChild(self.browser_panel.GetHandle(),
[0, 0, width, height])
# NEURON
app_port = find_port()
t = threading.Thread(target=start_server, args=(app_port,))
t.daemon = True
t.start()
flask_url = "http://localhost:" + str(app_port)
self.browser = cef.CreateBrowserSync(window_info, url=flask_url)
self.browser.SetClientHandler(FocusHandler())
window,
-1,
sdl2.render.SDL_RENDERER_ACCELERATED
)
else:
# Create the renderer using software acceleration
logging.info("Using software rendering")
renderer = sdl2.SDL_CreateRenderer(
window,
-1,
sdl2.render.SDL_RENDERER_SOFTWARE
)
# Set-up the RenderHandler, passing in the SDL2 renderer
renderHandler = RenderHandler(renderer, width, height - headerHeight)
# Create the browser instance
browser = cef.CreateBrowserSync(window_info,
url="https://www.google.com/",
settings=browser_settings)
browser.SetClientHandler(LoadHandler())
browser.SetClientHandler(renderHandler)
# Must call WasResized at least once to let know CEF that
# viewport size is available and that OnPaint may be called.
browser.SendFocusEvent(True)
browser.WasResized()
# Begin the main rendering loop
running = True
# FPS debug variables
frames = 0
logging.debug("beginning rendering loop")
resetFpsTime = True
fpsTime = 0
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
window_info = cefpython.WindowInfo()
window_info.SetAsChild(self.GetHandle())
if not browser_settings:
browser_settings = {}
self.browser = cefpython.CreateBrowserSync(
window_info,
browserSettings=browser_settings, navigateUrl=url)
if platform.system() == "Windows":
self.Bind(wx.EVT_SET_FOCUS, self.on_set_focus)
self.Bind(wx.EVT_SIZE, self.on_size)
self._useTimer = use_timer
self.Bind(wx.EVT_IDLE, self.on_idle)
self.Bind(wx.EVT_CLOSE, self.on_close)
def embed_browser(self):
window_info = cef.WindowInfo()
(width, height) = self.GetClientSize()
print("embed_browser0", width, height)
if self.hidden:
window_info.SetAsChild(self.Handle, [0, 0, 1, 1])
else:
window_info.SetAsChild(self.Handle, [0, 0, width, height])
print("embed_browser", width, height)
self.browser = cef.CreateBrowserSync(window_info, url = self.url)
self.browser.SetClientHandler(FocusHandler(self))
self.browser.SetClientHandler(KeyboardHandler(self))
this = self
def wx_fun(value):
print("Value sent from Javascript: ", value)
print(type(self))
#self.Show()
bindings = cef.JavascriptBindings()
bindings.SetFunction("wx_fun", wx_fun)
self.browser.SetJavascriptBindings(bindings)
if self.url:
self.browser.GetMainFrame().LoadUrl(self.url)
else:
import re
m = re.search("GtkPlug at 0x(\w+)", str(self.plug))
hexId = m.group(1)
gtkPlugPtr = int(hexId, 16)
...
plug.show()
self.show()
---------------------------------------------------------
"""
windowInfo = cefpython.WindowInfo()
# Need to pass to CEF the GtkWidget* pointer
windowInfo.SetAsChild(gtkPlugPtr)
# Linux requires adding "file://" for local files,
# otherwise /home/some will be replaced as http://home/some
self.browser = cefpython.CreateBrowserSync(windowInfo,
browserSettings={},
navigateUrl="file://"+GetApplicationPath("example.html"))
cefpython.WindowUtils.gtk_widget_show(gtkPlugPtr)
self.show()
def embed_browser(self):
window_info = cef.WindowInfo()
# TODO: on Mac pass rect[x, y, width, height] to SetAsChild
window_info.SetAsChild(self.get_handle())
self.browser = cef.CreateBrowserSync(window_info,
url="https://www.google.com/")