import pcop

def registeredApplications():
	return pcop.application_list()

class DCOPApplication:
        def __init__( self, name ):
                self.name = name
        def __getattr__( self, item ):
		if item == "__repr__":
			return self.__repr__
		if item == "__str__":
			return self.__str__
		if item == "__call__":
			return self.__call__
                return DCOPObject( self.name, item )

class DCOPObject:
        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 self.__repr__
		if item == "__str__":
			return self.__str__
		if item == "__call__":
			return self.__call__
                return DCOPMethod( self.appname, self.name, item )

class DCOPMethod:
        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 )
