wxpythoncefpython

How to bind cefpython browser object to BoxSizer in wxpython?


I have created custom maximize frame using wxpython. On the panel top, custom close button and bottom cefpython browser need to be a contains. To separation, I have used BoxSizer. CreateBrowserSync is returning the browser object so for this reason, I am getting the error.

error:

[CEF Python] ExceptHook: catched exception, will shutdown CEF

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/wx/core.py", line 2116, in Notify
    self.notify()
  File "/usr/local/lib/python2.7/dist-packages/wx/core.py", line 3245, in Notify
    self.result = self.callable(*self.args, **self.kwargs)
  File "wxpython.py", line 162, in embed_browser
    self.sizer.Add(self.browser, 1, wx.EXPAND)
TypeError: Sizer.Add(): arguments did not match any overloaded call:
  overload 1: argument 1 has unexpected type 'cefpython_py27.PyBrowser'
  overload 2: argument 1 has unexpected type 'cefpython_py27.PyBrowser'
  overload 3: argument 1 has unexpected type 'cefpython_py27.PyBrowser'
  overload 4: argument 1 has unexpected type 'cefpython_py27.PyBrowser'
  overload 5: argument 1 has unexpected type 'cefpython_py27.PyBrowser'
  overload 6: argument 1 has unexpected type 'cefpython_py27.PyBrowser'
  overload 7: argument 1 has unexpected type 'cefpython_py27.PyBrowser'
  overload 8: argument 1 has unexpected type 'cefpython_py27.PyBrowser'
  overload 9: argument 1 has unexpected type 'cefpython_py27.PyBrowser'

code

  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(),
                               [1, 1, width, height])

        self.browser = cef.CreateBrowserSync(window_info,
                                             url="https://www.google.com/")

self.sizer = wx.BoxSizer(wx.VERTICAL) 
    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.sizer.Add(closeBtn, 0, wx.ALIGN_RIGHT | wx.ALL)
    sizer.Add(self.browser, 1, wx.EXPAND)
    self.SetSizer(sizer)

How to bind cefpython browser object to BoxSizer in wxpython. Please let me know if any other alternative solution.


Solution

  • The self.browser variable contains a Python object, but BoxSizer.Add method expects as first argument a Widget (panel, window, etc).

    Change this line:

    sizer.Add(self.browser, 1, wx.EXPAND)
    

    To this:

    sizer.Add(self.browser_panel, 1, wx.EXPAND)