[PyKDE] DCOP From Cron
Jim Bublitz
jbublitz at nwinternet.com
Tue Jun 20 21:40:52 BST 2006
On Tuesday 20 June 2006 11:28, you wrote:
> Jim Bublitz wrote:
> > On Tuesday 20 June 2006 08:49, Richard Heck wrote:
> >> İsmail Dönmez wrote:
> >>> Salı 20 Haziran 2006 17:19 tarihinde, Richard Heck şunları yazmıştı:
> >>>> I'm writing a simple application to rotate wallpaper every so often,
> >>>> and I want to run it as a cron job. The basic structure is pretty
> >>>> simple, and it works fine if I run it in a shell under KDE. But when I
> >>>> run it as a cron job, it does not connect to the DCOP server. Is there
> >>>> some way to tell the script which DCOP server to connect to?
> >>>
> >>> Maybe try dcop --user $username .
> >>
> >> Sorry, that wasn't clear. The program I'm writing is in Python.
> >
> > Yes, but it should be running under cron as the same user you're testing
> > it as (the user who owns the display and is running KDE).
> >
> > Your application should be based on KApplication, and can use
> > KApplication.dcopClient() to connect to the DCOP server.
>
> Here is the relevant part of the application as it presently exists:
>
> #Create DCOP clients
> import kdecore
> import dcopext
> dcopclient = kdecore.KApplication.dcopClient()
> dcopclient.registerAs("changewp")
> dcopapp = dcopext.DCOPApp("kdesktop", dcopclient)
>
> and then later we have things like:
>
> dcopapp.KBackgroundIface.setWallpaper(...)
>
> As said, if I run this from a konsole under KDE, it works fine. But if I
> CTRL-ALT-F1 and open a terminal outside KDE, then it doesn't work,
> despite the fact that I'm running as the same user.
>
> 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.
Jim
More information about the PyQt
mailing list