=== modified file 'doc/pykhtml.htm'
--- doc/pykhtml.htm 2007-06-14 12:04:11 +0000
+++ doc/pykhtml.htm 2007-07-03 00:39:39 +0000
@@ -23,7 +23,7 @@
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.
Set this to any callable that you want to receive alert messages. The default implementation just does nothing.
If you're going to do something that will inadvertently cause PyKHTML to browse to a new page and you want a function to be called when the page is loaded, set onNextLoad to the function.
-
+Set this to any callable that you want to receive JavaScript prompt messages. It will be called passing the message and the defaultText (if specified; None otherwise). Return the text you would like to be passed back to the JS interpreter or None for JavaScript null. The default implementation just returns None.
Set whether callbacks passed to functions such as
Browser.load or
dom.Document.visit will have a reference to this browser object passed as a parameter. Default is True.
Take a screenshot of the current webpage and save it to the given file name. Once the screenshot has been taken and saved, the given callback parameter will be called. You can specify the width (the default is 800) to resize the page to. File type will be determined by extension or by the optional format parameter (one of "PNG", "BMP", "XBM", "XPM", or "JPG"). You can also specify the optional quality parameter, a value from 1-100 (leave as None for default values).
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.
=== modified file 'pykhtml/__init__.py'
--- pykhtml/__init__.py 2007-06-29 12:58:41 +0000
+++ pykhtml/__init__.py 2007-07-03 00:39:39 +0000
@@ -78,7 +78,6 @@
application = kdecore.KApplication()
global _config
_config = _ConfigurationHandler()
- # the widget that will host the KHTMLParts
def _createDialog():
global dialog
@@ -90,6 +89,7 @@
dialog.show()
#dialog.layout = qt.QVBoxLayout(dialog)
+
_weDisabledKWallet = False
def _disableKWallet():
@@ -125,7 +125,6 @@
if advice != "Accept":
advice.writeEntry("CookieGlobalAdvice", "Accept")
advice.sync()
-
def excepthook(type, value, trace):
""" Our exception hook that prints out the traceback, powers down the pykhtml engine, and then exits """
@@ -298,17 +297,20 @@
self.part = khtml.KHTMLPart(dialog)
qt.QObject.connect(self.part.browserExtension(), qt.SIGNAL("openURLRequestDelayed(const KURL &, const KParts::URLArgs &)"), self._openURLRequest)
if debugWithGUI:
+ # XX multiple Browsers doesn't seem to work. Very bad. Troubleshoot
+ #if dialog.centralWidget():
+ #dialog.centralWidget().hide()
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.loadFunction = None
+ self._passReferenceToCallbacks = True
# sore finger remedy:
self.connect = self.part.connect
self.disconnect = self.part.disconnect
- self.loadFunction = None
- self._passReferenceToCallbacks = True
def _openURLRequest(self, url, urlArgs):
# setURLArgs to pass on form data and stuff
@@ -342,11 +344,10 @@
dialog.resize(width, contentsHeight)
#print view.contentsX(), view.contentsY()
#qt.qApp.processEvents()
+ # now wait for a re-paint and onto phase two
timer(0.1, partial(self._screenshotPart2, callback, fileName, width, contentsHeight, format, quality))
def _screenshotPart2(self, callback, fileName, width, contentsHeight, format, quality):
- # now wait for a re-paint and onto phase two
- #pixmap = qt.QPixmap.grabWidget(self.part.widget())
pixmap = qt.QPixmap(width, contentsHeight)
pixmap.fill(qt.Qt.white)
painter = qt.QPainter()
@@ -373,7 +374,7 @@
def _setOnNextLoad(self, callback):
if self.loadFunction:
- self.disconnect(self.part, qt.SIGNAL("docCreated()"). self._slotDocCreated)
+ self.disconnect(self.part, qt.SIGNAL("docCreated()"), self._slotDocCreated)
self.loadFunction = callback
self.connect(self.part, qt.SIGNAL("docCreated()"), self._slotDocCreated)
def _getOnNextLoad(self):
@@ -431,12 +432,11 @@
def onAlert(self, s):
""" Set this to any callable that you want to receive alert messages. The default implementation just does nothing """
- #print "ALERT:", message
pass
def onPrompt(self, message, defaultText):
+ """ Set this to any callable that you want to receive JavaScript prompt messages. It will be called passing the message and the defaultText (if specified; None otherwise). Return the text you would like to be passed back to the JS interpreter or None for JavaScript null. The default implementation just returns None. """
pass
-
def _slotDocCreated(self):
self._installJavaScriptOverrides()
@@ -463,7 +463,7 @@
@property
def source(self):
- print [x for x in dir(self.part) if x.lower().count("source") or x.lower().count("doc")]
+ #print [x for x in dir(self.part) if x.lower().count("source") or x.lower().count("doc")]
return str(self.part.documentSource())
@property