[Pyxpcomext] Display and Rendering Question

Todd Whiteman twhitema at yahoo.com.au
Thu Feb 25 10:34:34 PST 2010

On 10-02-25 09:38 AM, Nathan Hamiel wrote:
> I have a couple of questions about the display and rendering of HTML 
> using XUL with Python. For example in my XULrunner application, I want 
> to construct a request using httplib or httplib2 and display the 
> return data in both HTML source as well as rendered HTML.
> So I would have something like so:
> urlval = "http://python.org"
> handler = httplib2.Http()
> resp, content = handler.request(urlval, "GET")
> I have some tabpanels set up with vbox's on them. What I would like to 
> do after the request for this content is made is take the content 
> value, which contains the HTML of the return response, and on one 
> panel display the HTML source (preferably syntax highlighted) and on 
> other panel render the HTML. It shouldn't matter how the HTML is 
> retrieved though since at some point it may be pulled from something 
> such as a SQLite database or other storage mechanism.
> I am not sure of the best way to go about this. If there are any 
> examples or documentation anyone can point me to, it would be greatly 
> appreciated. Sorry if the answer is painfully obvious and there is 
> something I am just not getting.
> I have even tried to use the browser object by instantiating it like so:
> In my XUL file I have:
> <browser id="browser" src="about:blank" flex="1" />
> In my .py file I have:
> browser = document.getElementById("browser")
> However, when trying to use this an to say reload an error like so 
> happens:
> XPCOM component '<unknown>' has no attribute 'reload'
> Anyway, I am stumped and I figured I would ask for help. Please let me 
> know if I need to provide more detail and I will gladly do so. Thanks 
> in advance.

It's because <browser> is a XBL element and XBL elements are generally 
not exposed through XPCOM. You can check the implements section of:

that means these XBL properties/methods like "reload", "goBack", 
"autoscrollEnabled" are not exposed to XPCOM, so if you try to use them 
via XPCOM you'll get an attribute error like the one above.

You'll need to use JavaScript to obtain access to these methods. For 
Python/XPCOM, you'd need to write a JavaScript XPCOM wrapper that 
exposes the browser functionality you need, so Python would call your JS 
XPCOM browser component and then the JS component would call the XBL 
browser methods.


More information about the Pyxpcomext mailing list