+
Node and all of its subclasses provide you with read-only access to the page's DOM. Instantiating the classes themselves won't do you much good.
For those that can't live without JavaScript DOM-compatible method names.
Get the children nodes of this node.
Syntactic sugar for isinstance.
-
+
An HTML element. Instances of it provide methods for doing things with the element – traversing it, adding events, etc.
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.
@@ -43,7 +43,7 @@
Get the lowercase name of this tag.
If the next child of this element is a text node, this will return the text value of that node.
-
+
This lets you listen for certain events as they occur on the current element. Only particularly useful when listening for load events reaaally.
@@ -59,7 +59,7 @@
Get the lowercase name of this tag.
If the next child of this element is a text node, this will return the text value of that node.
-
+
A text node lets you access the text in it using the
Text.value attribute or by converting to a string with str().
@@ -68,10 +68,10 @@
Get the children nodes of this node.
Syntactic sugar for isinstance.
Equivalent to str(textNode). Get the string this node represents.
-
-
-
-
+
+
+
+
=== modified file 'doc/pykhtml.htm'
--- doc/pykhtml.htm 2007-02-10 19:24:59 +0000
+++ doc/pykhtml.htm 2007-02-10 20:22:22 +0000
@@ -14,19 +14,19 @@
pykhtml
None
-
+
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.
Get a reference to the document (see
dom.Document) for the currently loaded page. It contains all the tasty methods for walking the DOM tree like getElementById / getElementsByTagName, and methods for browsing to other linked pages.
Load a webpage in the browser. It takes as parameters the URI of the page to load, and a callable object to call when the page has loaded.
Browse to a new location. You probably don't want to set this directly as you'll receive no notification when the page has loaded. Have a look at Browser.load instead.
-
Starts the PyKHTML event loop. PyKHTML works with an asynchronous callback mechanism – a little like Twisted does. Calls to open a new webpage aren't synchronous, as with urllib, for example.
-
Stop the event loop and hence exit the scraper.
-
Call the given function after the alloted time. Requires that the PyKHTML event loop is running.
-
Initiate the system if necessary (start Xvfb if it's not running, connect to it, start our program instance). This is called automatically when you create a Browser instance, so you shouldn't have to worry about it. You can specify use of a certain display by setting the `display` parameter.
-
Utility function to search for and get the full path of a file in $PATH.
-
Check whether a process of the given name is running.
+
Starts the PyKHTML event loop. PyKHTML works with an asynchronous callback mechanism – a little like Twisted does. Calls to open a new webpage aren't synchronous, as with urllib, for example.
+
Stop the event loop and hence exit the scraper.
+
Call the given function after the alloted time. Requires that the PyKHTML event loop is running.
+
Initiate the system if necessary (start Xvfb if it's not running, connect to it, start our program instance). This is called automatically when you create a Browser instance, so you shouldn't have to worry about it. You can specify use of a certain display by setting the `display` parameter.
+
Utility function to search for and get the full path of a file in $PATH.
+
Check whether a process of the given name is running.
=== modified file 'doc/styles.css'
--- doc/styles.css 2007-02-10 19:24:59 +0000
+++ doc/styles.css 2007-02-10 20:22:22 +0000
@@ -37,6 +37,12 @@
color: #aaa;
margin-left: .5em;
}
+.inherits-label a.reference {
+color: #8a8;
+}
+.inherits-label a.reference:hover {
+color: #797;
+}
#modules {
padding: .3em 0;
=== modified file 'makedocs.py'
--- makedocs.py 2007-02-10 19:23:01 +0000
+++ makedocs.py 2007-02-10 20:22:22 +0000
@@ -2,6 +2,7 @@
""" Create documentation. Takes two optional arguments -- the CSS file to reference in the generated HTML, and a JS file to load.
Limitations:
+ + No inheritance diagram multi-inheritance support
+ Can't link to superclasses in other modules
+ No support for ordered lists (not massively important)
"""
@@ -39,6 +40,9 @@
"__repr__"
]
+fontPath = "arial.ttf"
+
+
classToClassList = {}
# dirty hack so that qt/kdecore/khtml aren't loaded when pykhtml calls 'import ...'
@@ -59,9 +63,43 @@
background = Image.new("RGB", image.size, backgroundColor)
return image.crop(ImageChops.difference(image, background).getbbox())
-def makeDiagram(cls):
- #image = Image.new("RGB", (300, 300))
- pass
+#def getDiagram(cls):
+ #fontSize = 12
+ ## ....
+ #image = Image.new("RGB", (300, 300), (255, 255, 255))
+ #if not os.path.exists(fontPath):
+ #raise OSError("'%s' not found. Set the fontPath variable in this script accordingly (you can point to any ttf file if you'd like)" % fontPath)
+ #font = ImageFont.truetype(fontPath, fontSize)
+ ## font.getsize(string) -> (width, height)
+ #canvas = ImageDraw.Draw(image)
+ ## Refers to the position above which the next bit of text should be placed
+ ##cursor = image.size()[1]
+ ##center = image.size()[0] / 2
+ #classToTopCenter = {}
+ #parent = None
+ #while cls:
+ #if parent is None:
+ #topCenterPosition = [image.size[0] / 2, image.size[1]]
+ #else:
+ #topCenterPosition = classToTopCenter[parent]
+ ##if inspect.isclass(cls):
+ #size = font.getsize(cls.__name__)
+ #ourCenterPosition = topCenterPosition[:]
+ #ourCenterPosition[1] -= size[1] + fontSize
+ #position = ourCenterPosition[:]
+ #position[0] -= size[0] / 2
+ #position[1] -= size[1] / 2
+ #classToTopCenter[cls] = ourCenterPosition
+ #canvas.text(position, cls.__name__, font=font, fill=((0, 0, 0) if cls.__name__ != "object" else (100, 100, 100)))
+ #print "class was =", cls
+ #parent = cls
+ #cls = cls.__bases__[0] if cls.__bases__ else None
+ #print "class now =", cls
+ #print
+ ##canvas.text()
+ ##del canvas
+ ##return image
+ #return autocrop(image)
def myImport(name):
@@ -142,8 +180,6 @@
# go up through bases checking for the existence of meth.im_func
# in the
-#def getPropertyImplementor(prop, cls):
- #return getMethodImplementor(prop.fget, cls)
class GenerateHtml:
html = """
@@ -241,9 +277,9 @@
inherits = ""
if cls[3].__bases__:
inherits = '
(inherits '
- inherits += ", ".join('%s' % x.__name__ for x in cls[3].__bases__)
+ inherits += ", ".join('[[%s]]' % x.__name__ for x in cls[3].__bases__)
inherits += ")"
- append('
\n' % (cls[1], cls[1], inherits, self.markup(cls[2])))
+ append('
\n' % (cls[1], cls[1], inherits, self.markup(cls[2])))
for method in item:
# check if this has been inherited
inheritedClassNameValue = ""
@@ -251,7 +287,7 @@
# if the implementing class is not this one
if method[4] != cls[1]:
inheritedClassNameValue = "inherited "
- inheritedMessage = '
Inherited from [%s]
' % method[4]
+ inheritedMessage = '
Inherited from [[%s]]
' % method[4]
if method[0] == 2:
append('
\n' % (inheritedClassNameValue, cls[1], method[1].split("(")[0], method[1], inheritedMessage, self.markup(method[2])))
elif method[0] == 3:
@@ -268,7 +304,7 @@
# Finally, add all the links
content = "".join(output)
for name in names:
- if content.count("[%s]" % name):
+ if content.count("[[%s]]" % name):
# deduce the link URL
url = ""
anchorName = name
@@ -288,7 +324,9 @@
anchorName = name.replace(possibleModule, "").lstrip(".")
url += "#" + anchorName
print url
- content = content.replace("[%s]" % name, '
%s' % (url, name))
+ content = content.replace("[[%s]]" % name, '
%s' % (url, name))
+ # weed out any null references
+ content = content.replace("[[", "").replace("]]", "")
# add the stylesheet link if necessary
stylesheet = ""
script = ""
@@ -306,8 +344,7 @@
def main():
- # turn the module names into modules
- makeInheritanceDiagrams = "--diagrams" in sys.argv
+ #makeInheritanceDiagrams = "--diagrams" in sys.argv
modules = []
## Speed up
inspect_isclass = inspect.isclass
@@ -339,11 +376,12 @@
extra = thingToExamine[2:]
# class
if inspect_isclass(item) and item.__module__ in moduleNames:
- print "Checking for %s.%s.png" % (moduleName, name)
- if makeInheritanceDiagrams:
- makeDiagram(item)
- else:
- assert os.path.exists(os.path.join(docDirectory, "%s.%s.png" % (moduleName, name)))
+ diagramFileName = os.path.join(docDirectory, "diagrams", "%s.%s.png" % (moduleName, name))
+ #print "Checking for %s" % (diagramFileName)
+ #if makeInheritanceDiagrams:
+ #getDiagram(item).save(diagramFileName)
+ #else:
+ #assert os.path.exists(diagramFileName)
_documentClass(item, name, itemsToExamine, documentedItems)
# method (extra tuple items: class, definingClass)
elif inspect_ismethod(item):
=== modified file 'pykhtml/__init__.py'
--- pykhtml/__init__.py 2007-02-10 19:23:01 +0000
+++ pykhtml/__init__.py 2007-02-10 20:22:22 +0000
@@ -158,6 +158,6 @@
@property
def document(self):
- """ Get a reference to the document (see [dom.Document]) for the currently loaded page. It contains all the tasty methods for walking the DOM tree like getElementById / getElementsByTagName, and methods for browsing to other linked pages. """
+ """ Get a reference to the document (see [[dom.Document]]) for the currently loaded page. It contains all the tasty methods for walking the DOM tree like getElementById / getElementsByTagName, and methods for browsing to other linked pages. """
return dom.Document(self.part.htmlDocument(), self)
=== modified file 'pykhtml/dom.py'
--- pykhtml/dom.py 2007-02-10 19:23:01 +0000
+++ pykhtml/dom.py 2007-02-10 20:22:22 +0000
@@ -48,7 +48,7 @@
class Text(Node):
- """ A text node lets you access the text in it using the [Text.value] attribute or by converting to a string with str() """
+ """ A text node lets you access the text in it using the [[Text.value]] attribute or by converting to a string with str() """
def __init__(self, cTextNode):
Node.__init__(self, cTextNode)
@@ -101,7 +101,7 @@
# convenience
def getElementsByClass(self, className, tagName="*"):
- """ Get elements in the document that have a certain class """
+ """ 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)
@@ -123,7 +123,7 @@
self._.addEventListener(DOMString(eventName), listener, capture)
def removeEvent(self, eventName, func, capture=False):
- """ Removes events that you've added with [Element.addEvent] """
+ """ Removes events that you've added with [[Element.addEvent]] """
self._.removeEventListener(DOMString(eventName), _CallbackEventListener.getCallbackInstance(eventName, func), capture)
_CallbackEventListener.remove(eventName, func)
# -- important, we hook to the method not Element base class
@@ -131,7 +131,7 @@
class Anchor(Element):
- """ Anchor elements with an [Anchor.href] property """
+ """ Anchor elements with an [[Anchor.href]] property """
def __init__(self, cAnchor):
Element.__init__(self, cAnchor)
self._ = sip.cast(self._, _DOM.HTMLAnchorElement)
@@ -151,7 +151,7 @@
class Document(object):
- """ Document object for accessing the DOM tree. Don't keep this object around, when the page changes it's invalidated. Just access it through [pykhtml.Browser.document] whenever you want it. """
+ """ Document object for accessing the DOM tree. Don't keep this object around, when the page changes it is invalidated. Just access it through [[pykhtml.Browser.document]] whenever you want it. """
def __init__(self, htmlDocument, browser):
self._d = htmlDocument
self.browser = browser