Пример #1
0
    def __init__(self):
        wx.Frame.__init__(self,
                          parent=None,
                          id=wx.ID_ANY,
                          title='wxPython CEF 3 example',
                          size=(800, 600))
        self.CreateMenu()

        # Cannot attach browser to the main frame as this will cause
        # the menu not to work.
        # --
        # 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)

        windowInfo = cefpython.WindowInfo()
        windowInfo.SetAsChild(self.mainPanel.GetGtkWidget())
        # 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={"plugins_disabled": False},
            navigateUrl="file://" + GetApplicationPath("index.html"))

        clientHandler = ClientHandler()
        self.browser.SetClientHandler(clientHandler)
        cefpython.SetGlobalClientCallback("OnCertificateError",
                                          clientHandler._OnCertificateError)
        cefpython.SetGlobalClientCallback("OnBeforePluginLoad",
                                          clientHandler._OnBeforePluginLoad)

        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]
        ])
        jsBindings.SetObject("external", JavascriptExternal(self.browser))
        self.browser.SetJavascriptBindings(jsBindings)

        self.Bind(wx.EVT_CLOSE, self.OnClose)
        if USE_EVT_IDLE:
            # Bind EVT_IDLE only for the main application frame.
            self.Bind(wx.EVT_IDLE, self.OnIdle)
Пример #2
0
 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()
     print "WIndow Infor", windowInfo
     windowInfo.SetAsChild(self.winId())
     print "WIn Id", int(self.winId())
     self.browser = cefpython.CreateBrowserSync(windowInfo,
                                                browserSettings={},
                                                navigateUrl="about:None")
     self.browser.GetMainFrame().LoadUrl("http://www.google.com")
     self.clientHandler.mainBrowser = self.browser
     self.browser.SetClientHandler(self.clientHandler)
     # cefpython.MessageLoop()
     self.show()
Пример #3
0
    def loadCustumUrl(self, url):
        # self.layout = QtGui.QVBoxLayout()
        # self.killRef = QtGui.QPushButton()
        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()
Пример #4
0
    def __init__(self, url=None, popup=False, params=None):
        if popup:
            title = os.path.basename(url)
        else:
            title = "Kam1n0"
        wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, title=title)
        size = (800, 500)

        # icon
        #setup icon object
        #icon = wx.Icon(GetApplicationPath("www/img/favicon.ico"), wx.BITMAP_TYPE_ICO)

        #setup taskbar icon
        #tbicon = wx.TaskBarIcon()
        #tbicon.SetIcon(icon, "McGill Icon")
        loc = wx.IconLocation(GetApplicationPath("www/img/favicon.ico"), 0)
        self.SetIcon(wx.IconFromLocation(loc))

        # 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)

        global gdata
        if gdata is None:
            gdata = GetData()

        gdp = json.loads(gdata)

        if not url:
            url = gdp['url']
            # Test hash in url.
            # url += "#test-hash"

        # self.CreateMenu()

        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)

        self.javascriptExternal = JavascriptExternal(self.browser, gdata)
        jsBindings.SetObject("external", self.javascriptExternal)
        jsBindings.SetProperty("GData", gdata)
        if not params is None:
            jsBindings.SetProperty("params", params)
        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)
Пример #5
0
    def __init__(self, *largs, **dargs):
        super(CefBrowser, self).__init__()
        self.url = dargs.get("url", "")
        self.keyboard_mode = dargs.get("keyboard_mode", "local")
        self.resources_dir = dargs.get("resources_dir", "")
        self.keyboard_above_classes = dargs.get("keyboard_above_classes", [])
        switches = dargs.get("switches", {})
        self.__rect = None
        self.browser = None
        self.popup = CefBrowserPopup(self)

        self.register_event_type("on_loading_state_change")
        self.register_event_type("on_address_change")
        self.register_event_type("on_title_change")
        self.register_event_type("on_before_popup")
        self.register_event_type("on_load_start")
        self.register_event_type("on_load_end")
        self.register_event_type("on_load_error")
        self.register_event_type("on_certificate_error")
        self.register_event_type("on_js_dialog")
        self.register_event_type("on_before_unload_dialog")

        self.key_manager = CefKeyboardManager(cefpython=cefpython, browser_widget=self)

        self.texture = Texture.create(size=self.size, colorfmt='rgba', bufferfmt='ubyte')
        self.texture.flip_vertical()
        with self.canvas:
            Color(1, 1, 1)
            self.__rect = Rectangle(pos=self.pos, size=self.size, texture=self.texture)

        md = cefpython.GetModuleDirectory()

        # Determine if default resources dir should be used or a custom
        if self.resources_dir:
            resources = self.resources_dir
        else:
            resources = md

        def cef_loop(*largs):
            cefpython.MessageLoopWork()
        Clock.schedule_interval(cef_loop, 0)

        settings = {
                    #"debug": True,
                    "log_severity": cefpython.LOGSEVERITY_INFO,
                    #"log_file": "debug.log",
                    "persist_session_cookies": True,
                    "release_dcheck_enabled": True,  # Enable only when debugging.
                    "locales_dir_path": os.path.join(md, "locales"),
                    "browser_subprocess_path": "%s/%s" % (cefpython.GetModuleDirectory(), "subprocess")
                }
        cefpython.Initialize(settings, switches)

        windowInfo = cefpython.WindowInfo()
        windowInfo.SetAsOffscreen(0)
        cefpython.SetGlobalClientCallback("OnCertificateError", self.OnCertificateError)
        self.browser = cefpython.CreateBrowserSync(windowInfo, {}, navigateUrl=self.url)

        # Set cookie manager
        cookie_manager = cefpython.CookieManager.GetGlobalManager()
        cookie_path = os.path.join(resources, "cookies")
        cookie_manager.SetStoragePath(cookie_path, True)

        self.browser.SendFocusEvent(True)
        ch = ClientHandler(self)
        self.browser.SetClientHandler(ch)
        self.set_js_bindings()
        self.browser.WasResized()
        self.bind(size=self.realign)
        self.bind(pos=self.realign)
        self.bind(keyboard_mode=self.set_keyboard_mode)
        if self.keyboard_mode == "global":
            self.request_keyboard()
Пример #6
0
    def __init__(self,
                 parent,
                 title,
                 pos,
                 size,
                 style,
                 name,
                 url=None,
                 popup=True):

        wx.Frame.__init__(self,
                          parent=parent,
                          id=wx.ID_ANY,
                          title=title,
                          pos=pos,
                          size=size,
                          style=style,
                          name=name)
        size = (1000, 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)
        self.panel = wx.Panel(self)
        self.panel.SetBackgroundColour(wx.WHITE)
        if not url:
            url = "file://" + GetApplicationPath("example2.html")
            # Test hash in url.
            # url += "#test-hash"

        #self.CreateMenu()

        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.panel,
                                      size=(700, 635),
                                      pos=(600, 400))
        # 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=True,
                                                  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)
Пример #7
0
    def __init__(self, url=None):
        wx.Frame.__init__(self, parent=None, id=wx.ID_ANY,
                title='wxPython CEF 3 example', size=(800,600))

        global g_countWindows
        g_countWindows += 1

        if not url:
            url = "file://"+GetApplicationPath("wxpython.html")
            # Test hash in url.
            # url += "#test-hash"

        self.CreateMenu()

        # Cannot attach browser to the main frame as this will cause
        # the menu not to work.
        # --
        # 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()
        (width, height) = self.mainPanel.GetClientSizeTuple()
        windowInfo.SetAsChild(self.mainPanel.GetHandle(),
                              [0, 0, width, height])
        # 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)

        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)

        self.Bind(wx.EVT_CLOSE, self.OnClose)
        if USE_EVT_IDLE:
            # Bind EVT_IDLE only for the main application frame.
            self.Bind(wx.EVT_IDLE, self.OnIdle)