如何在wxpython中将cefpython浏览器对象绑定到BoxSizer?

时间:2018-04-03 05:55:25

标签: wxpython cefpython

我使用wxpython创建了自定义最大化框架。在面板顶部,自定义关闭按钮和底部cefpython浏览器需要是一个包含。为了分离,我使用了BoxSizer。 CreateBrowserSync返回浏览器对象,因此我收到错误。

错误:

[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'

  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)

如何在wxpython中将cefpython浏览器对象绑定到BoxSizer。如果有其他替代解决方案,请告诉我。

1 个答案:

答案 0 :(得分:1)

self.browser变量包含一个Python对象,但BoxSizer.Add方法需要第一个参数为Widget(面板,窗口等)。

更改此行:

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

对此:

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