Why does not my wx.html.HtmlWindow work?

L

liqfemail

Below are my source code:

import wx
import wx.html

class MyHtmlFrame(wx.Frame):

def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(600,400))
html = wx.html.HtmlWindow (self)
if "gtk2" in wx.PlatformInfo:
html.SetStandardFonts()
html.LoadPage(" http://www.pythonthreads.com/articles/python/incorporating-into-wxpython-part-1.html")

app = wx.PySimpleApp()
frm = MyHtmlFrame(None, "Simple HTML Browser")
frm.Show()
app.MainLoop()

It is just an example in the book "wxPython in action". But every time
when I try to get it run, my CPU is fully occupied, and there is no
frame that comes into existence. Why?
 
R

Rob Williscroft

(e-mail address removed) wrote in
in
comp.lang.python:
Below are my source code:

import wx
import wx.html

class MyHtmlFrame(wx.Frame):

def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(600,400))
html = wx.html.HtmlWindow (self)
if "gtk2" in wx.PlatformInfo:
html.SetStandardFonts()
html.LoadPage("
http://www.pythonthreads.com/articles/python/incorporating-into
-wxpython-part-1.html")

app = wx.PySimpleApp()
frm = MyHtmlFrame(None, "Simple HTML Browser")
frm.Show()
app.MainLoop()

It is just an example in the book "wxPython in action". But every time
when I try to get it run, my CPU is fully occupied, and there is no
frame that comes into existence. Why?

I think your problem is that you call LoadPage before app.MainLoop() is
called, IOW you need to call LoadPage in an event handler:

import wx
import wx.html

class MyHtmlFrame(wx.Frame):

HOME = "http://www.google.co.uk"

def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(600,400))
self.html = wx.html.HtmlWindow (self)
if "gtk2" in wx.PlatformInfo:
self.html.SetStandardFonts()
self.done_show = False
wx.EVT_IDLE( self, self.OnShow )
self.html.SetPage(
"<a href='%s'>Loading ...</a>" % self.HOME
)

def OnShow( self, event ):
if self.done_show:
return
self.done_show = True
self.html.LoadPage( self.HOME )

app = wx.PySimpleApp()
frm = MyHtmlFrame(None, "Simple HTML Browser")
frm.Show()
app.MainLoop()

Note: the URL you loading takes ages to show, which is why I
use: http://www.google.co.uk above.

Rob.
 
L

liqfemail

(e-mail address removed) wrote incomp.lang.python:









I think your problem is that you call LoadPage before app.MainLoop() is
called, IOW you need to call LoadPage in an event handler:

import wx
import wx.html

class MyHtmlFrame(wx.Frame):

HOME = "http://www.google.co.uk"

def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(600,400))
self.html = wx.html.HtmlWindow (self)
if "gtk2" in wx.PlatformInfo:
self.html.SetStandardFonts()
self.done_show = False
wx.EVT_IDLE( self, self.OnShow )
self.html.SetPage(
"<a href='%s'>Loading ...</a>" % self.HOME
)

def OnShow( self, event ):
if self.done_show:
return
self.done_show = True
self.html.LoadPage( self.HOME )

app = wx.PySimpleApp()
frm = MyHtmlFrame(None, "Simple HTML Browser")
frm.Show()
app.MainLoop()

Note: the URL you loading takes ages to show, which is why I
use:http://www.google.co.ukabove.

Rob.
--http://www.victim-prime.dsl.pipex.com/


To Rob Williscroft,

It works when I call LoadPage() in any event handler, though I don't
know the reason. I'll try to learn it.
Thank you.
And the example in the book "wxPython In Action" is wrong?
 
K

kyosohma

To Rob Williscroft,

It works when I call LoadPage() in any event handler, though I don't
know the reason. I'll try to learn it.
Thank you.
And the example in the book "wxPython In Action" is wrong?

I know some of the examples from the book are no longer current, but I
cannot recall if the HtmlWindow one was one of them or not. You can
ask at the wxPython users group. Robin Dunn (one of the authors of the
book) is one of the moderators there. http://wxpython.org/maillist.php

I recommend using the examples in the wxPython Demo as they are
usually the most current.

Mike
 
J

Jorgen Bodde

Hi,

Coming from the wx community, I do know that the wx.HtmlWindow is NOT
meant to load full blown web pages with. It has no concept of
javascript, CSS, and other complex DOM properties.

If you really want to display complex web pages in a window, look at
wxMozilla or the wxIE binding.

So the reason it freaks out might be related to the fact the page is
too complex, or that the simplistic engine cannot cope with html tags
out in the wild.

Regards,
- Jorgen

On 7 Apr 2007 20:38:25 -0700, (e-mail address removed) wrote
Below are my source code:
[snip
html.LoadPage("
http://www.pythonthreads.com/articles/python/incorporating-into-
wxpython-part-1.html")
[snip]

Have you tried loading a simpler page, something like http://www.google.com?

-Carsten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top