[Python.NET] About PythonEngine.RunString

2006-01-23 Thread Eugene
Hello All!
I'm new in C#. Now I try embed Python in my C# prog.
I wrote

public partial class Form1 : Form
{
PyObject m;
string ans="none";
public Form1()
{
InitializeComponent();
PythonEngine.Initialize();
m =PythonEngine.RunString("2+3");
ans = m.ToString;<- How i can eval answer from RunString?!
label1.Text = ans;
}

when i debug and see the m variable - watch say m=Null
why?! what i'm doing wrong?!

Thanks!
}
_
Python.NET mailing list - [email protected]
http://mail.python.org/mailman/listinfo/pythondotnet


[Python.NET] Custom delegates and wrapping class instance in .net object

2006-01-18 Thread Eugene Yakubovich
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
[EMAIL PROTECTED]
_
Python.NET mailing list - [email protected]
http://mail.python.org/mailman/listinfo/pythondotnet