[PyKDE] DCOP From Cron

Jim Bublitz jbublitz at nwinternet.com
Wed Jun 21 03:02:59 BST 2006


On Tuesday 20 June 2006 16:26, Richard Heck wrote:
> Jim Bublitz wrote:
> >> Here's a simple test program:
> >>
> >> #/usr/bin/python
> >> #Create DCOP clients
> >> import kdecore
> >> import dcopext
> >> dcopclient = kdecore.KApplication.dcopClient()
> >> dcopclient.registerAs("changewp")
> >> dcopapp = dcopext.DCOPApp("kdesktop", dcopclient)
> >> print dcopapp.KBackgroundIface.currentWallpaper(1)[1]
> >>
> >> If I run that from a konsole, I get e.g.
> >> /usr/share/wallpapers/default_gears.jpg. But if I run it from a virtual
> >> terminal, I get: None. And again: I'm the same user both times.
> >
> > It appears the problem is with KDE and DCOP. There are a few things I'd
> > try. First, I'd see what some of the DCOPClient methods, like
> > isAttached() and isRegistered() return. I'd also query the interface and
> > see if I could get a list of applications, or objects for an application.
> > Lastly, I'd look into instantiating and attaching a DCOPClient directly,
> > rather than using KApplication's, and pay attention to return values.
> >
> > I think DCOP is intended for IPC within a KDE session (ie - with child
> > processes of a kdeinit). It might be that you need to create your
> > application as a daemon under the current KDE session and then us cron to
> > communicate with that daemon.
>
> The strange thing, however, is that if I use the dcop command line tool,
>
> then I can do:
> >dcop --user rgheck
>
> and connect to the relevant server. It seems as if there ought to be
> some way to do that using PyKDE. And similarly as if there ought to be
> some way to do what you could do via
>
> >dcop --all-users
>
> and the like. But I don't see that facility.

The first functional lines of the dcop utility you're using are:

    DCOPClient client;
    client.attach();

In Python the equivalent would be:

import dcop
c = DCOPClient ()
c.attach ()

If you run that from the Python interpreter, c.attach () returns False. It 
appears that attach is trying to use a server address (c.dcopServerFile () 
returns it) that doesn't exist. If I use c.setServerAddress ('some valid 
address') I get other errors that are apparently coming from X/ICE. The 
server address is apparently of the form DCOPserver_<hostname>_:0
(might be username instead of hostname, as they're identical on this machine) 
It's a small text file in your home directory - assuming I found the right 
file. You can also set the DCOPSERVER environment variable to point to it 
apparently.

There is a signal emitted ('attachFailed') that contains more diagnostic 
information about why attach () failed, but since I was in the interpreter, 
it would be kind of a pain to connect to that - you could try it 
programmatically.

That still doesn't explain why attach() works in the dcop utility, but not 
from Python, but perhaps the diagnostics will provide some more help.

The code for the dcop utility is at  kdelibs-3.5.0/dcop/client or whatever 
version of kdelibs source you might have.

Jim




More information about the PyQt mailing list