HTML Rendering

I was wondering if there was a way to use the platforms default browser to render HTML inside a wxPython window. I know there is wxHtmlWindow, but I would like some more features primarily CSS support for what I am doing and in my peliminary tests CSS does not work nor does using the style attribute (eg. or .) I know for this example I could just do font color= but there are more advanced thing I want to do that are much easyer with CSS especialy if I want the end users to be able to custimize thier view.

~Dj Gilcrease

Yes, there is wx.IEHtmlWindow for PC, wx.webkit for Mac and another project for Mozilla browser that is GPL on Sourceforge. The first two are in the the pydocs. You'd have to go to wxMozilla to find out more about this if you wanted integration since it would be an add on.

Regards,
David

Dj Gilcrease wrote:

···

I was wondering if there was a way to use the platforms default browser to render HTML inside a wxPython window. I know there is wxHtmlWindow, but I would like some more features primarily CSS support for what I am doing and in my peliminary tests CSS does not work nor does using the style attribute (eg. <font style="color: #800080;"> or <font class="test">.) I know for this example I could just do font color= but there are more advanced thing I want to do that are much easyer with CSS especialy if I want the end users to be able to custimize thier view.

Thanks, from looking at the Mozilla project it still isnt fully crossplatform compatible, and obviously webkit and IEHtmlWindow are not. Guess I will talk to the people at wxMozilla to see how the project is coming along.

···

On 2/1/06, David Pratt fairwinds@eastlink.ca wrote:

Yes, there is wx.IEHtmlWindow for PC, wx.webkit for Mac and another
project for Mozilla browser that is GPL on Sourceforge. The first two

are in the the pydocs. You’d have to go to wxMozilla to find out more
about this if you wanted integration since it would be an add on.

Regards,
David

Dj Gilcrease wrote:

I was wondering if there was a way to use the platforms default browser

to render HTML inside a wxPython window. I know there is wxHtmlWindow,
but I would like some more features primarily CSS support for what I am
doing and in my peliminary tests CSS does not work nor does using the

style attribute (eg. or .) I know for this example I could just do font color= but
there are more advanced thing I want to do that are much easyer with CSS

especialy if I want the end users to be able to custimize thier view.

~Dj Gilcrease


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org


Dj Gilcrease
OpenRPG Developer
~~http://www.openrpg.com
OpenRPG++ Lead Developer
~~http://winopenrpg.sf.net
Web Admin for
Thewarcouncil.us

~~http://www.thewarcouncil.us

Ok in my search of CSS support I have found nothing that is fully cross platform compliant or near to be so I wrote a quick and dirty way to get BASIC CSS support. I stress basic because it is limited to the attributes that the wxHTMLWindow will process for each tag, but it will do what I was looking for mostly. What it does is create two dict’s globalclasses and tagclasses. How you fill these is up to you. I have a CSS looking file I parse the info from. (I say looking since it isn’t fully CSS compliant). With this code instead of calling wnd.SetPage(htmltext) for your wxHTMLWindow you would call wnd.SetPage( css_parser(htmltext) ). I hope other’s find this useful.

from HTMLParser import HTMLParser

globalclasses = {}
globalclasses[classname] = [('bgcolor','#000000'), ('align','center'), ('blablabla','morebla')]

tagclasses = {}
tagclasses[tagname] ={}
tagclasses[tagname][classname] = [('bgcolor','#000000'), ('align','center'), ('blablabla','morebla')]

# Global parser for stripping HTML tags:
# The 'tag stripping' is implicit, because this parser echoes every

# type of html data *except* the tags.
class CSSParser(HTMLParser):
    def __init__(self):
        self.accum = ""
        self.nonclosedtags = ['br','img','hr']
        self.tags = 0

    def handle_data(self, data):  # quote cdata literally
        self.accum += data

    def handle_entityref(self, name): # entities must be preserved exactly
        self.accum += "&" + name + ";"

    def handle_starttag(self, tag, attrs):
        if tag not in self.nonclosedtags:
            self.tags += 1
        self.accum += '<' + tag
        for attrib in attrs:
            if attrib[0] == 'class':

                if globalclasses.has_key(attrib[1]):
                    for style in globalclasses[attrib[1]]:
                        self.accum += ' ' + style[0] + '="' + style[1] + '"'
                elif tagclasses.has_key(tag) and tagclasses[tag].has_key(attrib[1]):
                    for style in tagclasses[tag][attrib[1]]:
                        self.accum += ' ' + style[0] + '="' + style[1] + '"'
            else:
                self.accum += ' ' + attrib[0] + '="' + attrib[1] + '"'
        self.accum += '>'

    def handle_endtag(self, tag):
        self.tags -= 1
         self.accum
+= '</' + tag + '>'

    def handle_charref(self, name):  # charrefs too
        self.accum += "&#" + name + ";"

cssparser = CSSParser()

def css_parser(string):
    "Return string with css info added to the tags."

    cssparser.reset()
    cssparser.accum = ""
    cssparser.feed(string)
    cssparser.close()
    if cssparser.tags != 0:
        print 'Bad HTML but doing nothing about it'
    return cssparser.accum
···

On 2/1/06, Dj Gilcrease digitalxero@gmail.com wrote:

Thanks, from looking at the Mozilla project it still isnt fully crossplatform compatible, and obviously webkit and IEHtmlWindow are not. Guess I will talk to the people at wxMozilla to see how the project is coming along.

On 2/1/06, David Pratt <fairwinds@eastlink.ca > > wrote:

Yes, there is wx.IEHtmlWindow for PC, wx.webkit for Mac and another
project for Mozilla browser that is GPL on Sourceforge. The first two

are in the the pydocs. You’d have to go to wxMozilla to find out more
about this if you wanted integration since it would be an add on.

Regards,
David

Dj Gilcrease wrote:

I was wondering if there was a way to use the platforms default browser

to render HTML inside a wxPython window. I know there is wxHtmlWindow,
but I would like some more features primarily CSS support for what I am
doing and in my peliminary tests CSS does not work nor does using the

style attribute (eg. or .) I know for this example I could just do font color= but
there are more advanced thing I want to do that are much easyer with CSS

especialy if I want the end users to be able to custimize thier view.

~Dj Gilcrease


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org


Dj Gilcrease
OpenRPG Developer
~~http://www.openrpg.com
OpenRPG++ Lead Developer
~~http://winopenrpg.sf.net
Web Admin for
Thewarcouncil.us

~~http://www.thewarcouncil.us


Dj Gilcrease
OpenRPG Developer
~~http://www.openrpg.com
OpenRPG++ Lead Developer
~~http://winopenrpg.sf.net
Web Admin for
Thewarcouncil.us

~~http://www.thewarcouncil.us