On Friday 17 March 2006 10:21, Ismail Donmez wrote:
> Hi all,
>
> I am using khtml in my PyKDE app ( which rocks btw ) , two minor problems
> appear, I have to use stuff like
>
> document = self.htmlPart.document()
> document.getElementsByTagName(DOM.DOMString("input"))
>
> would it be possible to write it like
> document = self.htmlPart.document()
> document.getElementsByTagName("input")
>
> which means a auto-conversion between DOMString & str.

I'm not clear if you want auto-conversion for a single method, or PyKDE-wide 
auto-conversion. In either case, I think I'd probably give the same answer. 
There are probably several hundred khtml methods that take DOM.DOMString as 
an argument. Conversion could be done with handwritten code, but that's a 
considerable amount to generate and maintain. There might be some other way 
to do it that's workable - I'd have to give that some thought.

In the meantime, the easiest way to handle it would be to subclass (in Python) 
the class that contains the method(s). For example:

class PyHtmlDocument (DOM.HTMLDocument):
        def getElementsByTagName (self, pyString):
                return DOM.HTMLDocument.getElementsByTagName (self, 
                               DOM.DOMString (pyString))

> Also is there a way to handle C++ exceptions in Python ? Because per DOM
>  spec khtml throws exceptions in DOM code which results in a crash
>  because I can't handle it as a Python exception.

In configure.py, generate_code (), add:

if mname == "khtml":
        argv.append("-e")

That should generate Python exceptions for any C++ exceptions anywhere in 
khtml. I'll modify configure.py to do that for the next release.

Jim

_______________________________________________
PyKDE mailing list    [email protected]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Reply via email to