MS Edge backend fails in Notebook (other than first page)

Hi Robin,

I’m still a new user apparently, so I had to create a new topic. I have some example code illustrating my issue described in this topic.

It turns out the issue happens when using Edge in Notebook pages other than the first. In my code below, if you chagne the backend to IE, it works fine. I’ve also tried combinations where there is only one webview, and that fails with Edge if it is not in the first Notebook page.

  • Windows7
  • Edge Version 87.0.664.30 (Official build) beta (64-bit)
  • wxPython4.1.1a1.dev5044+6959fd7f-cp37-cp37m-win32.whl

Unfotunately, I don’t have a Windows 10 machine to try it on now. But this strikes me as unrelated to the OS?

import wx
import wx.html2 as webview


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 = wx.Notebook(self, wx.ID_ANY)
        self.tab_keys = ['Browser 1', 'Browser 2']

        self.notebook_tab = {key: wx.Panel(self.notebook_main_view, wx.ID_ANY) for key in self.tab_keys}
        self.plot = {key: webview.WebView.New(self.notebook_tab[key], backend=webview.WebViewBackendEdge) for key in self.tab_keys}
        for plot in self.plot.values():
            plot.LoadURL("http://www.google.com")

        notebook_sizers = {key: wx.BoxSizer(wx.VERTICAL) for key in self.tab_keys}
        for key, notebook_tab in self.notebook_tab.items():
            notebook_sizers[key].Add(self.plot[key], 1, wx.EXPAND, 0)
            notebook_tab.SetSizer(notebook_sizers[key])
            self.notebook_main_view.AddPage(self.notebook_tab[key], key)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.notebook_main_view, 1, wx.EXPAND, 0)

        self.SetSizer(sizer)
        self.Layout()
        self.Center()


class MainApp(wx.App):
    def OnInit(self):
        self.SetAppName('DVH Analytics')
        self.frame = DVHAMainFrame(None, wx.ID_ANY, "")
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True


def start():
    app = MainApp()
    app.MainLoop()


if __name__ == "__main__":
    start()

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()
1 Like

Thanks for being so quick!

Unfortunately, I can make it fail with only one browser.

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

        for key in self.tab_keys:
            func = self.make_web_page if key == self.tab_keys[-1] else self.make_text_page
            func(key)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(self.notebook_main_view, 1, wx.EXPAND, 0)

        self.SetSizer(sizer)
        self.Layout()
        self.Center()

    def make_web_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)

    def make_text_page(self, title):
        page = wx.Panel(self.notebook_main_view)
        text = wx.StaticText(page, wx.ID_ANY, "This is just text for %s" % title)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(text, 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()

Does it work if you restore the delay using wx.CallLater like in my example?

Oh I see… you did say it was a notebook creation issue. Not a webview generation issue.

The site should automatically promote you from new_user to basic_user after you’ve spent a certain amount of time on the site, entered a number of topics, and read a number of posts. From your current stats it looks like you just need to read another 10 posts or so. Let me know if the auto-promotion doesn’t happen.

1 Like

I’m still troubleshooting. I applied the wx.CallLater approach for wx.Notebook.AddPage in my original program, but that did not resolve the issue. Hopefully, I can generate additional, simple code to demonstrate this. Maybe something else in make_page has the root cause?

NOTE: This also included spacing out webview generations by 0.1s as well.