=== modified file 'doc/pykhtml.htm'
--- doc/pykhtml.htm 2007-03-06 22:25:50 +0000
+++ doc/pykhtml.htm 2007-04-09 16:59:53 +0000
@@ -31,7 +31,7 @@
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. The PyKHTML event loop needs to be 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 unless you want to set some of the values of the arguments. You can specify use of a certain X display by setting the `display` parameter, and can stop pykhtml registering its exception handler (the
excepthook function) by setting `registerExceptionHandler` to False.
+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 unless you want to set some of the values of the arguments. You can specify use of a certain X display by setting the `display` parameter, and can stop pykhtml registering its exception handler (the
excepthook function) by setting `registerExceptionHandler` to False.
Our exception hook that prints out the traceback, powers down the pykhtml engine, and then exits.
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 'pykhtml/__init__.py'
--- pykhtml/__init__.py 2007-03-25 22:53:54 +0000
+++ pykhtml/__init__.py 2007-04-09 16:59:53 +0000
@@ -1,6 +1,6 @@
import sys, os, tempfile
-import khtml, kdecore, kdeui, kio
+import khtml, kdecore, kdeui, kio, dcopext
import sip # cast
#from khtml.DOM import DOMString
import qt
@@ -18,38 +18,12 @@
# set to true to see what's happening visually
debugWithGUI = False
-
-
-class partial:
- """ 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.
- Use is as follows:
-
- >>> def func(a, b):
- ... print "func:", a, b
- ...
- >>> func2 = pykhtml.partial(func, "foo")
- >>> func2("bar!")
- func: foo bar! """
- def __init__(self, func, *args, **kwargs):
- """ Create a new functor that -- when called -- will call the given function, passing any extra arguments / keyword-arguments that you specify """
- self.fun = func
- self.pending = args[:]
- self.kwargs = kwargs.copy()
-
- def __call__(self, *args, **kwargs):
- if kwargs and self.kwargs:
- kw = self.kwargs.copy()
- kw.update(kwargs)
- else:
- kw = kwargs or self.kwargs
- return self.fun(*(self.pending + args), **kw)
-
class _Dummy(object):
pass
# whether or not init() was successful
initSuccessful = False
-# KApplication
+# KApplication
application = None
# the dialog that hosts the KHTMLParts
dialog = None
@@ -67,6 +41,8 @@
# Xvfb process. All you need to know is that it's
# an object with a display attribute (that contains the
# X display value (i.e :1))
+#
+# XX refactor into init
xvfb = None
if running("Xvfb") and os.path.exists(os.path.join(temp, "PyKHTMLXvfb")):
f = file(os.path.join(temp, "PyKHTMLXvfb"))
@@ -91,7 +67,8 @@
def _startGraphicalApplication():
global application, dialog
if not application:
- kdecore.KCmdLineArgs.init(sys.argv[:1], "PyKHTML", "PyKHTML Library", "9.9")
+ about = kdecore.KAboutData("pykhtml", "PyKHTML", "9.9", "PyKHTML library", kdecore.KAboutData.License_BSD, "(c) 2006, Paul Giannaros")
+ kdecore.KCmdLineArgs.init([sys.argv[0]], about)
application = kdecore.KApplication()
global _config
_config = _ConfigurationHandler()
@@ -103,6 +80,30 @@
dialog.show()
#dialog.layout = qt.QVBoxLayout(dialog)
+_weDisabledKWallet = False
+def _disableKWallet():
+ wallet = kdecore.KConfig("kwalletrc")
+ wallet.setGroup("Wallet")
+ enabled = str(wallet.readEntry("Enabled"))
+ if enabled == "true":
+ global _weDisabledKWallet
+ _weDisabledKWallet = True
+ wallet.writeEntry("Enabled", "false")
+ wallet.sync()
+ # kick kwallet
+ kded = dcopext.DCOPApp("kded", application.dcopClient())
+ kded.kwalletd.reconfigure()
+ #print kded.kwalletd.reconfigure()
+
+def _reEnableKWallet():
+ wallet = kdecore.KConfig("kwalletrc")
+ wallet.setGroup("Wallet")
+ wallet.writeEntry("Enabled", "true")
+ wallet.sync()
+ # kick
+ kded = dcopext.DCOPApp("kded", kdecore.KApplication.kApplication().dcopClient())
+ print kded.kwalletd.reconfigure()
+
def excepthook(type, value, trace):
""" Our exception hook that prints out the traceback, powers down the pykhtml engine, and then exits """
import traceback
@@ -118,7 +119,7 @@
else:
sys.stderr.write("Qt debug: %s\n" % message)
-def init(display=1, registerExceptionHandler=True, _sleep=1, _supressQtDebug=True):
+def init(display=1, registerExceptionHandler=True, _sleep=1, _stopKWallet=True, _supressQtDebug=True):
""" 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 unless you want to set some of the values of the arguments. You can specify use of a certain X display by setting the `display` parameter, and can stop pykhtml registering its exception handler (the [[excepthook]] function) by setting `registerExceptionHandler` to False. """
global initSuccessful
if not initSuccessful:
@@ -151,7 +152,35 @@
initSuccessful = True
if registerExceptionHandler:
sys.excepthook = excepthook
- _startGraphicalApplication()
+ _startGraphicalApplication()
+ if _stopKWallet:
+ _disableKWallet()
+
+
+
+class partial:
+ """ 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.
+ Use is as follows:
+
+ >>> def func(a, b):
+ ... print "func:", a, b
+ ...
+ >>> func2 = pykhtml.partial(func, "foo")
+ >>> func2("bar!")
+ func: foo bar! """
+ def __init__(self, func, *args, **kwargs):
+ """ Create a new functor that -- when called -- will call the given function, passing any extra arguments / keyword-arguments that you specify """
+ self.fun = func
+ self.pending = args[:]
+ self.kwargs = kwargs.copy()
+
+ def __call__(self, *args, **kwargs):
+ if kwargs and self.kwargs:
+ kw = self.kwargs.copy()
+ kw.update(kwargs)
+ else:
+ kw = kwargs or self.kwargs
+ return self.fun(*(self.pending + args), **kw)
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. """
@@ -160,10 +189,13 @@
def stopEventLoop():
""" Stop the event loop and hence exit the scraper """
- global dialog
- dialog.deleteLater()
- dialog = 0
+ if _weDisabledKWallet:
+ _reEnableKWallet()
+ #dialog.deleteLater()
+ #global dialog
+ #dialog = 0
application.exit(0)
+ sys.exit(0)
class _Timer(qt.QTimer):