=== modified file 'doc/pykhtml.dom.htm' --- doc/pykhtml.dom.htm 2007-03-06 22:25:50 +0000 +++ doc/pykhtml.dom.htm 2007-03-15 01:46:43 +0000 @@ -46,6 +46,7 @@

childNodes (read-only property)

Inherited from Node
For those that can't live without JavaScript DOM-compatible method names.

children (read-only property)

Inherited from Node
Get a list containing the children nodes of this node. If you want to loop over children just loop over this node as with any regular list – it is more memory efficient that way.

className (property)

The class name of this element.
+

click(self, button='left', shift=False, ctrl=False)

Simluate a click on the element. You can optionally specify that a different button was clicked (defaults to "left" – can be "left", "middle", or "right") or that shift/ctrl are held down at the time of click.

getElementsByClass(self, className, tagName='*')

Get elements in the document (optionally with a given tag name) that have a certain class.

getElementsByTagName(self, name)

Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().

getElementsByTagNameNS(self, ns, name)

Get elements by tag name given a certain namespace.
@@ -69,6 +70,7 @@

childNodes (read-only property)

Inherited from Node
For those that can't live without JavaScript DOM-compatible method names.

children (read-only property)

Inherited from Node
Get a list containing the children nodes of this node. If you want to loop over children just loop over this node as with any regular list – it is more memory efficient that way.

className (property)

Inherited from Element
The class name of this element.
+

click(self, button='left', shift=False, ctrl=False)

Inherited from Element
Simluate a click on the element. You can optionally specify that a different button was clicked (defaults to "left" – can be "left", "middle", or "right") or that shift/ctrl are held down at the time of click.

getElementsByClass(self, className, tagName='*')

Inherited from Element
Get elements in the document (optionally with a given tag name) that have a certain class.

getElementsByTagName(self, name)

Inherited from Element
Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().

getElementsByTagNameNS(self, ns, name)

Inherited from Element
Get elements by tag name given a certain namespace.
@@ -94,6 +96,7 @@

childNodes (read-only property)

Inherited from Node
For those that can't live without JavaScript DOM-compatible method names.

children (read-only property)

Inherited from Node
Get a list containing the children nodes of this node. If you want to loop over children just loop over this node as with any regular list – it is more memory efficient that way.

className (property)

Inherited from Element
The class name of this element.
+

click(self, button='left', shift=False, ctrl=False)

Inherited from Element
Simluate a click on the element. You can optionally specify that a different button was clicked (defaults to "left" – can be "left", "middle", or "right") or that shift/ctrl are held down at the time of click.

getElementsByClass(self, className, tagName='*')

Inherited from Element
Get elements in the document (optionally with a given tag name) that have a certain class.

getElementsByTagName(self, name)

Inherited from Element
Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().

getElementsByTagNameNS(self, ns, name)

Inherited from Element
Get elements by tag name given a certain namespace.
@@ -148,6 +151,34 @@

isA(self, klass)

Inherited from Node
Syntactic sugar for isinstance.

removeEvent(self, eventName, func, capture=False)

Inherited from Node
Removes events that you've added with Element.addEvent.

value (read-only property)

Equivalent to unicode(textNode). Get the string this node represents.
+

class TextArea (inherits Input)

+
Textareas. Just like Inputs really ;-).
+

__init__(self, cTextArea, browser, cast=<class 'khtml.HTMLTextAreaElement'>)

+

__delitem__(self, name)

Inherited from Element
Delete an attribute.
+

__getitem__(self, name)

Inherited from Element
Get the value of the attribute with the given name.
+

__iter__(self)

Inherited from Node
Iterate over child nodes.
+

__setitem__(self, name, value)

Inherited from Element
Set the value of the attribute with the given name.
+

addEvent(self, eventName, func, capture=False)

Inherited from Node
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.
+

attributes (read-only property)

Inherited from Element
+

childNodes (read-only property)

Inherited from Node
For those that can't live without JavaScript DOM-compatible method names.
+

children (read-only property)

Inherited from Node
Get a list containing the children nodes of this node. If you want to loop over children just loop over this node as with any regular list – it is more memory efficient that way.
+

className (property)

Inherited from Element
The class name of this element.
+

click(self)

Inherited from Input
Simulate a click on the input element. If this is a submit button, for example, this clicks it.
+

focus(self)

Focus the textarea.
+

form (read-only property)

Get the form element this textarea resides in.
+

getElementsByClass(self, className, tagName='*')

Inherited from Element
Get elements in the document (optionally with a given tag name) that have a certain class.
+

getElementsByTagName(self, name)

Inherited from Element
Get elements by tag name. Returns a generator that you can loop over or flatten into a list with list().
+

getElementsByTagNameNS(self, ns, name)

Inherited from Element
Get elements by tag name given a certain namespace.
+

hasAttribute(self, name)

Inherited from Element
Check whether an attribute exists in this element.
+

id (property)

Inherited from Element
The ID of this element.
+

innerHTML (property)

Inherited from Element
The HTML markup inside of this element. Notice that this property is writable, so you can change the markup if need be.
+

isA(self, klass)

Inherited from Node
Syntactic sugar for isinstance.
+

name (property)

The HTML name of this input.
+

originalTagName (read-only property)

Inherited from Element
Like tagName but this won't convert things to lower. Only really useful if you're dealing with XML, which probably isn't the case anyway!
+

removeEvent(self, eventName, func, capture=False)

Inherited from Node
Removes events that you've added with Element.addEvent.
+

tagName (read-only property)

Inherited from Element
Get the lowercase name of this tag.
+

text (read-only property)

Inherited from Element
If the next child of this element is a text node, this will return the text value of that node.
+

value (property)

The content of this textarea.

elementCast(e, browser)

nodeCast(n, browser)

registerElement(elementName, klass)

=== modified file 'pykhtml/__init__.py' --- pykhtml/__init__.py 2007-03-06 22:25:50 +0000 +++ pykhtml/__init__.py 2007-03-15 01:46:43 +0000 @@ -1,6 +1,6 @@ import sys, os, tempfile -import khtml, kdecore +import khtml, kdecore, kdeui, kio import sip # cast #from khtml.DOM import DOMString import qt @@ -85,22 +85,21 @@ os_path_join = os.path.join return [os_path_join(x, name) for x in path if os_path_exists(os_path_join(x, name))] -class _MyDialog(qt.QDialog): - def closeEvent(self, e): - # stops a crash... - e.accept() - stopEventLoop() +class _PyKHTMLDialog(kdeui.KMainWindow): + pass -def _startKApplication(): +def _startGraphicalApplication(): global application, dialog kdecore.KCmdLineArgs.init(sys.argv[:1], "PyKHTML", "PyKHTML Library", "9.9") application = kdecore.KApplication() + global _config + _config = _ConfigurationHandler() # the widget that will host the KHTMLParts - dialog = _MyDialog(None) + dialog = _PyKHTMLDialog(None) application.setMainWidget(dialog) if debugWithGUI: dialog.show() - dialog.layout = qt.QVBoxLayout(dialog) + #dialog.layout = qt.QVBoxLayout(dialog) def excepthook(type, value, trace): """ Our exception hook that prints out the traceback, powers down the pykhtml engine, and then exits """ @@ -147,7 +146,7 @@ usingXvfb = False if _supressQtDebug: qt.qInstallMsgHandler(_displayQtDebug) - _startKApplication() + _startGraphicalApplication() initSuccessful = True if registerExceptionHandler: sys.excepthook = excepthook @@ -182,6 +181,19 @@ _Timer(int(time * 1000), func) +class _ConfigurationHandler: + """ Used internally to handle (woo!) config data manipulating (e.g user agent loading, etc) """ + UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1" + def __init__(self): + self.slaveConfig = kio.KIO.SlaveConfig.self() + qt.QObject.connect(self.slaveConfig, qt.SIGNAL("configNeeded(const QString&, const QString&)"), self.configNeeded) + + def configNeeded(self, protocol, host): + #print "Sending user agent", self.configuration.userAgent(host) + #print "Set Config Data" + self.slaveConfig.setConfigData(protocol, host, "UserAgent", self.UserAgent) +_config = None + class Browser(object): """ A Browser is the main class you use to navigate around and visit different pages. Have a look at Browser.load and Browser.document to access basic use. """ def __init__(self): @@ -190,12 +202,12 @@ self.part = khtml.KHTMLPart(dialog) qt.QObject.connect(self.part.browserExtension(), qt.SIGNAL("openURLRequestDelayed(const KURL &, const KParts::URLArgs &)"), self._openURLRequest) if debugWithGUI: - dialog.layout.addWidget(self.part.view()) + dialog.setCentralWidget(self.part.view()) self.part.show() # disable images, java, and stylesheets so things load quicker - self.part.setJavaEnabled(False) - self.part.setPluginsEnabled(False) - self.part.setAutoloadImages(False) + self.part.setJavaEnabled(True) + self.part.setPluginsEnabled(True) + self.part.setAutoloadImages(True) # sore finger remedy: self.connect = self.part.connect self.disconnect = self.part.disconnect === modified file 'pykhtml/dom.py' --- pykhtml/dom.py 2007-03-06 22:25:50 +0000 +++ pykhtml/dom.py 2007-03-15 01:46:43 +0000 @@ -1,5 +1,6 @@ from khtml import DOM as _DOM +import qt import sip DOMString = _DOM.DOMString @@ -163,9 +164,9 @@ def getElementsByClass(self, className, tagName="*"): """ Get elements in the document (optionally with a given tag name) that have a certain class """ for element in self.getElementsByTagName(tagName): - if className in str(element.getAttribute(DOMString("class")).string()).split(" "): - e = elements.item(i) - yield nodeCast(e, self.browser) + if className in element["class"].split(" "): + #e = elements.item(i) + yield element def _getId(self): return str(self._.id().string()) @@ -194,6 +195,16 @@ def originalTagName(self): """ Like tagName but this won't convert things to lower. Only really useful if you're dealing with XML, which probably isn't the case anyway! """ return str(e.nodeName().string()) + + def click(self, button="left", shift=False, ctrl=False): + """ Simluate a click on the element. You can optionally specify that a different button was clicked (defaults to "left" -- can be "left", "middle", or "right") or that shift/ctrl are held down at the time of click """ + """ Simulate a click on the element (for javascript calls, for example) """ + buttonCode = {"left": 0, "middle": 1, "right": 2}[button] + cDocument = self.browser.document._d + event = cDocument.createEvent(DOMString("MouseEvents")) + mouseEvent = _DOM.MouseEvent(event) + mouseEvent.initMouseEvent(DOMString("click"), True, True, cDocument.defaultView(), 1, 0, 0, 0, 0, ctrl, False, shift, False, buttonCode, self._) + self._.dispatchEvent(mouseEvent) # -- important, we hook to the method not Element base class registerNode(1, elementCast) @@ -271,6 +282,33 @@ value = property(_getValue, _setValue, None, "The value of this input -- for example, for textareas and inputs of type 'text', this is its content. For buttons, this is the text inside the button, etc.") registerElement("INPUT", Input) +class TextArea(Input): + """ Textareas. Just like [[Input]]s really ;-) """ + def __init__(self, cTextArea, browser, cast=_DOM.HTMLTextAreaElement): + Element.__init__(self, cTextArea, browser, cast) + + @property + def form(self): + """ Get the form element this textarea resides in """ + return Form(self._.form()) + + def _getName(self): + return str(self._.name().string()) + def _setName(self, name): + self._.setName(DOMString(name)) + name = property(_getName, _setName, None, "The HTML name of this input") + + def focus(self): + """ Focus the textarea """ + self._.focus() + + def _getValue(self): + return str(self._.value().string()) + def _setValue(self, value): + self._.setValue(DOMString(value)) + value = property(_getValue, _setValue, None, "The content of this textarea") +registerElement("TEXTAREA", TextArea) + #class Title(Element): #def __init__(self, cTitle): #Node.__init__(self, cTitle) @@ -317,9 +355,9 @@ def getElementsByClass(self, className, tagName="*"): """ Get elements in the document that have a certain class """ for element in self.getElementsByTagName(tagName): - if className in str(element.getAttribute(DOMString("class")).string()).split(" "): - e = elements.item(i) - yield nodeCast(e, self.browser) + if className in element.className.split(" "): + #e = elements.item(i) + yield element def visit(self, text=None, callback=None, attributes=None, stripSpace=True): """ Visit a page pointed to by a certain link. This function searches for all links in the document that either: === modified file 'todo.txt' --- todo.txt 2007-03-06 22:25:50 +0000 +++ todo.txt 2007-03-15 01:46:43 +0000 @@ -2,7 +2,7 @@ * PyKHTML Todo List * ********************** - + Event dispatching (document.createEvent, initMouseEvent with type "click", then dispatch on an element) + + UNIT TESTS! + Make the examples available online + Big friendly 'Download (latest)' button + Add Contact section to the website