I was able to replicate the issue on Windows 10. The reason I suspected it to be a OS-specific issue is that since it’s a MS component, and since Win7 has moved into the end-of-support stage, there’s a (slim) chance that there is some API that isn’t able to be implemented on Win7, or some issue like that.
However I do see it on Win10 so that rules out that idea. It is definitely weird. For me it varies somewhat which tab is successfully loaded and which is not. That made me think that perhaps there is some sort of timing issue due to creating all the webviews at the same time. I experimented a little and found that delaying the creation of the notebook pages a little bit, and only doing one at a time, solves the problem. One possibility is that at least part of the Edge component’s creation is asynchronous and is done in follow up events, so trying to make a new one immediately after the first WebView.New
returns is messing things up internally.
Here is my tweaked version of your sample:
import wx
import wx.html2 as webview
from wx.lib.inspection import InspectionTool
from wx.lib.agw.flatnotebook import FlatNotebook
NotebookClass = wx.Notebook
# NotebookClass = FlatNotebook
# BACKEND = webview.WebViewBackendDefault
BACKEND = webview.WebViewBackendEdge
class DVHAMainFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.notebook_main_view = NotebookClass(self, wx.ID_ANY)
self.tab_keys = ['Browser 1', 'Browser 2', 'Browser 3']
delay = 0
for key in self.tab_keys:
wx.CallLater(delay, self.make_page, key)
delay += 50
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.notebook_main_view, 1, wx.EXPAND, 0)
self.SetSizer(sizer)
self.Layout()
self.Center()
def make_page(self, title):
page = wx.Panel(self.notebook_main_view)
plot = webview.WebView.New(page, backend=BACKEND)
plot.LoadURL("http://www.google.com")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(plot, 1, wx.EXPAND)
page.SetSizer(sizer)
self.notebook_main_view.AddPage(page, title)
class MainApp(wx.App):
def OnInit(self):
self.SetAppName('DVH Analytics')
self.frame = DVHAMainFrame(None, wx.ID_ANY, "", size=(800,600))
self.SetTopWindow(self.frame)
# InspectionTool().Show()
self.frame.Show()
return True
def start():
app = MainApp()
app.MainLoop()
if __name__ == "__main__":
start()