=== modified file 'examples/pykhtmlsite.py' (properties changed)
--- examples/pykhtmlsite.py 2007-02-11 15:51:11 +0000
+++ examples/pykhtmlsite.py 2007-02-11 18:58:20 +0000
@@ -1,10 +1,8 @@
-#!/usr/bin/python
import sys
sys.path.append("..")
import pykhtml
-pykhtml.debugWithGUI = True
PyKHTMLUrl = "http://localhost/PyKHTML/"
=== modified file 'pykhtml/__init__.py'
--- pykhtml/__init__.py 2007-02-11 15:51:11 +0000
+++ pykhtml/__init__.py 2007-02-11 18:58:20 +0000
@@ -10,7 +10,7 @@
import dom
# set to true to see what's happening visually
-debugWithGUI = False
+debugWithGUI = True
class curry:
""" Partial application of parameters. This is used internally but is also very useful with [[Browser.load]] as it allows you to pass data to other functions.
@@ -73,7 +73,7 @@
def _startKApplication():
global application, dialog
- kdecore.KCmdLineArgs.init(sys.argv, "PyKHTML", "PyKHTML Library", "0.1")
+ kdecore.KCmdLineArgs.init(sys.argv, "PyKHTML", "PyKHTML Library", "9.9")
application = kdecore.KApplication()
# the widget that will host the KHTMLParts
dialog = qt.QDialog(None)
@@ -87,7 +87,7 @@
global initSuccessful
if not initSuccessful:
# check that Xvfb is in the path
- if not pathSearch("Xvfb"):
+ if pathSearch("Xvfb"):
raise OSError("Xvfb not installed")
global xvfb
if not xvfb:
@@ -112,6 +112,7 @@
def startEventLoop():
""" 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. """
+ init()
application.exec_loop()
def stopEventLoop():
@@ -120,9 +121,25 @@
application.quit()
#sys.exit(0)
+
+class _Timer(qt.QTimer):
+ def __init__(self, time, func):
+ init()
+ qt.QTimer.__init__(self, application)
+ self.func = func
+ self.connect(self, qt.SIGNAL("timeout()"), self.call)
+ self.start(time)
+
+ def call(self):
+ self.stop()
+ self.func()
+ application.removeChild(self)
+ del self
+
def timer(time, func):
""" Call the given function after the alloted time. The PyKHTML event loop needs to be running """
- qt.QTimer.singleShot(int(time * 1000), func)
+ _Timer(int(time * 1000), func)
+
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. """
@@ -177,6 +194,13 @@
# XX why not just put addEvent in Node and make Document inherit from Node? Document IS meant to be a Node, after all.
docElement = dom.Element(self.document._d).addEvent("load", func)
+ def setHtml(self, source, url=None):
+ """ Set the HTML of the browser. Parses the HTML and generates the DOM tree so you can navigate it as usual. As well as the `source` parameter, a `url` parameter allows you to specify a URL with which this source code is linked so that e.g any scripts/images referenced in the HTML will be found. """
+ url = url or kdecore.KURL()
+ self.part.begin(url)
+ self.part.write(source)
+ self.part.end()
+
@property
def source(self):
print [x for x in dir(self.part) if x.lower().count("source") or x.lower().count("doc")]