HTML2 and SetPage

675 views
Skip to first unread message

tsmorton

unread,
Jul 8, 2012, 2:15:49 PM7/8/12
to wxpytho...@googlegroups.com
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 

Robin Dunn

unread,
Jul 9, 2012, 1:46:48 AM7/9/12
to wxpytho...@googlegroups.com
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

unread,
Jun 18, 2013, 3:38:27 PM6/18/13
to wxpytho...@googlegroups.com
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 = '''<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map-canvas { height: 100% }
    </style>
    <script type="text/javascript"
    </script>
    <script type="text/javascript">
      function initialize() {
        var mapOptions = {
          center: new google.maps.LatLng(-34.397, 150.644),
          zoom: 8,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map-canvas"),
            mapOptions);
      }
      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>
  <body>
    <div id="map-canvas"/>
  </body>
</html>
'''

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("<html><body>Hello World</body></html>", "")
    #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?

Robin Dunn

unread,
Jun 19, 2013, 1:41:16 PM6/19/13
to wxpytho...@googlegroups.com
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.

Brian Salter

unread,
Jun 19, 2013, 1:56:18 PM6/19/13
to wxpytho...@googlegroups.com
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 

Robin Dunn

unread,
Jun 19, 2013, 9:25:09 PM6/19/13
to wxpytho...@googlegroups.com
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. ;-)

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.

Brian Salter

unread,
Jun 21, 2013, 4:14:36 PM6/21/13
to wxpytho...@googlegroups.com
Will do, and thanks for the info!
Reply all
Reply to author
Forward
0 new messages