Custom delegates and wrapping class instance in .net object

Hi, I'm using Python .Net in conjuction with .Net WinForms to do some GUI development. What I have is one class that derives from Control and has all the GUI code and one class that handles all the network I/O (using standard Python sockets). The network I/O code runs in a separate thread and when it receives some data it needs to pass it to the GUI thread to display it. What I need is a custom delegate. If it was a C# program, it would be really easy to create: public delegate void DataArrived(object data); With Python.Net I don't see how I can do that. What I ended up doing is writing a simple assembly in C# that just contains the following lines: public delegate void NoArgDelegate(); public delegate void ObjectArgDelegate(object arg); public delegate void ArrayArgDelegate(object[] arg); My hope is to keep this utility assembly around for those times when I need a custom delegate. The delegates are somewhat general and with the last one, it is possible to pass as many arguments as needed. I would like to know, however, if anyone else encountered this problem and how they solved it. Is there a way to solve it with pure Python .Net (without C#)? If not, maybe a custom delegate(s) should be included into Python .Net? My second problem is that I can't pass Python class instances as arguments to my delegates. For example: def callback(arg): pass d = ObjectArgDelegate(callback) class PythonClass(object): pass d(PythonClass()) Results in: TypeError: no method matches given arguments Is there a way to convert a python class instance to a .Net object and then convert it back to python class instance? Eugene eyakubovich@getcollc.com

What I need is a custom delegate. If it was a C# program, it would be really easy to create: public delegate void DataArrived(object data);
With Python.Net I don't see how I can do that. What I ended up doing is writing a simple assembly in C# that just contains the following lines:
public delegate void NoArgDelegate(); public delegate void ObjectArgDelegate(object arg); public delegate void ArrayArgDelegate(object[] arg);
My hope is to keep this utility assembly around for those times when I need a custom delegate. The delegates are somewhat general and with the last one, it is possible to pass as many arguments as needed. I would like to know, however, if anyone else encountered this problem and how they solved it. Is there a way to solve it with pure Python .Net (without C#)? If not, maybe a custom delegate(s) should be included into Python .Net?
I don't think I understand what you're trying to do well enough to advise here - if you can post an example that would be helpful.
My second problem is that I can't pass Python class instances as arguments to my delegates. For example:
def callback(arg): pass d = ObjectArgDelegate(callback)
class PythonClass(object): pass
d(PythonClass())
Results in:
TypeError: no method matches given arguments
Is there a way to convert a python class instance to a .Net object and then convert it back to python class instance?
In this case, you should just be able to have PythonClass inherit from System.Object - that will get it a default conversion that should work for what you want to do. Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com
participants (2)
-
Brian Lloyd
-
Eugene Yakubovich