I have a class by name Point3D in Python.
class Point3D :
def __int(self):
self.__x =0.0
self.__y =0.0
self.__z =0.0
def setPoint(x,y,z):
self.__x =x
self.__y =y
self.__z =z
def getPoint(x,y,z):
x = self.__x
y = self.__y
z = self.__z
The above is not Python (I'm going to presume the news client ate
the indentation) -- in particular, your getPoint() is non functional; x,
y, z are input arguments to getPoint, and act as local variables within
the function.
class Point3D:
def __init__(self, x = 0.0, y = 0.0, z = 0.0):
self.setPoint(x, y, z)
def setPoint(x, y, z):
self._x = x
self._y = y
self._z = z
def getPoint():
return (self._x, self._y, self._z)
.... is functional Python
I dont want to expose the above Point3D implementation to the user /
client side.To achieve that we can use interface concept.In Python to
use interface concept.
At this point it still isn't clear what you consider a "user" or
"client".
How the interface class looks like for Point3D in python?.
How to implement that Interface?
How to access the implemented interface thru Interface Object in the
client side?
So far, all buzz words with no context...
It will be helpful if somebody proivide a piece of sample code for
creating the interface for the above access at the client place
said:
Access the Point data in the client side
IPoint *pIPoint = NULL;
pISampleInterface = CoCreateInstance(..);
...............
pISampleInterface ->QueryInstance(IID_IPoint ,(void*&)pIPoint )
NOW you have given CONTEXT...
CoCreateInstance is Windows specific for COM/OLE...
I suggest you obtain (if you don't already have it) the PyWin32 (aka
win32all) module package, and then study the documentation for the
pythoncom module within that package. Granted, the documentation is
somewhat sparse -- for example (I do hope this will pass for "fair use"
to illustrate what I mean by sparse).
-=-=-=-=-
pythoncom.WrapObject
PyIUnknown = WrapObject(ob, gatewayIID , interfaceIID )
Wraps a Python instance in a gateway object.
Parameters
ob : object
The object to wrap.
gatewayIID=IID_IDispatch : PyIID
The IID of the gateway object to create (ie, the interface of the server
object wrapped by the return value)
interfaceIID=IID_IDispatch : PyIID
The IID of the interface object to create (ie, the interface of the
returned object)
Return Value
Note that there are 2 objects created by this call - a gateway (server)
object, suitable for use by other external COM clients/hosts, as well as
the returned Python interface (client) object, which maps to the new
gateway.
There are some unusual cases where the 2 IID parameters will not be
identical. If you need to do this, you should know exactly what you are
doing, and why!
-=-=-=-=-=-=-
As for making things available to other programs via COM... That
probably requires creating and registering a COM server with the OS, so
other programs can find it. I have no experience with this level of COM
(give me an Amiga application with an ARexx port any day -- those were
relatively easy to code)
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/