jbublitz at nwinternet.com
Wed May 26 06:56:01 BST 2004
On Tuesday 25 May 2004 20:22, Amand Tihon wrote:
> I've been playing with pyKDE and DCOP these last few days, and I must say
> it is not really easy. The main problem being I haven't been able to find
> any documentation (as soon as I have something working, I'll put it on the
> Up to now, I've managed to implement void functions.
> But either there's something I didn't understand, or the python prototype
> of DCOPObject.process() should be reviewed.
> Currently, the replyType and replyData are passed as arguments (as it is in
> C++). Their types are respectively QCString and QByteArray.
> The replyType is not a real problem, as I can set it with the setStr()
> method. However, pyKDE offers very few ways to interract with a QByteArray.
> And since it is passed as reference, I cannot build one from a python
> I'd like to be able to return at least a bool, an int, a QCString or a
> QCStringList. I've already tried to play with some QDataStream, etc, but
> pyKDE doesn't support the stream operators << and >>, and I couldn't obtain
> any result.
> Perhaps the process() method should return a tuple of (bool, [something]) ?
> I don't know if it would be perfect, though.
> Does anyone know how to solve this ?
It always cheers me up when someone asks about something I'm in the middle of.
I basically got a PyKDE-adapted version of pydcop (from kde-bindings - written
by Torben Weis and Julian Rockey) working this afternoon. Here's the basic
code to call a DCOP method and get the result back:
[methods from kicker/Panel are int panelSize () and
void addURLButton (QString)]
app = KApplication (...)
d = DCOPApplication ("kicker, app.dcopClient ())
ok, pSize = d.Panel.panelSize () # pSize gets the int from the call
ok = d.Panel.addURLButton (QString ("http://kde.org"))
(the QString (...) may not be required - haven't tested it yet).
That's all that's required. The dcop extension (one .py file and two global
functions added to the PyKDE kdecore lib) will take care of marshalling the
arguments (you have to provide the correct argument value types and count),
calling the function and demarshalling the replyData. The underlying methods
are available if you want to/need to do it the hard way. The kdecore
functions allow you to easily pack and unpack a QByteArray (using a
No << or >> operators yet though (function calls instead) - maybe in the
future, although the interface above makes them un-needed. You need to borrow
the dcopClient instance from a KApplication (the second param in the
The methods above always return at least a bool ('ok' - the status value from
the DCOP call -True== success, False == Failure), and a value if the method
I'm in the process of figuring what types to support, but most of the common
Qt and KDE classes that DCOP uses will be supported - for the most part
supporting a type is trivial. Not sure about the template types yet (for
example, QMap). Also, docs are needed and I need to decide if some exceptions
are required or if what's already there is sufficient.
I already had the basic QByteArray/QDataStream code done, and with what PyKDE
has available plus the elegant interface the KDE guys named above wrote (and
I stole) it's a pretty slick little package. Not much code at all.
It may not be finished for the next PyKDE release, but I'll probably include
it anyway, as it's pretty usable already. I still have to look at handling
the various string types (transparently I hope) and passing in things like
lists or dicts from Python. There should be something available in a couple
The other things I haven't looked at yet at all are DCOP enabling apps you
write using PyKDE or handling DCOP signals, but there's code I can steal for
More information about the PyQt