HTML2 and SetPage

I am trying the new html2 control with my app in place of htmlWindow and it works pretty good except SetPage() appends to a page instead of replacing the content on a page. I found where this is a bug in wxWidgets, http://trac.wxwidgets.org/ticket/13770, but when will this fix be available in wxPython, or is there a simple workaround?

Thanks,
Tim

Give the latest 2.9.4 preview build a try: https://groups.google.com/d/topic/wxpython-dev/6K4-EnGiHPI/discussion

···

On 7/8/12 11:15 AM, tsmorton wrote:

I am trying the new html2 control with my app in place of htmlWindow and
it works pretty good except SetPage() appends to a page instead of
replacing the content on a page. I found where this is a bug in
wxWidgets, wxTrac has been migrated to GitHub Issues - wxWidgets, but when will this
fix be available in wxPython, or is there a simple workaround?

--
Robin Dunn
Software Craftsman

Interestingly (Well, to me, anyway!), SetPage() now seems to only work for simple pages. Is there some magic I’m missing? Here’s the code:

import wx

import wx.html2

data = ‘’'

html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map-canvas { height: 100% }

‘’’

class AppFrame(wx.Frame):

def init(self, parent):

super(AppFrame, self).init(parent, size=(500,500))

self.html_view = wx.html2.WebView.New(self)

sizer = wx.BoxSizer(wx.VERTICAL)

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

self.SetSizer(sizer)

if name == ‘main’:

app = wx.App()

frame = AppFrame(None)

#Example 1: Works fine! ============================================

frame.html_view.SetPage(“Hello World”, “”)

#Example 2: Works fine! ============================================

#frame.html_view.LoadURL(‘file://c:/python26/tst_map_page3.html’)

#Example 3: Doesn’t work!!! ========================================

#frame.html_view.SetPage(data, ‘http://maps.google.com/maps/api’)

frame.Show()

app.MainLoop()

When I do a SetPage to some very simple html, no problem. When I LoadURL from a file, no problem. But when I try to SetPage to the very same html that’s in the file, I get nothing. I’ve tried various values for the second parameter, but it doesn’t seem to matter. Any ideas?

···

On Sunday, July 8, 2012 10:46:48 PM UTC-7, Robin Dunn wrote:

On 7/8/12 11:15 AM, tsmorton wrote:

I am trying the new html2 control with my app in place of htmlWindow and

it works pretty good except SetPage() appends to a page instead of

replacing the content on a page. I found where this is a bug in

wxWidgets, http://trac.wxwidgets.org/ticket/13770, but when will this

fix be available in wxPython, or is there a simple workaround?

Give the latest 2.9.4 preview build a try:
https://groups.google.com/d/topic/wxpython-dev/6K4-EnGiHPI/discussion


Robin Dunn

Software Craftsman

http://wxPython.org

Brian Salter wrote:

Interestingly (Well, to me, anyway!), SetPage() now seems to only work
for simple pages. Is there some magic I'm missing? Here's the code:

[...]

When I do a SetPage to some very simple html, no problem. When I LoadURL
from a file, no problem. But when I try to SetPage to the very same html
that's in the file, I get nothing. I've tried various values for the
second parameter, but it doesn't seem to matter. Any ideas?

It works fine here (OSX, wx 2.95 preview build). Since it appears you are on windows then I'm going to blame the IE control that is being used to render the WebView content. Perhaps the Google JS code is expecting to find some feature or resource on IE that it is not providing in this context, or something like that.

The baseUrl parameter is use for constructing full URLs from a relative URI for additional resources loaded from the page, like images. Your document doesn't have any relative resources, so it probably doesn't matter at all in this case.

Have you noticed this problem with any other "complex" pages? Any that don't involve loading JS code or other resources from a 3rd party website?

As you can probably tell I am guessing a little here. You will be able to reach the people who know this code better via the wx-users mail list.

···

--
Robin Dunn
Software Craftsman

I think you missed a bit there, Robin… I’d expect to be able to blame the IE backend too, except

that it works flawlessly when used with LoadURL. (Well, flawlessly except that it doesn’t support

HTML5 canvasses, but that’s ANOTHER problem! grin) No, I expect that this is a problem in how

SetPage hands the data over to the HTML2 widget, but it beats me why it wouldn’t happen nearly

the same way that it works with LoadURL. It’s almost as though SetPage is doing some kind of

filtering on the data, above what LoadURL does.

Brian

···

On Wednesday, June 19, 2013 10:41:16 AM UTC-7, Robin Dunn wrote:

Brian Salter wrote:

Interestingly (Well, to me, anyway!), SetPage() now seems to only work

for simple pages. Is there some magic I’m missing? Here’s the code:

[…]

When I do a SetPage to some very simple html, no problem. When I LoadURL

from a file, no problem. But when I try to SetPage to the very same html

that’s in the file, I get nothing. I’ve tried various values for the

second parameter, but it doesn’t seem to matter. Any ideas?

It works fine here (OSX, wx 2.95 preview build). Since it appears you
are on windows then I’m going to blame the IE control that is being used
to render the WebView content. Perhaps the Google JS code is expecting
to find some feature or resource on IE that it is not providing in this
context, or something like that.

The baseUrl parameter is use for constructing full URLs from a relative
URI for additional resources loaded from the page, like images. Your
document doesn’t have any relative resources, so it probably doesn’t
matter at all in this case.

Have you noticed this problem with any other “complex” pages? Any that
don’t involve loading JS code or other resources from a 3rd party website?

As you can probably tell I am guessing a little here. You will be able
to reach the people who know this code better via the wx-users mail list.


Robin Dunn

Software Craftsman

http://wxPython.org

Brian Salter wrote:

I think you missed a bit there, Robin... I'd expect to be able to blame
the IE backend too, except
that it works flawlessly when used with LoadURL. (Well, flawlessly
except that it doesn't support
HTML5 canvasses, but that's ANOTHER problem! *grin*) No, I expect that
this is a problem in how
SetPage hands the data over to the HTML2 widget, but it beats me why it
wouldn't happen nearly
the same way that it works with LoadURL. It's almost as though SetPage
is doing some kind of
filtering on the data, above what LoadURL does.

I didn't miss it, but it didn't fully sink in. :wink:

Glancing at the code it looks like the difference between LoadURL and SetPage is that LoadURL simply calls the IE control's Navigate method and SetPage gets a pointer to the view's IHTMLDocument and calls document->write. So they are quite different code paths.

You should ask about this on wx-users or create a ticket at trac.wxwidgets.org, the folks who have a better understanding of the webview classes will see it there.

···

--
Robin Dunn
Software Craftsman

Will do, and thanks for the info!

···

On Wednesday, June 19, 2013 6:25:09 PM UTC-7, Robin Dunn wrote:

Brian Salter wrote:

I think you missed a bit there, Robin… I’d expect to be able to blame

the IE backend too, except

that it works flawlessly when used with LoadURL. (Well, flawlessly

except that it doesn’t support

HTML5 canvasses, but that’s ANOTHER problem! grin) No, I expect that

this is a problem in how

SetPage hands the data over to the HTML2 widget, but it beats me why it

wouldn’t happen nearly

the same way that it works with LoadURL. It’s almost as though SetPage

is doing some kind of

filtering on the data, above what LoadURL does.

I didn’t miss it, but it didn’t fully sink in. :wink:

Glancing at the code it looks like the difference between LoadURL and
SetPage is that LoadURL simply calls the IE control’s Navigate method
and SetPage gets a pointer to the view’s IHTMLDocument and calls
document->write. So they are quite different code paths.

You should ask about this on wx-users or create a ticket at
trac.wxwidgets.org, the folks who have a better understanding of the
webview classes will see it there.


Robin Dunn

Software Craftsman

http://wxPython.org