Experimental PyQt projects

Extension script and PyQt tricks
This page provides a place to discuss and keep track of some of the things various folks are working on with the extension script system for scribus. Currently, that's pretty much me (ringerc).

PyKDE and DCOP
Scribus has a fairly good API exposed via Python. Why not try to expose *that* using DCOP, or use dcop's automatic Qt proxy to expose the underlying C++ API? PyKDE looks like it's well worth investigating.

Scribus is not a KDE application ... but dcop works fine with it anyway. One can load the dcop bindings from PyKDE then create, attach, and register a DCOP client, and things appear to work. If one launches Scribus with, then loads dcop support:

>>> import dcop >>> dclient = dcop.DCOPClient >>> dclient.attach >>> myname = dclient.registerAs('scribus')

it should now be possible to access Scribus's newly created dcop interface from the command line dcop client:

$ dcop kded klauncher scribus-23330 $ dcop scribus-23330 qt $ dcop scribus-23330 qt QCStringList functions QCStringList interfaces QCStringList objects QCStringList find(QCString) $ dcop scribus-23330 qt objects qt/desktop qt/unnamed382(QSmSocketReceiver, 0x84bdc80) qt/unnamed382(QSmSocketReceiver, 0x84bdc80)/unnamed1(QSocketNotifier, 0x84bdd50)qt/scribus qt/scribus/global font cache qt/scribus/session manager qt/scribus/default event loop qt/scribus/toolTipManager qt/scribus/toolTipManager/unnamed1(QTimer, 0x84c6b18) qt/scribus/popup submenu timer ...blah blah blah... qt/scribus/global font cache qt/scribus/session manager qt/scribus/default event loop qt/scribus/toolTipManager qt/scribus/toolTipManager/unnamed1(QTimer, 0x84c6b18) qt/scribus/popup submenu timer qt/_ptrpriv $ dcop scribus-23330 qt/unnamed381 hide $ dcop scribus-23330 qt/unnamed381 show $ dcop scribus-23330 qt/unnamed381 slotFileQuit call failed $

You will note that a lot of objects are unnamed, and that I had to find the main window by digging through the object list. I'm going to be slowly fixing that up, starting with important objects like the main window, menu bars, palettes, etc. My local copy of scribus already has the properties palette, view, main window etc named, and you can expect to see those in CVS soon.

The final call, to slotFileQuit, failed. It actually quit the application fine, but of course it shut down the Python interpreter, so it was unable to reply to the dcop message. No big deal.

A more serious issue is that because many objects are unnamed, it can be very hard to reliably pick them out - especially as the numbering changes when new unnamed objects are created or destroyed. Naming the key objects in the app should address this.

Here's a python script you can use as a startup script in Scribus to dcop-enable it when it loads. Make sure to either run Scribus with  or start the   before Scribus loads, because it needs to be able to register with the dcop server when it first starts up. If you use this script, you'll have a new name  in the global namespace - this can be accessed from the script console and from extension scripts.

The dcop documentation is probably going to be of interest to folks reading this. It's all C++ based, but not too hard to translate to Python. The KDE Developer Library might be useful too.

Update: DCOP's automagic bindings only appear to work for a small subset of functions, possibly only  functions with no arguments. Full DCOP support would requre the use of the DCOP IDL compiler, and KDE support for the Scribus core. Consequently any direct integration work is on hold, though I'm still interested in exposing the scripter API over DCOP.

Other PyKDE uses
Be aware that most of the KDE stuff will require a KApplication instance, which doesn't exist with Scribus. So while DCOP works (at least the qt bridge), large chunks of PyKDE probably won't. Still, it should be fun to find out what can and can not be done. The  module is probably a good place to start.