From felix_mcallister at hotmail.com Mon Nov 3 11:41:32 2003 From: felix_mcallister at hotmail.com (Felix McAllister) Date: Mon Nov 3 11:41:38 2003 Subject: [Python.NET] Opening a SqlClient.Connection object fails Message-ID: Hi, Has anyone successfully opened a connection to SQL Server 2000 using PythonNet and the SqlClient.Connection object? Here's some code I have: import CLR import CLR.System import CLR.System.Data import CLR.System.Data.SqlClient connectionString = u"Driver={SQL Server};Server=(local);Database=Enterprise;Trusted_Connection=yes;" conn = CLR.System.Data.SqlClient.SqlConnection() conn.ConnectionString = connectionString conn.Open() conn.Close() The error I get is: Traceback (most recent call last): File "C:\tmp\testcon.py", line 10, in ? conn.ConnectionString = connectionString TypeError: Exception has been thrown by the target of an invocation. Ideas anyone? Felix. _________________________________________________________________ MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus From felix_mcallister at hotmail.com Mon Nov 3 12:00:45 2003 From: felix_mcallister at hotmail.com (Felix McAllister) Date: Mon Nov 3 12:00:49 2003 Subject: [Python.NET] Opening a SqlClient.Connection object fails Message-ID: Er, this is embarassing. I've used an ADO connection string instead of an ADO.NET one. Sorry. Felix. _________________________________________________________________ Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail From brian at zope.com Mon Nov 3 12:47:43 2003 From: brian at zope.com (Brian Lloyd) Date: Mon Nov 3 12:49:08 2003 Subject: [Python.NET] Opening a SqlClient.Connection object fails In-Reply-To: Message-ID: > > Er, this is embarassing. I've used an ADO connection string instead of an > ADO.NET one. > > Sorry. > > Felix. Ah, but I think you caught a good bug in the process - I think the less-than-useful error message shows that I need to fix the property handling. Methods pass the 'real' exception along, but properties don't seem to. Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From gordonm at uk.facilita.com Tue Nov 4 13:56:11 2003 From: gordonm at uk.facilita.com (Gordon McKeown) Date: Tue Nov 4 14:05:00 2003 Subject: [Python.NET] Subclassing a subclassed Form Message-ID: Hi If I create a new (Form) class using Visual Studio and then subclass it in Python then I get "TypeError: no method matches given arguments" when executing 'WinForms.Application.Run(self)'. The new Form instance is created OK and the following returns true: 'isinstance(form, System.Windows.Forms.Form)' The only differences from the working examples appear to be: 1. The parameter is an object subclassed from a class that is in turn subclassed from System.Windows.Forms.Form. (The intermediate class is written in C#). 2. The class I created is not in the GAC. It is loaded using 'Assembly.LoadFile("D:\\forecastdev\\net\\TestGraphs\\bin\\Debug\\TestGraphs .exe")' Has anybody any suggestions? Regards Gordon --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.532 / Virus Database: 326 - Release Date: 27/10/2003 -------------- next part -------------- A non-text attachment was scrubbed... Name: winmail.dat Type: application/ms-tnef Size: 2140 bytes Desc: not available Url : http://mail.python.org/pipermail/pythondotnet/attachments/20031104/6b044ddd/winmail.bin From meeper at innerverse.com Tue Nov 4 16:55:10 2003 From: meeper at innerverse.com (Mike Casaday) Date: Tue Nov 4 16:55:20 2003 Subject: [Python.NET] Using an existing Python installation Message-ID: Python for .NET is really cool! Here's something I found out while trying to get it to work with my existing Python 2.3 installation. The README says: > **Can I use it with my existing Python installation?** > > Yes, at least on win32 systems. Just copy the files > Python.Runtime.dll and CLR.dll from the PythonNet directory to the > root directory of your python installation. > This answer comes with one caveat in my experience. For some reason you have to 'import CLR' before trying to import anything else from the .NET runtime. This isn't the case if I use the Python executable included in PythonNet-1.0-beta1.tgz, only if I use my existing Python installation. So this fails: from CLR.System.Reflection import Assembly Assembly.LoadWithPartialName('SomeNamespace') import CLR.SomeNamespace as SomeNamespace But this works: import CLR from CLR.System.Reflection import Assembly Assembly.LoadWithPartialName('SomeNamespace') import CLR.SomeNamespace as SomeNamespace Is it possible I'm doing something wrong (more than likely)? Is this a bug? Is this expected behavior? ZODB requires you to 'import ZODB' before you do certain things, so I wouldn't be surprised... ______________ mike P.S. I'm now playing around with the TrueVision3D game engine using Python, something that I couldn't really do until now. I'm happy I saw a link to this project from Daily Python-URL. From brian at zope.com Tue Nov 4 19:20:38 2003 From: brian at zope.com (Brian Lloyd) Date: Tue Nov 4 19:22:14 2003 Subject: [Python.NET] Using an existing Python installation In-Reply-To: Message-ID: > So this fails: > > from CLR.System.Reflection import Assembly > Assembly.LoadWithPartialName('SomeNamespace') > import CLR.SomeNamespace as SomeNamespace > > But this works: > > import CLR > from CLR.System.Reflection import Assembly > Assembly.LoadWithPartialName('SomeNamespace') > import CLR.SomeNamespace as SomeNamespace Hi Mike - yes, I've already got this one in the bug hopper for b2. It has to do with the trickery I'm using to install the import hook not being quite tricky enough when it happens in an already-running interpreter. Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From brian at zope.com Tue Nov 4 22:51:49 2003 From: brian at zope.com (Brian Lloyd) Date: Tue Nov 4 22:52:53 2003 Subject: [Python.NET] Need some feedback on events... Message-ID: Hi all - Looking at fixing a problem with events, I'm realizing that my original plan has a big hole in it :( Here's the situation: the framework requires that an event be implemented by providing an add_SomeEvent and a remove_SomeEvent method. However, the actual storage and mechanisms used to call the delegates registered via those special methods are completely up to the implementor of a class. When you write, for example, a class with an event in C# using the MS tools, you get: - add_* and remove_* methods - a private internal field to hold the delegate You do *not* get an automagic method to fire the event, because the class implementor is supposed to provide this if it appropriate (but may choose not to). The current Python.NET event stuff expects this setup, and it allows you to treat the event as a callable object - when you call the event, it tries to call that internal delegate. The problem is that its wrong :) According to everything I can find, a class is supposed to provide an 'OnSomeEvent' method to fire an event if it is appropriate for client code to fire the events of the class explicitly. If a class does not provide an 'OnSomeEvent' method, then it is assumed that it is not appropriate for the event to be fired by a client (and there is in fact no reliable way for the client to even try, since the dispatching to subscribers is purely internal to the class and could be done in arbitrary ways). I'm tempted to remove the ability to call event objects directly from Python, as this would match the convention and what you'd have to do in C# or VB, etc. (you'd call the OnSomeEvent method instead). The alternative would have to be doing some kind of automagical thing where we'd try lookup up an OnXXX if the usual private event field wasn't there, but that seems nasty... thoughts? Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From gotcha at swing.be Wed Nov 5 03:40:28 2003 From: gotcha at swing.be (Godefroid Chapelle) Date: Wed Nov 5 03:50:25 2003 Subject: [Python.NET] python for .net list on gmane Message-ID: For those who may be interested, I subscribed this list to gmane.org as gmane.comp.python.dotnet IOW you can also read it with your newsgroup client. -- Godefroid Chapelle (aka __gotcha) http://bubblenet.be From gordonm at uk.facilita.com Wed Nov 5 06:50:04 2003 From: gordonm at uk.facilita.com (Gordon McKeown) Date: Wed Nov 5 09:29:15 2003 Subject: [Python.NET] Subclassing a subclassed Form Message-ID: Hi I changed the calls to Assembly.LoadFile() to Assembly.LoadFrom() and the problem appears to be resolved. I'm a newcomer to .NET so I'm not sure whether the behaviour when Assembly.LoadFile() was used to load the Assemblies is correct or not... Regards Gordon --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.536 / Virus Database: 331 - Release Date: 03/11/2003 -------------- next part -------------- A non-text attachment was scrubbed... Name: winmail.dat Type: application/ms-tnef Size: 1792 bytes Desc: not available Url : http://mail.python.org/pipermail/pythondotnet/attachments/20031105/9b9f0b86/winmail.bin From brian at zope.com Wed Nov 5 09:49:20 2003 From: brian at zope.com (Brian Lloyd) Date: Wed Nov 5 09:50:08 2003 Subject: [Python.NET] Subclassing a subclassed Form In-Reply-To: Message-ID: Strange - there is good overview of assembly load context issues here: http://blogs.gotdotnet.com/suzcook/PermaLink.aspx/d5c5e14a-3612-4af1-a9b7-0a 144c8dbf16 I'm still a little perplexed that the isinstance call worked while the attempt to call the method didn't, given the internals of the integration layer :( I have a feeling I'll be learning more than I ever wanted to know about this when I work on the ability to find and load assemblies from the PYTHONPATH... Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com > -----Original Message----- > From: pythondotnet-bounces@python.org > [mailto:pythondotnet-bounces@python.org] On Behalf Of Gordon McKeown > Sent: Wednesday, November 05, 2003 6:50 AM > To: pythondotnet@python.org > Subject: [Python.NET] Subclassing a subclassed Form > > Hi > > I changed the calls to Assembly.LoadFile() to Assembly.LoadFrom() and the > problem appears to be resolved. I'm a newcomer to .NET so I'm not sure > whether the behaviour when Assembly.LoadFile() was used to load the > Assemblies is correct or not... > > Regards > Gordon > > > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.536 / Virus Database: 331 - Release Date: 03/11/2003 > << File: ATT00102.txt >> -------------- next part -------------- A non-text attachment was scrubbed... Name: winmail.dat Type: application/ms-tnef Size: 2712 bytes Desc: not available Url : http://mail.python.org/pipermail/pythondotnet/attachments/20031105/f657596f/winmail.bin From Michael.Amrhein at t-online.de Wed Nov 5 10:10:18 2003 From: Michael.Amrhein at t-online.de (Michael Amrhein) Date: Wed Nov 5 10:10:46 2003 Subject: [Python.NET] Need some feedback on events... In-Reply-To: References: Message-ID: <3FA912DA.5000005@t-online.de> Brian Lloyd wrote: > Hi all - > > Looking at fixing a problem with events, I'm realizing that > my original plan has a big hole in it :( These moments are tragic but ... things like this happen. ... hopefully not too frequently :) > (snip) > > The current Python.NET event stuff expects this setup, and it > allows you to treat the event as a callable object - when you > call the event, it tries to call that internal delegate. > > The problem is that its wrong :) According to everything I can > find, a class is supposed to provide an 'OnSomeEvent' method to > fire an event if it is appropriate for client code to fire the > events of the class explicitly. If a class does not provide an > 'OnSomeEvent' method, then it is assumed that it is not > appropriate for the event to be fired by a client (and there is > in fact no reliable way for the client to even try, since the > dispatching to subscribers is purely internal to the class and > could be done in arbitrary ways). > > I'm tempted to remove the ability to call event objects directly > from Python, as this would match the convention and what you'd > have to do in C# or VB, etc. (you'd call the OnSomeEvent method > instead). > > The alternative would have to be doing some kind of automagical > thing where we'd try lookup up an OnXXX if the usual private > event field wasn't there, but that seems nasty... > > thoughts? > Hi Brian, to me it doesn't feel to be a good idea to call events directly because this would be something not intended with events in the CLR. As i see it, events associated with an object are to provide a mechanism for other(!) objects to get notified of some change in the objects state and only the object itself should control when this notification takes place. This is why the On methods are protected. Their sole purpose is to give a subclass the chance to overwrite the event handling without registering a delegate. If a class wants to allow client code to trigger an event it should provide an appropriate method (or property) which changes the state of an object and then fires the corresponding event to notify who ever's interested. As far as I looked at the CLR classes I think this is the way they are designed. For example, Windows.Forms.Control: Click : OnClick : PerformClick Paint : OnPaint : Invalidate (or Refresh) GotFocus : OnGotFocus : Focus LostFocus : OnLostFocus : Focus The Focus method shows how important it may be to call the provided method instead of triggering an event directly. Calling GotFocus directly would do only half of the show. I don't know if there's a way to prevent python code from calling protected members of CLR objects from outside. If not, may be it possible to follow the common convention and make them visible under names beginning with an _. Michael From brian at zope.com Fri Nov 7 09:54:28 2003 From: brian at zope.com (Brian Lloyd) Date: Fri Nov 7 09:55:01 2003 Subject: [Python.NET] CVS updates Message-ID: Hi all - For the intrepid, I've checked in a number of fixes to things that have come up on the list: - Events refactored, -= now works for internalcalls, events are no longer directly callable (use OnSomeEvent(...) instead) - Implicit assembly loading now uses the PYTHONPATH to find assemblies. This means you can just add to sys.path to use an assembly that doesn't live in appbase or the GAC - Fixed a dumb bug in constructor handling that could cause you to get an 'IntPtr.Zero' instance rather than an exception in some cases when instantiating an object (this was the root of Michael's Point subclassing problem) If any of these are holding you up, you can get the fixes from CVS. I'm going to try to make a b2 tonight if the baby holds off for one more day :) Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From l.oluyede at virgilio.it Fri Nov 7 11:50:25 2003 From: l.oluyede at virgilio.it (Lawrence Oluyede) Date: Fri Nov 7 11:50:38 2003 Subject: [Python.NET] Generating MSIL code Message-ID: <3FABCD51.30904@virgilio.it> First and foremost I want to thank Bryan Lloyd for his great effort of making something useful for Python guys on the .NET Framework. Now I gotta explain the subject. I think that the "dream" feature for a Python .NET implementation is generation of standard IL code (not only bridging). I mean something like the previous [1] effort made by Mark Hammond with his Python .NET implementation (I've talked to him by email months ago and he told me that he stopped working on it cause he was no longer an ActiveState employee and nobody financed him to continue working). Do you, Brian, ever thougth to do something like that? What do you think about that? Thanks in advance 1 - http://starship.python.net/crew/mhammond/dotnet/ -- Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com From brian at zope.com Fri Nov 7 13:39:52 2003 From: brian at zope.com (Brian Lloyd) Date: Fri Nov 7 13:40:59 2003 Subject: [Python.NET] Generating MSIL code In-Reply-To: <3FABCD51.30904@virgilio.it> Message-ID: > Now I gotta explain the subject. I think that the "dream" feature for a > Python .NET implementation is generation of standard IL code (not only > bridging). I mean something like the previous [1] effort made by Mark > Hammond with his Python .NET implementation (I've talked to him by email > months ago and he told me that he stopped working on it cause he was no > longer an ActiveState employee and nobody financed him to > continue working). > > Do you, Brian, ever thougth to do something like that? What do you > think about that? I think it would be great if there were a "native" Python implementation for .NET. Mark's whitepaper makes a lot of good points, and I agree with his assessment that it would doable given the commitment to make it happen. I think the result would end up looking a whole lot like Jython (a pure-Java implementation of Python, for anyone who hasn't heard of it). The main obstacle is that it would be a _lot_ of work, both up front and over time to update the implementation to track the evolution of the Python language. Jython is a good example of both the potential and the challenge - it is a great solution, but it struggles to keep up with CPython over time. I chose to do a bridge rather than try to carry on Mark's work mainly because it was something I had a shot at finishing in the limited amount of time I have to work on it (nights and weekends - my job doesn't really involve .net). While I was convinced that there was enough business value to justify the effort to do the bridge, it may still be too early in the .NET adoption curve to know whether there is enough business value in a full managed implementation to justify the (much higher) effort. I hope it does happen one day - if nothing else because I'm a big Python fan and would like to see it flourish. But it won't be me doing it on nights & weekends :^) Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From brian at zope.com Thu Nov 13 20:59:24 2003 From: brian at zope.com (Brian Lloyd) Date: Thu Nov 13 21:00:59 2003 Subject: [Python.NET] Python for .NET 1.0 beta 2 released Message-ID: Python for .NET 1.0 beta 2 has been released - you can download it from: http://www.zope.org/Members/Brian/PythonNet/ Python for .NET is a near-seamless integration of Python with the .NET common language runtime. For more details, see the README: http://www.zope.org/Members/Brian/PythonNet/README.html The beta 2 release fixes several issues found in beta 1: - It is now possible to import assemblies from any directory on the PYTHONPATH (sys.path), in addition to importing from the appbase and the GAC - A problem that prevented registration of event handlers from working for some kinds of objects has been fixed - Constructor invokation handled some error conditions incorrectly, leading to odd results when calling some constructors There is also now a mailing list for discussion, questions and issues related to Python for .NET at: pythondotnet@python.org. To subscribe to the mailing list or read the online archives, see: http://mail.python.org/mailman/listinfo/pythondotnet Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From Michael.Amrhein at t-online.de Fri Nov 14 04:10:57 2003 From: Michael.Amrhein at t-online.de (Michael Amrhein) Date: Fri Nov 14 04:12:51 2003 Subject: [Python.NET] CVS updates In-Reply-To: References: Message-ID: <3FB49C21.3020504@t-online.de> Brian Lloyd wrote: ... > - Fixed a dumb bug in constructor handling that could cause you > to get an 'IntPtr.Zero' instance rather than an exception in > some cases when instantiating an object (this was the root of > Michael's Point subclassing problem) ... Hi Brian, the bug in constructor handling is fixed: (running beta 2) Python 2.3.2 (#49, Oct 2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import CLR >>> from CLR.System.Drawing import Point >>> class P(Point): ... def __repr__(self): ... return 'P(%s,%s)' % (self.X, self.Y) ... >>> p=P() Traceback (most recent call last): File "", line 1, in ? TypeError: no constructor matches given arguments But there is still some strange behavior: >>> p=P(0,0) >>> p.__repr__() 'P(0,0)' Fine, but ... >>> repr(p) '' Why? Michael From petri.savolainen at iki.fi Thu Nov 13 07:41:22 2003 From: petri.savolainen at iki.fi (Petri Savolainen) Date: Fri Nov 14 09:41:41 2003 Subject: [Python.NET] Bug report: beta2 crashes on Win98SE, dot Net 1.1 Message-ID: <3FB37BF2.9010004@iki.fi> Full pkg crashes when starting the interpreter and existing 2.3.2 distro when importing anything from CLR. "Application generated an exception that could not be handled". Regards, Petri From brian at zope.com Fri Nov 14 09:58:09 2003 From: brian at zope.com (Brian Lloyd) Date: Fri Nov 14 09:59:17 2003 Subject: [Python.NET] CVS updates In-Reply-To: <3FB49C21.3020504@t-online.de> Message-ID: > But there is still some strange behavior: > > >>> p=P(0,0) > >>> p.__repr__() > 'P(0,0)' > > Fine, but ... > > >>> repr(p) > '' > > Why? > > Michael The short answer is that there is still some work to do in type generation for subclasses of reflected types. The long answer :) is that right now the "magic" methods (__something__) that are related to C "slots" in the Python type object aren't dispatched correctly. There is a _lot_ of code in the C runtime to fixup these slots correctly, but it isn't exposed in a very convenient way and I'm trying to work out the exact right dance to trick the runtime into doing it for me rather than having to reimplement it. This is one of the next things on my list, so hopefully b3 will resolve it. Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From brian at zope.com Fri Nov 14 10:25:39 2003 From: brian at zope.com (Brian Lloyd) Date: Fri Nov 14 10:26:23 2003 Subject: [Python.NET] RE: PythonNet python.exe crashes... In-Reply-To: <16510007930.20031113200636@kaishaku.org> Message-ID: > I just run it in a fresh Win2k3 install and it crashes. I tried running > python.exe demo/helloform.py first and it crashed then just decided to try > python.exe alone and that's a problem. Any idea what's up? mmm... I just tried on a w2k3 box, and what I got was: - startup from cygwin shell works ok - startup from cmd shell works ok - double-click on python.exe - crashes :( It doesn't do this on XP. I'll have to dig into this one. > Will this let me develop .net web applications in Python as I would in C#? > > I understand you are embedding Python, similar to me embedding Python for > use in Delphi applications. Would this work for web development or would I > have all sorts of wrappers for my Python code in a first class > language like > C# which might just be calling to execute the Python code? It doesn't allow you define types that are directly visible at compile-time to C#, etc., so you probably would have to implement some sort of "pass- through" to delegate to your Python code. It should be possible to come up with a generic dispatcher though, so you wouldn't necessarily have to write a lot of wrappers. Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From MBarclay at cri-inc.com Fri Nov 14 12:31:19 2003 From: MBarclay at cri-inc.com (MBarclay@cri-inc.com) Date: Fri Nov 14 12:31:41 2003 Subject: [Python.NET] example of calling Python from C# with simple object marshalling Message-ID: In case anyone is trying to use the embedding aspect of this fine package (well-done, Brian!), here is a quick-and-dirty starting point that shows how one might call a Python function with a variable argument list of .NET simple value types (e.g. int, double, string) returning an object list, from a .NET application. The in and out lists are ordinary simple type objects in the NET wold, and ordinary Python objects in the Python world. Note that this is not meant to replace anything Brian has in the Runtime DLL. It is simply a proof of concept test I did to begin discovering what I can do in the C# -> Python direction. The following trivial python file has an invoke() method which can be called from C# in a very uncluttered way... """ PyPortal.py demonstration of passing simple type arguments and returning a tuple of simple types """ def invoke(a1, a2): print 'invoke() called with %s and %s.' % (a1, a2) # show that we can return a list of simple types... return ("[wrap(%s)]" % s, f*2) The C# code that calls this looks like this, including a traversal of the returned objects.... PythonEngine.Initialize(); PyObject pyportal = PythonEngine.ImportModule("PyPortal"); PyObject callable = pyportal.GetAttr("invoke"); Portal portal = new Portal(); object[] objects = portal.Invoke(callable, "Mark Barclay", 123.456); if (objects != null) { foreach (object o in objects) { if (o != null) Console.WriteLine(o.ToString()); else Console.WriteLine("o is null."); } } Note the object instantiation "Portal portal = new Portal()". For this to work, the following in-lined file, Portal.cs, needs to be added to the runtime (I created a project PyWrapper in VS2003 that includes all the sources from src\runtime), because it needs internal visibility into some of the classes there (e.g. Converter). There is almost certainly a better, simpler way, but for now this showed me that calling Pythoin with arbitrary value type args and retuning a list of Python objects onverted to .NET objects was feasible using Python for .NET. A class such as this (Portal) might be a handy addition to the runtime, or maybe Brian has something like that there already, or on the drawing board. If not, I'd be happy to take on the task of creating a more complete and robust implementation of this, if anyone thinks it would be useful. (Please forgive the lack of comments, error detection and general completeness in the following demonstration code) using System; namespace Python.Runtime { public class Portal { public Portal() { } public object[] Invoke(PyObject callable, params object[] objects) { if (!callable.IsCallable()) { throw new Exception("Invoke called with an un-callable"); } int size = objects.Length; IntPtr items = Runtime.PyTuple_New(size); for (int i=0; i Hello: I am not sure if this is a bug, or just me attempting to run code on a platform it was not designed for but ... Here is the traceback I get when I attempt to display the 'helloform.py' using the python version shipped with the .tar.gz __________________________________________________________ C:\Desktop\PythonNet-1.0-beta2>python.exe .\demo\helloform.py Unhandled Exception: System.ArgumentException: The parameter is incorrect. at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode , IntPtr errorInfo) at System.Runtime.InteropServices.Marshal.FreeHGlobal(IntPtr hglobal) at Python.Runtime.StaticMethodWrapper..ctor(Type obType, String name) at Python.Runtime.ImportHook.Initialize() at Python.Runtime.Runtime.Initialize() at Python.Runtime.PythonEngine.Initialize() at PythonConsole.Main(String[] args) C:\Desktop\PythonNet-1.0-beta2> ___________________________________________________________ I get the same traceback with PythonNet-1.0-beta1 , however, both PythonNet-preview1 and PythonNet-preview2 continue to work fine ( at least for the limited testing performed). I am running Windows 98 (fully updated from Microsoft) using Win4Lin on top of i386 linux , kernel 2.2.18. I have only one version of python on the 'virtual' machine (2.3.2) -- installed using the standard python.org. installer. The .NET Framework version is 1.1.4322 Any thoughts or suggestions? Sincerely, J From brian at zope.com Mon Nov 17 21:55:54 2003 From: brian at zope.com (Brian Lloyd) Date: Mon Nov 17 21:56:17 2003 Subject: [Python.NET] pythondotnet beta 2 initialization error. In-Reply-To: <200311171115.01124.stauft@telus.net> Message-ID: > I am not sure if this is a bug, or just me attempting to run code on a > platform it was not designed for but ... > > Here is the traceback I get when I attempt to display the > 'helloform.py' using > the python version shipped with the .tar.gz grr - it's a bug, and a really dumb one at that :( Fixed in CVS for b3. Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From david.powell at kcl.ac.uk Wed Nov 19 05:21:45 2003 From: david.powell at kcl.ac.uk (david Powell) Date: Wed Nov 19 05:21:12 2003 Subject: [Python.NET] Form design Message-ID: <000001c3ae86$fb103560$6d244989@STR12B1> Skipped content of type multipart/alternative-------------- next part -------------- A non-text attachment was scrubbed... Name: form1.xfrm Type: application/octet-stream Size: 3274 bytes Desc: not available Url : http://mail.python.org/pipermail/pythondotnet/attachments/20031119/afadcdbe/form1.obj -------------- next part -------------- import CLR import CLR.System.Windows.Forms as WinForms from CLR.System.Drawing import Size, Point class MyForm(WinForms.Form): def __init__(self): self.ClientSize=Size(424, 301) self.pn = WinForms.Panel() self.Controls.Add(self.pn) self.pn.Name='pn' self.pn.Location=Point(16,168) self.pn.Size=Size(136, 104) self.pn.TabIndex=6 self.tc = WinForms.TabControl() self.Controls.Add(self.tc) self.tc.Name='tc' self.tc.TabIndex=4 self.tc.Size=Size(216, 104) self.tc.Location=Point(176,176) self.Page1 = WinForms.TabPage() self.tc.Controls.Add(self.Page1) self.Page1.Text='Page1' self.Page1.Size=Size(208, 78) self.Page1.Location=Point(4,22) self.btnpage1 = WinForms.Button() self.Page1.Controls.Add(self.btnpage1) self.btnpage1.Name='btnpage1' self.btnpage1.Location=Point(48,16) self.btnpage1.Size=Size(96, 24) self.btnpage1.Text='button Page 1' self.btnpage1.TabIndex=0 self.Page2 = WinForms.TabPage() self.tc.Controls.Add(self.Page2) self.Page2.Text='Page2' self.Page2.Size=Size(208, 78) self.Page2.Location=Point(4,22) self.btnPage2 = WinForms.Button() self.Page2.Controls.Add(self.btnPage2) self.btnPage2.Name='btnPage2' self.btnPage2.Location=Point(56,16) self.btnPage2.Size=Size(88, 24) self.btnPage2.Text='button Page2' self.btnPage2.TabIndex=0 self.pb = WinForms.PictureBox() self.Controls.Add(self.pb) self.pb.Name='pb' self.pb.Size=Size(136, 128) self.pb.Location=Point(16,32) self.pb.BorderStyle=WinForms.BorderStyle.FixedSingle self.btnTextClear = WinForms.Button() self.Controls.Add(self.btnTextClear) self.btnTextClear.Name='btnTextClear' self.btnTextClear.Location=Point(264,16) self.btnTextClear.Size=Size(80, 32) self.btnTextClear.Text='Clear' self.btnTextClear.TabIndex=2 self.textBox = WinForms.TextBox() self.Controls.Add(self.textBox) self.textBox.Name='textBox' self.textBox.BackColor=CLR.System.Drawing.Color.FromArgb(192,255,255) self.textBox.TabIndex=1 self.textBox.Location=Point(168,64) self.textBox.Size=Size(160, 56) self.textBox.Multiline=True self.textBox.Text='textBox' self.btnTextAdd = WinForms.Button() self.Controls.Add(self.btnTextAdd) self.btnTextAdd.Name='btnTextAdd' self.btnTextAdd.Location=Point(168,16) self.btnTextAdd.Size=Size(80, 32) self.btnTextAdd.Text='Add' self.btnTextAdd.TabIndex=0 def run(self): WinForms.Application.Run(self) def main(): MyForm().run() if __name__ == '__main__': main() -------------- next part -------------- from form1 import * class MyFormWithEvents(MyForm): def __init__(self): MyForm.__init__(self) self.addEventHandlers() def ButtonClick1(self,sender,args): self.textBox.Text+="zzz" def ButtonClick2(self,sender,args): self.textBox.Text="" def addEventHandlers(self): #setattr(MyForm,"ButtonClick1",ButtonClick1) self.btnTextAdd.Click += self.ButtonClick1 self.btnTextClear.Click += self.ButtonClick2 def main(): f=MyFormWithEvents() f.textBox.Text="Initial value" CLR.System.Windows.Forms.Application.Run(f) if __name__== '__main__': main() -------------- next part -------------- #Some functions that take either #(a) an xml form defintion from the IDE SharpDevelop #or #(b) a C# form definition from the IDE SharpDevelop # #and then produces a python-PythondotNet form defintion # #note that Frederik Lundh's ElementTree is needed #http://effbot.org/downloads/ from elementtree.ElementTree import * def tab(n): if n<=0 : return('') else: s='' for i in range(n): s=s+('\t') return(s) def csharpToPythondotNet (filenameCsharp, filenamePythondotNet): #experimental name='' elc=0 f=open(r'd:\sharp\form1.cs') Ls=f.readlines() f=open(r'd:\sharp\form1cs.py','w') s='import CLR' writeLine(f,s) s='from CLR.System.Drawing import *' writeLine(f,s) s='from CLR.System.Windows.Forms import *' writeLine(f,s) process=False for aL in Ls: #print aL if aL.find('public class')>=0 : k=aL.find('public class') k=k+len('public class') k1=aL.find(':') name=aL[k:k1].strip() print name s='class ' + name + '(CLR.System.Windows.Forms.Form):' writeLine(f,s) process=True tabs=1 continue if process: a=aL.strip() a=a.strip('\t') a=a.strip('\r') a=a.strip('\n') if a.find('private System')==0: continue if a.find('}')==0: continue if a.find(r'//')==0 : aL=aL.replace(r'//',r'#') writeLine(f,aL) continue if a.find('public ' + name)==0: #build constructor s=tab(1) + 'def __init__(self):' writeLine(f,s) tabs=2 continue if a.find('private void Initialize')==0 : s='def InitializeComponent(self):' s= tab(1) + s writeLine(f,s) tabs=2 continue #all other lines a=a.replace('this.','self.') a=a.replace(';','') a=a.replace('{','') a=a.replace('= new','= ') a=a.replace('System.Windows.Forms.','CLR.System.Windows.Forms.') a=a.replace('System.Drawing','CLR.System.Drawing') a=a.replace('true','True') a=a.replace('false','False') if a=='': elc=elc+1 else: elc=0 if a=='': if elc==1: writeLine(f,'') else: s=tab(tabs)+a writeLine(f,s) s='def main():' writeLine(f,s) s=tab(1) + 'f=' + name + '()' writeLine(f,s) s = tab(1) + 'CLR.System.Windows.Forms.Application.Run(f)' writeLine(f,s) s="if __name__== '__main__':" writeLine(f,s) s = tab(1) + 'main()' writeLine(f,s) f.close() def XMLToPythondotNet(filenameXML,filenamePythondotNet): #the recursive function processControls is used because #a form can contain a tab control and a tabpage has its #own controls collection d={} d['ClientSize']='Size' d['Size']='Size' d['Location']='Point' d['Name']='Text' d['TabIndex']='Int' d['Multiline']='Boolean' d['Text']='Text' d['BorderStyle']='Enum' d['SelectedIndex']='Int' d['BackColor']='Color' d['ForeColor']='Color' f=open(filenamePythondotNet,'w') writeLine(f,'import CLR') writeLine(f,'import CLR.System.Windows.Forms as WinForms') writeLine(f,'from CLR.System.Drawing import Size, Point') #get tree from file tree=ElementTree(file=filenameXML) r=tree.getroot() nc=r.getiterator("System.Windows.Forms.Form") n=nc[0] el=n.find("Name") formName=el.get("value") s='class ' + formName + '(WinForms.Form):' writeLine(f,'') writeLine(f,s) writeLine(f,'') s=tab(1) + 'def __init__(self):' writeLine(f,s) el=n.find("ClientSize") s=tab(2) + 'self.' + propertyFormat(el,d) writeLine(f,s) n=n.find('Controls') processControls(n,'self',f,d) s=tab(1) + 'def run(self):' writeLine(f,s) s=tab(2) + 'WinForms.Application.Run(self)' writeLine(f,s) s='def main():' writeLine(f,s) s=tab(1) + formName + '().run()' writeLine(f,s) s="if __name__ == '__main__':" writeLine(f,s) s=tab(1) + 'main()' writeLine(f,s) f.close() def processControls(n,parent,f,d): for c in n._children: #these are the controls elname=c.find('Name') name=elname.get('value') controlType=c.tag controlType=controlType.replace('System.Windows.Forms','WinForms') s=tab(2) + 'self.' + name + ' = ' + controlType + '()' writeLine(f,'') writeLine(f,s) s=tab(2) + parent +'.Controls.Add(self.' + name + ')' writeLine(f,s) for cp in c._children: #these are control properties if not d.has_key(cp.tag): continue ## if cp.tag=='Name': ## continue ## if cp.tag=="Lines": ## continue ## if cp.tag=="TabPages": ## continue ## if cp.tag=="DockPadding": ## continue ## if cp.tag=="Controls": ## continue s=tab(2) + 'self.' + name + '.' + propertyFormat(cp,d) writeLine(f,s) if controlType=='WinForms.TabControl': tcname=name #remember tabcontrol name ntabpages=c.find('TabPages') for ntp in ntabpages._children: controlType=ntp.tag controlType=controlType.replace('System.Windows.Forms','WinForms') if controlType!='WinForms.TabPage': pass elname=ntp.find('Name') name=elname.get('value') writeLine(f,'') s=tab(2) + 'self.' + name + ' = ' + controlType + '()' writeLine(f,s) s=tab(2) + 'self.' + tcname +'.Controls.Add(self.' + name + ')' writeLine(f,s) for cp in ntp._children: if cp.tag=='Name': continue if cp.tag=="Lines": continue if cp.tag=="TabPages": continue if cp.tag=="DockPadding": continue if cp.tag=="Controls": continue s=tab(2) + parent + '.' + name + '.' + propertyFormat(cp,d) writeLine(f,s) ntpc=ntp.find('Controls') processControls(ntpc,(parent + '.' + name),f,d) ## for cp in c._children: ## if cp.tag=='Name': ## continue ## if cp.tag=="Lines": ## continue ## if cp.tag=="TabPages": ## continue ## s=tab(2) + 'self.' + name + '.' + propertyFormat(cp,d) ## writeLine(f,s) #s=tab(2)+parent+'.Controls.Add(self.' + name + ')' #writeLine(f,s) def writeLine(f,s): f.write(s+"\n") def sizeFormat(s): size=s size=size.replace('{','(') size=size.replace('}',')') size=size.replace('Width=','') size=size.replace('Height=','') return ('Size' + size) def pointFormat(s): point=s point=point.replace('{','(') point=point.replace('}',')') point=point.replace('X=','') point=point.replace('Y=','') return ('Point' + point) def colorFormat(s): sa=s.split(',') sn=sa[1][3:] sn+=','+ sa[2][3:] k=sa[3].find(']') sn+=',' + sa[3][3:k] sn="CLR.System.Drawing.Color.FromArgb(" + sn + ")" return sn def propertyFormat(el,d): print el.tag if not d.has_key(el.tag): pass type=d[el.tag] s=el.get('value') if type=='Size' : s=sizeFormat(s) elif type=='Point': s=pointFormat(s) elif type=='Int': pass elif type=='Boolean': pass elif type=='Enum': s="WinForms." + el.tag + '.' + s elif type=='Color': s=colorFormat(s) else: s="'" + s + "'" s=el.tag + '=' + s return(s) From brian at zope.com Wed Nov 19 14:50:30 2003 From: brian at zope.com (Brian Lloyd) Date: Wed Nov 19 14:51:44 2003 Subject: [Python.NET] RE: example of calling Python from C# with simple object marshalling In-Reply-To: Message-ID: > In case anyone is trying to use the embedding aspect of this fine package > (well-done, Brian!), here is a quick-and-dirty starting point that shows > how one might call a Python function with a variable argument list of .NET > simple value types (e.g. int, double, string) returning an object list, > from a .NET application. The in and out lists are ordinary simple type > objects in the NET wold, and ordinary Python objects in the Python world. > > Note that this is not meant to replace anything Brian has in the Runtime > DLL. It is simply a proof of concept test I did to begin > discovering what I > can do in the C# -> Python direction. > > The following trivial python file has an invoke() method which can be > called from C# in a very uncluttered way... I think this points out an area still wanting in the embedding interface (calling into Python and getting back managed objects rather than PyObject wrappers). I'm thinking that a good start would be a variation on what your example does as an overload for the Invoke method of PyObjects: object Invoke(...) object[] Invoke(...) I think it would also be a good idea to have a 'ToObject' method on PyObjects: object ToObject(); which would: - if the Python object represents a managed object, return that object - if the Python object is a primitive type that is convertible to a managed primitive type, return the converted value - otherwise throw an exception Another option could be to have PyObject implement IConvertible, though that would be more work, and might not buy you anything over using: int i = thing.ToObject() as Int32 thoughts? Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From MBarclay at cri-inc.com Wed Nov 19 16:20:06 2003 From: MBarclay at cri-inc.com (MBarclay@cri-inc.com) Date: Wed Nov 19 16:20:32 2003 Subject: [Python.NET] RE: example of calling Python from C# with simple object marshalling Message-ID: Yes, overloading Invoke() for PyObjects sounds like a better solution than adding a Portal class. That is so much simpler. It's complete signature should probably be: public object[] Invoke(params object[] objects) This way, with a single method, you can pass down to Python nothing, a single primitive value, or a bunch of them (0, 1, *). Regarding your first overload (object Invoke(...) as opposed to object[] Invoke(...)), I don't believe you can overload by return type alone (maybe I'm thinking in C++), but that would be fine because the overload you indicated that returns an object is less important than the one that returns an object list (with the latter you can achieve what the former does, with the additional utility of being able to return an empty object list to mean "null" where a primitive type would otherwise be expected). The other method... object ToObject(); would be worth having as publics also, in fact I suppose it would nicely encapsulate what the new Invoke() method(s) need to do their internal stuff. Just a nitpick: I don't think you can compile: int i = thing.ToObject() as Int32 ...since "i" is a value type, and the 'as' operator can only be used on reference types (value types cannot hold null). But I get your point... int i = (Int32)thing.ToObject(); // this will throw an exception if the conversion is not valid Mark Barclay Sr. Software Engineer CRi Inc. "Brian Lloyd" m> cc: Subject: RE: example of calling Python from C# with simple object 11/19/2003 marshalling 02:50 PM I think this points out an area still wanting in the embedding interface (calling into Python and getting back managed objects rather than PyObject wrappers). I'm thinking that a good start would be a variation on what your example does as an overload for the Invoke method of PyObjects: object Invoke(...) object[] Invoke(...) I think it would also be a good idea to have a 'ToObject' method on PyObjects: object ToObject(); which would: - if the Python object represents a managed object, return that object - if the Python object is a primitive type that is convertible to a managed primitive type, return the converted value - otherwise throw an exception Another option could be to have PyObject implement IConvertible, though that would be more work, and might not buy you anything over using: int i = thing.ToObject() as Int32 thoughts? Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From hawkeye.parker at autodesk.com Wed Nov 19 17:39:31 2003 From: hawkeye.parker at autodesk.com (Hawkeye Parker) Date: Wed Nov 19 17:38:33 2003 Subject: [Python.NET] trouble with windows servers Message-ID: <9BDC80F712DD0C4CB5FBF48D2ED3DD8B44ADDF@msgusawmb02.ads.autodesk.com> i've managed to get python.net up and running on win2k, but when i try to run it in my server environment (Windows 2003 server), python.exe crashes: Application has generated an exception that could not be handled. Process id=0xd38 (3384), Thread id=0xd40 (3392). cmd traceback: Unhandled Exception: System.Runtime.InteropServices.COMException (0x80070006): T he handle is invalid. at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode , IntPtr errorInfo) at System.Runtime.InteropServices.Marshal.FreeHGlobal(IntPtr hglobal) at Python.Runtime.StaticMethodWrapper..ctor(Type obType, String name) at Python.Runtime.ImportHook.Initialize() at Python.Runtime.Runtime.Initialize() at Python.Runtime.PythonEngine.Initialize() at PythonConsole.Main(String[] args) any ideas why or how to fix? thanks, hawkeye parker QA Software Engineer Autodesk, Inc -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20031119/de1bea51/attachment.html From hawkeye.parker at autodesk.com Wed Nov 19 19:35:38 2003 From: hawkeye.parker at autodesk.com (Hawkeye Parker) Date: Wed Nov 19 19:34:38 2003 Subject: [Python.NET] very newbie installation question Message-ID: <9BDC80F712DD0C4CB5FBF48D2ED3DD8B0200695F@msgusawmb02.ads.autodesk.com> apologies in advance for this one, but i'm very new to .net: do you need .net (1.1) installed to run python for .net? or is the entire clr "built" into python for .net? to put it another way, do you need anything aside from the python for .net tarball to run python for .net? thanks hawkeye -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20031119/76308110/attachment.html From brian at zope.com Wed Nov 19 19:37:08 2003 From: brian at zope.com (Brian Lloyd) Date: Wed Nov 19 19:37:50 2003 Subject: [Python.NET] very newbie installation question In-Reply-To: <9BDC80F712DD0C4CB5FBF48D2ED3DD8B0200695F@msgusawmb02.ads.autodesk.com> Message-ID: very newbie installation questionI don't bundle the .NET redist, so that needs to be installed for it to run. Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com -----Original Message----- From: pythondotnet-bounces@python.org [mailto:pythondotnet-bounces@python.org]On Behalf Of Hawkeye Parker Sent: Wednesday, November 19, 2003 7:36 PM To: pythondotnet@python.org Subject: [Python.NET] very newbie installation question apologies in advance for this one, but i'm very new to .net: do you need .net (1.1) installed to run python for .net? or is the entire clr "built" into python for .net? to put it another way, do you need anything aside from the python for .net tarball to run python for .net? thanks hawkeye -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20031119/5dd3003c/attachment.html From brian at zope.com Wed Nov 19 22:58:24 2003 From: brian at zope.com (Brian Lloyd) Date: Wed Nov 19 22:59:56 2003 Subject: [Python.NET] Python for .NET 1.0 beta 3 released Message-ID: Python for .NET 1.0 beta 3 has been released - you can download it from: http://www.zope.org/Members/Brian/PythonNet/ Python for .NET is a near-seamless integration of Python with the .NET common language runtime. For more details, see the README: http://www.zope.org/Members/Brian/PythonNet/README.html The beta 3 release fixes a startup issue that has been affecting people on some platforms. There is also now a mailing list for discussion, questions and issues related to Python for .NET at: pythondotnet@python.org. To subscribe to the mailing list or read the online archives, see: http://mail.python.org/mailman/listinfo/pythondotnet Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From brian at zope.com Wed Nov 19 23:32:30 2003 From: brian at zope.com (Brian Lloyd) Date: Wed Nov 19 23:33:49 2003 Subject: [Python.NET] RE: example of calling Python from C# with simple object marshalling In-Reply-To: Message-ID: > Just a nitpick: I don't think you can compile: > > int i = thing.ToObject() as Int32 > > ...since "i" is a value type, and the 'as' operator can only be used on > reference types (value types cannot hold null). But I get your point... Sorry - I dashed that note out between meetings :) Should be Thing t = value.ToObject() as Thing or int i = (int)value.ToObject() Sounds like we agree that this is simple enough not to worry about IConvertible for now. So I will look at getting object[] Invoke(params object[] args) object ToObject() checked in for PyObject for b4 (I had to make a b3 tonight, since a lot of people were getting bitten by a startup issue). Brian Lloyd brian@zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From kfarmer at thuban.org Thu Nov 20 15:45:11 2003 From: kfarmer at thuban.org (Keith J. Farmer) Date: Thu Nov 20 15:45:36 2003 Subject: [Python.NET] hosted interpreter Message-ID: Is there a simple example of hosting the Python interpreter in a .NET form? I'm thinking something similar to PyShell/PyCrust in wxPython. From wengyan at hotmail.com Tue Nov 25 14:08:59 2003 From: wengyan at hotmail.com (Yan Weng) Date: Tue Nov 25 14:12:35 2003 Subject: [Python.NET] a demo program using ASP .Net and Python for .Net Message-ID: Hi all, I wrote a small program to illustrate how to embed Python engine in Asp .Net using Python for .Net. If you are interested in that, take a look of this site http://s89292973.onlinehome.us/research.htm . If you find the demo is useful or have some questions about that, please contact with me at wengyan@hotmail.com or yweng@cs.uoregon.edu . :-) Best regards, Yan 412-421-6958 wengyan@hotmail.com http://www.cs.uoregon.edu/~yweng -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20031125/fe0faf5a/attachment.html