def main(): # Use paths relative to this python file pythonFileFolder = os.path.dirname(os.path.realpath(__file__)) os.chdir(pythonFileFolder) _, innerFolder = os.path.split(pythonFileFolder) check_versions() sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error settings = { "remote_debugging_port": 49155, } cef.SetGlobalClientCallback("OnAfterCreated", on_after_create) cef.Initialize(settings=settings) browser = cef.CreateBrowserSync(url='file:///index.html', window_title=innerFolder) clientHandler = ClientHandler() browser.SetClientHandler(clientHandler) bindings = cef.JavascriptBindings() testObject = TestObject() bindings.SetObject("testObject", testObject) browser.SetJavascriptBindings(bindings) cef.MessageLoop() cef.Shutdown()
def set_global_handler(): # A global handler is a special handler for callbacks that # must be set before Browser is created using # SetGlobalClientCallback() method. global_handler = GlobalHandler() cef.SetGlobalClientCallback("OnAfterCreated", global_handler.OnAfterCreated)
def loadCustumUrl(self, url): self.clientHandler = ClientHandler() cefpython.SetGlobalClientCallback( "OnCertificateError", self.clientHandler._OnCertificateError) cefpython.SetGlobalClientCallback( "OnBeforePluginLoad", self.clientHandler._OnBeforePluginLoad) cefpython.SetGlobalClientCallback("OnAfterCreated", self.clientHandler._OnAfterCreated) windowInfo = cefpython.WindowInfo() windowInfo.SetAsChild(int(self.winId())) self.browser = cefpython.CreateBrowserSync(windowInfo, browserSettings={}, navigateUrl="about:None") self.browser.GetMainFrame().LoadUrl(url) self.clientHandler.mainBrowser = self.browser self.browser.SetClientHandler(self.clientHandler) self.show()
def set_global_handler(): def on_after_create(browser, **_): cef.WindowUtils.SetTitle(browser, 'Kam1n0') bindings = cef.JavascriptBindings( bindToFrames=True, bindToPopups=False) bindings.SetObject("browser_controller", BrowserController(browser)) bindings.SetFunction("send_msg", send_msg) browser.SetJavascriptBindings(bindings) cef.SetGlobalClientCallback("OnAfterCreated", on_after_create)
def main(): check_versions() sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error settings = { "remote_debugging_port": 49152, } cef.SetGlobalClientCallback("OnAfterCreated", on_after_create) cef.Initialize(settings=settings) browser = cef.CreateBrowserSync(url='file:///html/hello_world.html', window_title="2. Handlers") clientHandler = ClientHandler() browser.SetClientHandler(clientHandler) cef.MessageLoop() cef.Shutdown()
def main(): check_versions() sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error settings = { # "remote_debugging_port": 49152, } cef.SetGlobalClientCallback("OnAfterCreated", on_after_create) cef.Initialize(settings=settings) browser = cef.CreateBrowserSync(url='file:///html/callback_test_managed.html', window_title="2. Handlers") clientHandler = ClientHandler() browser.SetClientHandler(clientHandler) bindings = cef.JavascriptBindings() testObject = TestObject() bindings.SetObject("testObject", testObject) browser.SetJavascriptBindings(bindings) cef.MessageLoop() cef.Shutdown()
def test_main(self): """Main entry point. All the code must run inside one single test, otherwise strange things happen.""" print("") print("CEF Python {ver}".format(ver=cef.__version__)) print("Python {ver}".format(ver=sys.version[:6])) # Test initialization of CEF settings = { "debug": False, "log_severity": cef.LOGSEVERITY_ERROR, "log_file": "", } if not LINUX: # On Linux you get a lot of "X error received" messages # from Chromium's "x11_util.cc", so do not show them. settings["log_severity"] = cef.LOGSEVERITY_WARNING if "--debug" in sys.argv: settings["debug"] = True settings["log_severity"] = cef.LOGSEVERITY_INFO if "--debug-warning" in sys.argv: settings["debug"] = True settings["log_severity"] = cef.LOGSEVERITY_WARNING cef.Initialize(settings) subtest_message("cef.Initialize() ok") # CRL set file certrevoc_dir = "" if WINDOWS: certrevoc_dir = r"C:\localappdata\Google\Chrome\User Data" \ r"\CertificateRevocation" elif LINUX: certrevoc_dir = r"/home/*/.config/google-chrome" \ r"/CertificateRevocation" elif MAC: certrevoc_dir = r"/Users/*/Library/Application Support/Google" \ r"/Chrome/CertificateRevocation" crlset_files = glob.iglob(os.path.join(certrevoc_dir, "*", "crl-set")) crlset = "" for crlset in crlset_files: pass if os.path.exists(crlset): cef.LoadCrlSetsFile(crlset) subtest_message("cef.LoadCrlSetsFile ok") # High DPI on Windows if WINDOWS: self.assertIsInstance(cef.DpiAware.GetSystemDpi(), tuple) window_size = cef.DpiAware.CalculateWindowSize(800, 600) self.assertIsInstance(window_size, tuple) self.assertGreater(window_size[0], 0) self.assertGreater(cef.DpiAware.Scale((800, 600))[0], 0) cef.DpiAware.EnableHighDpiSupport() self.assertTrue(cef.DpiAware.IsProcessDpiAware()) # Make some calls again after DPI Aware was set self.assertIsInstance(cef.DpiAware.GetSystemDpi(), tuple) self.assertGreater(cef.DpiAware.Scale([800, 600])[0], 0) self.assertIsInstance(cef.DpiAware.Scale(800), int) self.assertGreater(cef.DpiAware.Scale(800), 0) subtest_message("cef.DpiAware ok") # Global handler global_handler = GlobalHandler(self) cef.SetGlobalClientCallback("OnAfterCreated", global_handler._OnAfterCreated) subtest_message("cef.SetGlobalClientCallback() ok") # Create browser browser_settings = { "inherit_client_handlers_for_popups": False, } browser = cef.CreateBrowserSync(url=g_datauri, settings=browser_settings) self.assertIsNotNone(browser, "Browser object") browser.SetFocus(True) subtest_message("cef.CreateBrowserSync() ok") # Client handlers display_handler2 = DisplayHandler2(self) client_handlers = [LoadHandler(self, g_datauri), DisplayHandler(self), display_handler2] for handler in client_handlers: browser.SetClientHandler(handler) subtest_message("browser.SetClientHandler() ok") # Javascript bindings external = External(self) bindings = cef.JavascriptBindings( bindToFrames=False, bindToPopups=False) bindings.SetFunction("js_code_completed", js_code_completed) bindings.SetFunction("test_function", external.test_function) bindings.SetProperty("test_property1", external.test_property1) bindings.SetProperty("test_property2", external.test_property2) # Property with a function value can also be bound. CEF Python # supports passing functions as callbacks when called from # javascript, and as a side effect any value and in this case # a property can also be a function. bindings.SetProperty("test_property3_function", external.test_property3_function) bindings.SetProperty("cefpython_version", cef.GetVersion()) bindings.SetObject("external", external) browser.SetJavascriptBindings(bindings) subtest_message("browser.SetJavascriptBindings() ok") # Set auto resize. Call it after js bindings were set. browser.SetAutoResizeEnabled(enabled=True, min_size=[800, 600], max_size=[1024, 768]) subtest_message("browser.SetAutoResizeEnabled() ok") # Test Request.SetPostData(list) # noinspection PyArgumentList req = cef.Request.CreateRequest() req_file = os.path.dirname(os.path.abspath(__file__)) req_file = os.path.join(req_file, "main_test.py") if sys.version_info.major > 2: req_file = req_file.encode() req_data = [b"--key=value", b"@"+req_file] req.SetMethod("POST") req.SetPostData(req_data) self.assertEqual(req_data, req.GetPostData()) subtest_message("cef.Request.SetPostData(list) ok") # Test Request.SetPostData(dict) # noinspection PyArgumentList req = cef.Request.CreateRequest() req_data = {b"key": b"value"} req.SetMethod("POST") req.SetPostData(req_data) self.assertEqual(req_data, req.GetPostData()) subtest_message("cef.Request.SetPostData(dict) ok") # Cookie manager self.assertIsInstance(cef.CookieManager.CreateManager(path=""), cef.PyCookieManager) self.assertIsInstance(cef.CookieManager.GetGlobalManager(), cef.PyCookieManager) self.assertIsInstance(cef.CookieManager.GetBlockingManager(), cef.PyCookieManager) subtest_message("cef.CookieManager ok") # Window Utils if WINDOWS: hwnd = 1 # When using 0 getting issues with OnautoResize self.assertFalse(cef.WindowUtils.IsWindowHandle(hwnd)) cef.WindowUtils.OnSetFocus(hwnd, 0, 0, 0) cef.WindowUtils.OnSize(hwnd, 0, 0, 0) cef.WindowUtils.OnEraseBackground(hwnd, 0, 0, 0) cef.WindowUtils.GetParentHandle(hwnd) cef.WindowUtils.SetTitle(browser, "Main test") subtest_message("cef.WindowUtils ok") elif LINUX: cef.WindowUtils.InstallX11ErrorHandlers() subtest_message("cef.WindowUtils ok") elif MAC: hwnd = 0 cef.WindowUtils.GetParentHandle(hwnd) cef.WindowUtils.IsWindowHandle(hwnd) subtest_message("cef.WindowUtils ok") # Run message loop run_message_loop() # Make sure popup browser was destroyed self.assertIsInstance(cef.GetBrowserByIdentifier(MAIN_BROWSER_ID), cef.PyBrowser) self.assertIsNone(cef.GetBrowserByIdentifier(POPUP_BROWSER_ID)) subtest_message("cef.GetBrowserByIdentifier() ok") # Close browser and clean reference browser.CloseBrowser(True) del browser subtest_message("browser.CloseBrowser() ok") # Give it some time to close before checking asserts # and calling shutdown. do_message_loop_work(25) # Asserts before shutdown self.assertEqual(display_handler2.OnLoadingProgressChange_Progress, 1.0) # noinspection PyTypeChecker check_auto_asserts(self, [] + client_handlers + [global_handler, external]) # Test shutdown of CEF cef.Shutdown() subtest_message("cef.Shutdown() ok") # Display summary show_test_summary(__file__) sys.stdout.flush()
def set_global_handler(): global_handler = GlobalHandler() cef.SetGlobalClientCallback("OnAfterCreated", global_handler.OnAfterCreated)
def test_main(self): """Main entry point.""" # All this code must run inside one single test, otherwise strange # things happen. print("") print("CEF Python {ver}".format(ver=cef.__version__)) print("Python {ver}".format(ver=sys.version[:6])) # Test initialization of CEF settings = { "debug": False, "log_severity": cef.LOGSEVERITY_ERROR, "log_file": "", } if "--debug" in sys.argv: settings["debug"] = True settings["log_severity"] = cef.LOGSEVERITY_INFO cef.Initialize(settings) subtest_message("cef.Initialize() ok") # Test global handler global_handler = GlobalHandler(self) cef.SetGlobalClientCallback("OnAfterCreated", global_handler._OnAfterCreated) subtest_message("cef.SetGlobalClientCallback() ok") # Test creation of browser browser = cef.CreateBrowserSync(url=g_datauri) self.assertIsNotNone(browser, "Browser object") subtest_message("cef.CreateBrowserSync() ok") # Test other handlers: LoadHandler, DisplayHandler, DialogHandler etc. client_handlers = [ LoadHandler(self), DisplayHandler(self), DialogHandler(self) ] for handler in client_handlers: browser.SetClientHandler(handler) subtest_message("browser.SetClientHandler() ok") # Test javascript bindings external = External(self) bindings = cef.JavascriptBindings(bindToFrames=False, bindToPopups=False) bindings.SetFunction("test_function", external.test_function) bindings.SetProperty("test_property1", external.test_property1) bindings.SetProperty("test_property2", external.test_property2) bindings.SetProperty("cefpython_version", cef.GetVersion()) bindings.SetObject("external", external) browser.SetJavascriptBindings(bindings) subtest_message("browser.SetJavascriptBindings() ok") # Run message loop for some time. # noinspection PyTypeChecker cef_waiting(MESSAGE_LOOP_RANGE) subtest_message("cef.MessageLoopWork() ok") #Simulating file dialog click event for testing OnFileDialog handler browser.SendMouseClickEvent(67, 20, cef.MOUSEBUTTON_LEFT, False, 1) browser.SendMouseClickEvent(67, 20, cef.MOUSEBUTTON_LEFT, True, 1) # Run message loop for some time. cef_waiting(MESSAGE_LOOP_RANGE) # Test browser closing. Remember to clean reference. browser.CloseBrowser(True) del browser subtest_message("browser.CloseBrowser() ok") # Give it some time to close before calling shutdown. # noinspection PyTypeChecker cef_waiting(25) # Automatic check of asserts in handlers and in external automatic_check_handlers(self, [] + client_handlers + [global_handler, external]) # Test shutdown of CEF cef.Shutdown() subtest_message("cef.Shutdown() ok") # Display real number of tests there were run display_number_of_unittest("sub-tests in test_main") sys.stdout.flush()
def test_osr(self): """Main entry point. All the code must run inside one single test, otherwise strange things happen.""" print("") print("CEF Python {ver}".format(ver=cef.__version__)) print("Python {ver}".format(ver=sys.version[:6])) # Application settings settings = { "debug": False, "log_severity": cef.LOGSEVERITY_ERROR, "log_file": "", "windowless_rendering_enabled": True } if not LINUX: # On Linux you get a lot of "X error received" messages # from Chromium's "x11_util.cc", so do not show them. settings["log_severity"] = cef.LOGSEVERITY_WARNING if "--debug" in sys.argv: settings["debug"] = True settings["log_severity"] = cef.LOGSEVERITY_INFO if "--debug-warning" in sys.argv: settings["debug"] = True settings["log_severity"] = cef.LOGSEVERITY_WARNING switches = { # GPU acceleration is not supported in OSR mode, so must disable # it using these Chromium switches (Issue #240 and #463) "disable-gpu": "", "disable-gpu-compositing": "", # Tweaking OSR performance by setting the same Chromium flags # as in upstream cefclient (Issue #240). "enable-begin-frame-scheduling": "", "disable-surfaces": "", # This is required for PDF ext to work } browser_settings = { # Tweaking OSR performance (Issue #240) "windowless_frame_rate": 30, # Default frame rate in CEF is 30 } # Initialize cef.Initialize(settings=settings, switches=switches) subtest_message("cef.Initialize() ok") # Accessibility handler accessibility_handler = AccessibilityHandler(self) cef.SetGlobalClientHandler(accessibility_handler) subtest_message("cef.SetGlobalClientHandler() ok") # Global handler global_handler = GlobalHandler(self) cef.SetGlobalClientCallback("OnAfterCreated", global_handler._OnAfterCreated) subtest_message("cef.SetGlobalClientCallback() ok") # Create browser window_info = cef.WindowInfo() window_info.SetAsOffscreen(0) browser = cef.CreateBrowserSync(window_info=window_info, settings=browser_settings, url=g_datauri) # Javascript bindings bindings = cef.JavascriptBindings(bindToFrames=False, bindToPopups=False) bindings.SetFunction("js_code_completed", js_code_completed) bindings.SetProperty("cefpython_version", cef.GetVersion()) browser.SetJavascriptBindings(bindings) subtest_message("browser.SetJavascriptBindings() ok") # Enable accessibility browser.SetAccessibilityState(cef.STATE_ENABLED) subtest_message("cef.SetAccessibilityState(STATE_ENABLED) ok") # Client handlers client_handlers = [ LoadHandler(self, g_datauri), DisplayHandler(self), RenderHandler(self) ] for handler in client_handlers: browser.SetClientHandler(handler) # Initiate OSR rendering browser.SendFocusEvent(True) browser.WasResized() # Test selection on_load_end(select_h1_text, browser) # Message loop run_message_loop() # Close browser and clean reference browser.CloseBrowser(True) del browser subtest_message("browser.CloseBrowser() ok") # Give it some time to close before checking asserts # and calling shutdown. do_message_loop_work(25) # Asserts before shutdown # noinspection PyTypeChecker check_auto_asserts(self, [] + client_handlers + [global_handler, accessibility_handler]) # Test shutdown of CEF cef.Shutdown() subtest_message("cef.Shutdown() ok") # Display summary show_test_summary(__file__) sys.stdout.flush()
def test_main(self): """Main entry point.""" # All this code must run inside one single test, otherwise strange # things happen. print("") print("CEF Python {ver}".format(ver=cef.__version__)) print("Python {ver}".format(ver=sys.version[:6])) # Test initialization of CEF settings = { "debug": False, "log_severity": cef.LOGSEVERITY_ERROR, "log_file": "", } if "--debug" in sys.argv: settings["debug"] = True settings["log_severity"] = cef.LOGSEVERITY_INFO cef.Initialize(settings) subtest_message("cef.Initialize() ok") # Test global handler global_handler = GlobalHandler(self) cef.SetGlobalClientCallback("OnAfterCreated", global_handler._OnAfterCreated) subtest_message("cef.SetGlobalClientCallback() ok") # Test creation of browser browser = cef.CreateBrowserSync(url=g_datauri) self.assertIsNotNone(browser, "Browser object") subtest_message("cef.CreateBrowserSync() ok") # Test other handlers: LoadHandler, DisplayHandler etc. client_handlers = [LoadHandler(self), DisplayHandler(self)] for handler in client_handlers: browser.SetClientHandler(handler) subtest_message("browser.SetClientHandler() ok") # Test javascript bindings external = External(self) bindings = cef.JavascriptBindings(bindToFrames=False, bindToPopups=False) bindings.SetFunction("test_function", external.test_function) bindings.SetProperty("test_property1", external.test_property1) bindings.SetProperty("test_property2", external.test_property2) # Property with a function value can also be bound. CEF Python # supports passing functions as callbacks when called from # javascript, and as a side effect any value and in this case # a property can also be a function. bindings.SetProperty("test_property3_function", external.test_property3_function) bindings.SetProperty("cefpython_version", cef.GetVersion()) bindings.SetObject("external", external) browser.SetJavascriptBindings(bindings) subtest_message("browser.SetJavascriptBindings() ok") # Run message loop for some time. # noinspection PyTypeChecker for i in range(MESSAGE_LOOP_RANGE): cef.MessageLoopWork() time.sleep(0.01) subtest_message("cef.MessageLoopWork() ok") # Test browser closing. Remember to clean reference. browser.CloseBrowser(True) del browser subtest_message("browser.CloseBrowser() ok") # Give it some time to close before calling shutdown. # noinspection PyTypeChecker for i in range(25): cef.MessageLoopWork() time.sleep(0.01) # Automatic check of asserts in handlers and in external for obj in [] + client_handlers + [global_handler, external]: test_for_True = False # Test whether asserts are working correctly for key, value in obj.__dict__.items(): if key == "test_for_True": test_for_True = True continue if "_True" in key: self.assertTrue( value, "Check assert: " + obj.__class__.__name__ + "." + key) subtest_message(obj.__class__.__name__ + "." + key.replace("_True", "") + " ok") elif "_False" in key: self.assertFalse( value, "Check assert: " + obj.__class__.__name__ + "." + key) subtest_message(obj.__class__.__name__ + "." + key.replace("_False", "") + " ok") self.assertTrue(test_for_True) # Test shutdown of CEF cef.Shutdown() subtest_message("cef.Shutdown() ok") # Display real number of tests there were run print("\nRan " + str(g_subtests_ran) + " sub-tests in test_main") sys.stdout.flush()
def __init__(self, url=None, popup=False): if popup: title = "Popup" else: title = "Ardublockly" wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, title=title) size = (1250, 768) # This is an optional code to enable High DPI support. if (g_platform_os == "windows") \ and ("auto_zooming" in g_applicationSettings) \ and (g_applicationSettings["auto_zooming"] == "system_dpi"): # This utility function will adjust width/height using # OS DPI settings. For 800/600 with Win7 DPI settings # being set to "Larger 150%" will return 1200/900. size = cefpython.DpiAware.CalculateWindowSize(size[0], size[1]) self.SetSize(size) # On mac the cefpython.Shutdown() has to be place in the onClose method. # So, the number of opened windows has to be tracked/ if g_platform_os == "mac": global g_countWindows g_countWindows += 1 if not url: url = g_ardu_link # Cannot attach browser to the main frame as the menu won't work. # Also have to set wx.WANTS_CHARS style for all parent panels/controls self.mainPanel = wx.Panel(self, style=wx.WANTS_CHARS) # Global client callbacks must be set before browser is created. self.clientHandler = ClientHandler() cefpython.SetGlobalClientCallback( "OnCertificateError", self.clientHandler._OnCertificateError) cefpython.SetGlobalClientCallback( "OnBeforePluginLoad", self.clientHandler._OnBeforePluginLoad) cefpython.SetGlobalClientCallback("OnAfterCreated", self.clientHandler._OnAfterCreated) windowInfo = cefpython.WindowInfo() (width, height) = self.mainPanel.GetClientSizeTuple() windowInfo.SetAsChild(self.GetHandleForBrowser(), [0, 0, width, height]) self.browser = cefpython.CreateBrowserSync( windowInfo, browserSettings=g_browserSettings, navigateUrl=url) self.clientHandler.mainBrowser = self.browser self.browser.SetClientHandler(self.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] ]) self.javascriptExternal = JavascriptExternal(self.browser) jsBindings.SetObject("external", self.javascriptExternal) self.browser.SetJavascriptBindings(jsBindings) self.mainPanel.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) self.mainPanel.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_CLOSE, self.OnClose) if USE_EVT_IDLE and not popup: # Bind EVT_IDLE only for the main application frame. print(g_ardutag + "Using EVT_IDLE to execute the CEF message loop work") self.Bind(wx.EVT_IDLE, self.OnIdle) main_sizer = wx.BoxSizer(wx.VERTICAL) # Only add the menubar to the main application frame if not popup: self.CreateMenu() main_sizer.Add(self.menubar, proportion=0, flag=wx.ALL | wx.ALIGN_TOP | wx.EXPAND, border=0) main_sizer.Add(self.mainPanel, proportion=1, flag=wx.ALL | wx.ALIGN_TOP | wx.EXPAND, border=0) self.SetSizer(main_sizer) main_sizer.Layout()
# print ("JS Console Message : {0}".format(message)) if __name__ == "__main__": # start_falcon() # Here we could initialise the Falcon API. But we turn it off for the time being # Later to bring it back, we'd need to think more about how it works server = http.server.HTTPServer(('127.0.0.1', 4000), http.server.SimpleHTTPRequestHandler) serverThread = threading.Thread(target=server.serve_forever, args=()) serverThread.daemon = True serverThread.start() sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error cef.SetGlobalClientCallback("OnAfterCreated", browser_on_after_created) cef.Initialize(settings={"remote_debugging_port": 49155}) #TODO(elliot) : Version numbering (automatic) browser = cef.CreateBrowserSync( url='http://127.0.0.1:{0}/rulr-web/html/index.html'.format( server.server_port), window_title="Rulr", settings={ "application_cache_disabled": True # "web_security_disabled" : True }) clientHandler = ClientHandler() browser.SetClientHandler(clientHandler)
def __init__(self, url=None, popup=False): global server_port if popup: title = "wxPython Popup" else: title = "wxPython CEF 3 example" wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, title=title) size = (800, 600) # This is an optional code to enable High DPI support. if "auto_zooming" in g_applicationSettings \ and g_applicationSettings["auto_zooming"] == "system_dpi": # This utility function will adjust width/height using # OS DPI settings. For 800/600 with Win7 DPI settings # being set to "Larger 150%" will return 1200/900. size = cefpython.DpiAware.CalculateWindowSize(size[0], size[1]) self.SetSize(size) if not url: #url = "file://"+GetApplicationPath("temp.html") url = "http://localhost:%s" % (server_port) # Test hash in url. # url += "#test-hash" if TEST_EMBEDDING_IN_PANEL: print("Embedding in a wx.Panel!") # You also have to set the wx.WANTS_CHARS style for # all parent panels/controls, if it's deeply embedded. self.mainPanel = wx.Panel(self, style=wx.WANTS_CHARS) # Global client callbacks must be set before browser is created. self.clientHandler = ClientHandler() cefpython.SetGlobalClientCallback( "OnCertificateError", self.clientHandler._OnCertificateError) cefpython.SetGlobalClientCallback( "OnBeforePluginLoad", self.clientHandler._OnBeforePluginLoad) cefpython.SetGlobalClientCallback("OnAfterCreated", self.clientHandler._OnAfterCreated) windowInfo = cefpython.WindowInfo() windowInfo.SetAsChild(self.GetHandleForBrowser()) self.browser = cefpython.CreateBrowserSync( windowInfo, browserSettings=g_browserSettings, navigateUrl=url) self.clientHandler.mainBrowser = self.browser self.browser.SetClientHandler(self.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] ]) self.javascriptExternal = JavascriptExternal(self.browser) jsBindings.SetObject("external", self.javascriptExternal) jsBindings.SetProperty("sources", GetSources()) self.browser.SetJavascriptBindings(jsBindings) if self.mainPanel: self.mainPanel.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) self.mainPanel.Bind(wx.EVT_SIZE, self.OnSize) else: self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_CLOSE, self.OnClose) if USE_EVT_IDLE and not popup: # Bind EVT_IDLE only for the main application frame. print("Using EVT_IDLE to execute the CEF message loop work") self.Bind(wx.EVT_IDLE, self.OnIdle)