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 [hidden email] _________________________________________________ Python.NET mailing list - [hidden email] http://mail.python.org/mailman/listinfo/pythondotnet |
> 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 [hidden email] V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com _________________________________________________ Python.NET mailing list - [hidden email] http://mail.python.org/mailman/listinfo/pythondotnet |
Free forum by Nabble | Edit this page |