![]() |
|
Inhaltsverzeichnis |
DCOP steht für "Desktop COmmunication Protocol" und meint eine unter KDE gängige Art der Interprozesskommunikation. Das heißt, dass beliebige (KDE) Programme (bzw. Python-Skripte, auch Perl geht :-)) andere (KDE, bzw. DCOP-fähige) Programme steuern können. Damit kann man zum Beispiel dem Mixer sagen, er soll jetzt lauter oder leiser machen, das Hintergrundbild wechseln, Kopete soll eine Nachricht schicken, uvm.
apt-get install python-dcop
Geht mit Slackware und Suse bestimmt ähnlich, evtl. ist es auch teil der Python KDE-bindings.
Zu allererst will python-dcop initialisiert werden ...
#! /usr/bin/python # -*- encoding: utf-8 -*- import pcop import pydcop
... das pcop muss auch importiert werden, auch wenn wir daraus nix aufrufen, ansonsten zickt python und segfaultet beim Programmende. Warum auch immer 8-)
print "the following applications are known to the dcop system ..."
for appname in pydcop.apps():
print " `-> " + appname
print
### connecting to another application ##########################################
app = pydcop.anyAppCalled("kopete")
if not app: raise RuntimeError, "Couldn't find a running kopete instance"
### asking it to do something for us ....
rcpt = "stesie@jabber.zerties.org"
msg = "Das hier ist eine Nachricht, die mit Python via DCOP geschrieben wurde"
ret = app.KopeteIface.messageContact(rcpt, msg)
... dafür gibt's das Programm kdcop, das zeigt das Ganze in einer Baumstruktur an.
Beispiel (zum auslesen des KDE Adressbuchs):
#Codeausschnitt !
from kdecore import *
import dcopext
KCmdLineArgs.init ([" "], "programmname","","")
main = KApplication()
dcop = main.dcopClient ()
app = dcopext.DCOPApp ("kaddressbook", dcop)
ret, name = app.KAddressBookIface.getNameByPhone(sys.argv[1])
if ret:
print name.latin1()