IEHtmlWindow bug on Windows 7? Multiple calls to LoadString sometimes fail.

I have an IEHtmlWindow that works fine in XP but fails in Windows 7.
Here is some relevant code.

    def update(self):
        context = {'icon_path': templates.abspath('icons/busy.gif')}
        html = templates.render('generating_report.html', context)
        self.control.LoadString(html)
        util.start_thread(self._update)
    def _update(self):
        if self.info.run_report:
            content = self.info.func(self.run_id)
        else:
            content = self.info.func()
        wx.CallAfter(self.on_content, content)
    def on_content(self, content):
        self.content = content
        self.control.LoadString(content)

self.control is an IEHtmlWindow. update() displays a "Generating
report..." piece of HTML and then starts a new thread to render a
report, ultimately calling on_content which sets the final HTML. This
always seems to work the first time but I have a Refresh button in my
GUI that calls update() again and it sometimes fails to refresh and I
get a WindowsError on the ActiveX control.

This isn't the first time I've had issues with this control on Win7.

Any ideas?

If you're trying to update the GUI from a thread, then that's probably
the problem. You'll need to wrap any calls to the GUI in wx.CallAfter,
wx.CallLater or wx.PostEvent. See the following wiki page for various
solutions:

http://wiki.wxpython.org/LongRunningTasks

···

On Jul 20, 4:17 pm, FogleBird <fogle...@gmail.com> wrote:

I have an IEHtmlWindow that works fine in XP but fails in Windows 7.
Here is some relevant code.

def update\(self\):
    context = \{&#39;icon\_path&#39;: templates\.abspath\(&#39;icons/busy\.gif&#39;\)\}
    html = templates\.render\(&#39;generating\_report\.html&#39;, context\)
    self\.control\.LoadString\(html\)
    util\.start\_thread\(self\.\_update\)
def \_update\(self\):
    if self\.info\.run\_report:
        content = self\.info\.func\(self\.run\_id\)
    else:
        content = self\.info\.func\(\)
    wx\.CallAfter\(self\.on\_content, content\)
def on\_content\(self, content\):
    self\.content = content
    self\.control\.LoadString\(content\)

self.control is an IEHtmlWindow. update() displays a "Generating
report..." piece of HTML and then starts a new thread to render a
report, ultimately calling on_content which sets the final HTML. This
always seems to work the first time but I have a Refresh button in my
GUI that calls update() again and it sometimes fails to refresh and I
get a WindowsError on the ActiveX control.

This isn't the first time I've had issues with this control on Win7.

Any ideas?

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Thanks Mike, but I'm aware of that and my code snippet clearly shows
that I am using wx.CallAfter to update the GUI.

···

On Jul 21, 9:18 am, Mike Driscoll <kyoso...@gmail.com> wrote:

On Jul 20, 4:17 pm, FogleBird <fogle...@gmail.com> wrote:

> I have an IEHtmlWindow that works fine in XP but fails in Windows 7.
> Here is some relevant code.

> def update(self):
> context = {'icon_path': templates.abspath('icons/busy.gif')}
> html = templates.render('generating_report.html', context)
> self.control.LoadString(html)
> util.start_thread(self._update)
> def _update(self):
> if self.info.run_report:
> content = self.info.func(self.run_id)
> else:
> content = self.info.func()
> wx.CallAfter(self.on_content, content)
> def on_content(self, content):
> self.content = content
> self.control.LoadString(content)

> self.control is an IEHtmlWindow. update() displays a "Generating
> report..." piece of HTML and then starts a new thread to render a
> report, ultimately calling on_content which sets the final HTML. This
> always seems to work the first time but I have a Refresh button in my
> GUI that calls update() again and it sometimes fails to refresh and I
> get a WindowsError on the ActiveX control.

> This isn't the first time I've had issues with this control on Win7.

> Any ideas?

If you're trying to update the GUI from a thread, then that's probably
the problem. You'll need to wrap any calls to the GUI in wx.CallAfter,
wx.CallLater or wx.PostEvent. See the following wiki page for various
solutions:

LongRunningTasks - wxPyWiki

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Oops...sorry...I skimmed it very poorly. Well, hopefully you won't get
an idiotic answer from the next guy.

···

On Jul 21, 8:34 am, FogleBird <fogle...@gmail.com> wrote:

Thanks Mike, but I'm aware of that and my code snippet clearly shows
that I am using wx.CallAfter to update the GUI.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Upgrading from comtypes 0.6.1 to 0.6.2 seems to have resolved the
issue!

···

On Jul 21, 10:10 am, Mike Driscoll <kyoso...@gmail.com> wrote:

On Jul 21, 8:34 am, FogleBird <fogle...@gmail.com> wrote:

> Thanks Mike, but I'm aware of that and my code snippet clearly shows
> that I am using wx.CallAfter to update the GUI.

Oops...sorry...I skimmed it very poorly. Well, hopefully you won't get
an idiotic answer from the next guy.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org