[PyKDE] pykde newbie--several questions

Paul Giannaros ceruleanblaze at gmail.com
Thu Jan 4 22:09:06 GMT 2007

On Thursday 04 January 2007 21:32, Kenneth McDonald wrote:
> >> 2) It appears that pykde can access the DOM inside an HTML window in a
> >> great deal of detail. Is it possible to write pykde scripts that create
> >> an HTML window, receive events from the window, and then update the DOM
> >> of the window 'live' so that the user sees their action reflected in the
> >> contents of the window? To put it more simply, is it possible to script
> >> applications that simply use the HTML DOM as the user interface?
> >
> > I don't think KHTML exposes access to the DOM if thats what you mean.
> This PyKDE doc page in particular:
> http://www.riverbankcomputing.com/Docs/PyKDE3/classref/khtml/DOM.Node.html
> made me wonder if direct DOM access was possible. At the moment I don't
> have Kubuntu set up, so can't experiment.

Yes, it is. I do it myself fairly often. From your KHTMLPart instance you can 
access the htmlDocument() attribute and from there walk the DOM, use methods 
like getElementById/getElementsByTagName, etc. The main thing to remember is 
that when those functions ask for string input they require DOMStrings 
instead of regular strings. Quick DOMString examples:

>>> import khtml
>>> domString = khtml.DOM.DOMString("foo bar")
>>> qString = domString.string()    # the string() attribute of a DOMString 
returns a QString
>>> pythonString = str(qString)

As long as you follow the documentation and read the class information you 
should be okay.
You can also set up event handling (i.e catch an onclick event on a button or 
link and then run some Python code), though that's a little more involved. I 
can give you an example if you'd like.

> Thanks,
> Ken
> _______________________________________________
> PyKDE mailing list    PyKDE at mats.imk.fraunhofer.de
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

More information about the PyQt mailing list