diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 90825e2392b2d70e43c7a25b8a3752299a933894 (patch) | |
tree | e33aa27f02b74604afbfd0ea4f1cfca8833d882a /dcoppython/lib | |
download | tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'dcoppython/lib')
-rw-r--r-- | dcoppython/lib/Makefile.am | 4 | ||||
-rw-r--r-- | dcoppython/lib/pydcop.py | 122 |
2 files changed, 126 insertions, 0 deletions
diff --git a/dcoppython/lib/Makefile.am b/dcoppython/lib/Makefile.am new file mode 100644 index 00000000..99dbac94 --- /dev/null +++ b/dcoppython/lib/Makefile.am @@ -0,0 +1,4 @@ + +pyt_DATA = pydcop.py +pytdir = $(PYTHONMODDIR) + diff --git a/dcoppython/lib/pydcop.py b/dcoppython/lib/pydcop.py new file mode 100644 index 00000000..0333b742 --- /dev/null +++ b/dcoppython/lib/pydcop.py @@ -0,0 +1,122 @@ +import pcop + +def registeredApplications(): + """Return a list of current DCOP registered applications.""" + return pcop.app_list() + +def apps(): + """Return a list of current DCOP registered applications.""" + return pcop.app_list() + +def anyAppCalled(appName): + """Return any application instance called appName, or None if none currently registered.""" + for app in apps(): + if appName==app or appName+'-'==app[:len(appName)+1]: + return DCOPApplication(app) + return None + +def registerAs(appid, addpid=1): + """Register the application with DCOP and return the ID. This is needed in order to receive DCOP requests.""" + return pcop.register_as(appid,addpid) + +def processEvents(): + """Process any waiting QT events, then return.""" + pcop.process_events() + +def connectDCOPSignal(sender,senderObj,signal,receiverObj,slot,vol=1): + """Connect a dcop signal""" + return pcop.connect_dcop_signal(sender,senderObj,signal,receiverObj,slot,vol) + +def disconnectDCOPSignal(sender,senderObj,signal,receiverObj,slot): + """Connect a dcop signal""" + return pcop.disconnect_dcop_signal(sender,senderObj,signal,receiverObj,slot) + +class DCOPApplication(object): + def __init__( self, name ): + self.name = name + + def __getattr__( self, item ): + if item == "__repr__": + return object.__repr__ + if item == "__str__": + return object.__str__ + if item == "__call__": + return object.__call__ + if item == "_objects_": + return pcop.obj_list(self.name) + return DCOPObject( self.name, item ) + + def _object_(self, object): + return DCOPObject( self.name, object ) + +class DCOPObject(object): + def __init__( self, appname, name ): + self.appname = appname + self.name = name + + def __repr__( self ): + return "DCOPObject(%s,%s)" % ( self.appname, self.name ) + + def __str__( self ): + return "DCOPObject(%s,%s)" % ( self.appname, self.name ) + + def __getattr__( self, item ): + if item == "__repr__": + return object.__repr__ + if item == "__str__": + return object.__str__ + if item == "__call__": + return object.__call__ + if item == "_methods_": + return pcop.method_list( self.appname, self.name ) + return DCOPMethod( self.appname, self.name, item ) + + def _method_(self, method): + return DCOPMethod( self.appname, self.name, method ) + +class DCOPMethod(object): + def __init__( self, appname, objname, name ): + self.appname = appname + self.objname = objname + self.name = name + + def __repr__( self ): + return "DCOPMethod(%s,%s,%s)" % ( self.appname, self.objname, self.name ) + + def __str__( self ): + return "DCOPMethod(%s,%s,%s)" % ( self.appname, self.objname, self.name ) + + def __call__( self, *args ): + return pcop.dcop_call( self.appname, self.objname, self.name, args ) + +class DCOPServer(object): + def __init__( self, appid, addpid = 1): + self.app_id = pcop.register_as(appid, addpid) + + +class DCOPServerObject: + """Inherit from this class to DCOP enabled your object. + + Remember to call the base class constructor, and in your own constructor + you should called setMethods to set the methods to DCOP enable. + """ + + def __init__(self, objName=None): + """objName is the name of the object. If omitted, it will default to a hex + address. It is best to supply it.""" + if objName: + self.dcop_obj = pcop.create_dcop_object(self, objName) + else: + self.dcop_obj = pcop.create_dcop_object(self) + + def setMethods(self, methods): + """Set the method list for this object. + + methods is a list of tuple pairs. Each pair consists of the + method signature and the Python method that handles it. + + For example, setMethods([ ('QString cheeseType()', self.cheese_type), + ('void setGreatWines(bool perthPink, bool hobartMuddy, bool chateauChunder)') + """ + pcop.set_method_list(self.dcop_obj, methods) + |