wxpythoncefpython

How to bind cefpython on the panel(wxpython)?


Below specified code for wxpython GUI where you can observe I have used the wx.html2.WebView to render the web on the panel. Is it possible to replace from webview to cefpython for the same code?

I also got the cefpython code that was launching its own frame. I don't want to be open with its own frame instead of that it binds on wxpython panel. You can see the cefpython code below.

1.wxpython GUI Code

import wx
import sys
import wx.html2 

def main(args):
    app = CefApp(False, args)
    app.MainLoop()

class MainPanel(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent=parent)
        self.frame = parent

        sizer = wx.BoxSizer(wx.VERTICAL) 
        self.wv = wx.html2.WebView.New(self)
        closeBtn = wx.Button(self, label="X", size=(30, 30))
        closeBtn.Bind(wx.EVT_BUTTON, self.onClose)
        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox= wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add(closeBtn, 0, flag=wx.ALIGN_RIGHT | wx.ALL)
        vbox.Add(hbox, 0, flag=wx.ALIGN_RIGHT | wx.ALL)
        self.SetSizer(vbox)
        vbox.SetSizeHints(self)
        self.SetWindowStyle(wx.STAY_ON_TOP)

        sizer.Add(closeBtn, 0, wx.ALIGN_RIGHT | wx.ALL)
        sizer.Add(self.wv, 1, wx.EXPAND)
        self.SetSizer(sizer)

        self.wv.LoadURL("http://google.com")

    def onClose(self, event):
        dlg = DialogBox()
        dlg.ShowModal()

class MyFrame(wx.Frame):

    def __init__(self, args):
        wx.Frame.__init__(self, None, title="ESSB Demo")
        self.url = args
        self.browser_panel = MainPanel(self)
        self.ShowFullScreen(True)

2.CefPython Code.

from cefpython3 import cefpython as cef
import platform
import sys


def main():
    sys.excepthook = cef.ExceptHook  # To shutdown all CEF processes on error
    cef.Initialize()
    cef.CreateBrowserSync(url="https://www.google.com/")
    cef.MessageLoop()
    cef.Shutdown()

Please advice.


Solution

  • The cefpython code you provided comes from the hello_wordl.py example. That example does not support wxpython. Example of embedding CEF browser in a wxpython application inside a panel is available in the wxpython.py example:

    https://github.com/cztomczak/cefpython/blob/master/examples/wxpython.py