[PyKDE] about DCOP, QDataStream, <<, and >>
Jim Bublitz
jbublitz at nwinternet.com
Sat Nov 30 20:38:00 GMT 2002
On 30-Nov-02 Jim Bublitz wrote:
> On 30-Nov-02 Me wrote:
>> Hi, I'm trying to figure out how to use the DCOP interface. The
>> KDE C++
>> examples make use of << and >>, but how to do it with python? Is
>> there a work
>> around for this?
>
>> The example I'm working from has a part like so:
>
>> void MainWindow::bookLocation()
>> {
>> DCOPClient *client=kapp->dcopClient();
>> QByteArray params;
>> QDataStream stream(params, IO_WriteOnly);
>> stream << location->text();
>> if (!client->send("p6-*", "bookmarkList", "add(QString)",
>> params))
>> kdDebug() << "Error with DCOP\n";
>> }
>>
>> How would I do that with python? Thanks for any help.
>
> The short, quick, and unsatisfying answer is "I don't know". I've
> been aware that the DCOP interface in PyKDE *might* be
> incomplete, but haven't looked much farther than that. I seem to
> recall that I did see a way around this, but I'm not sure what
> it might be at the moment. I'll look into it and try to have an
> answer in the next day or two. Please post again if I don't get
> you an answer in that timeframe.
It looks like you should be able to use QDataStream.writeBytes
or QDataStream.writeRawBytes to put data on the stream. These
are declared in qdatastream.sip as:
QDataStream &writeBytes(const char * /Array/,uint /ArraySize/);
QDataStream &writeRawBytes(const char * /Array/,uint /ArraySize/);
I'm assuming the /.../ stuff (Phil ??) means that from Python you
only need to supply the char string and sip will compute the length
and pass it to Qt for you, eg:
stream.writeBytes (location.text())
(assuming location.text() returns a Python string or char * and NOT
a QString - you'll have to do conversion otherwise).
If that doesn't seem to work, then try adding the uint length
argument as well - just len(location.text()).
The kdDebug stream doesn't exist in PyKDE - you'll have to provide
your own error handling. Obviously I haven't tried any of this, so
let me know what fails if it doesn't work.
The other missing parts in DCOP will relate to IceConn messaging
stuff - off the top of my head, there didn't seem to be a good way
to extend the bindings to cover that as it's tied into X-Windows,
but I can look at it again if there's a need.
Jim
More information about the PyQt
mailing list