From hhspiny at pine.cc Sun Mar 13 21:54:15 2016 From: hhspiny at pine.cc (Hansong Huang) Date: Sun, 13 Mar 2016 21:54:15 -0400 Subject: [Python.NET] Can Python.Net inherit .Net Interface Class Message-ID: I am attempting to implement a MVVM WPF application in Python.Net. The ViewModel class needs to implement the INotifyPropertyChanged interface. class ViewModel(System.ComponentModel.INotifyPropertyChanged): def __init__(self): pass vm = ViewModel() gives exception: "TypeError: interface takes exactly one argument" I am not sure what is the reason. I remember a post last year saying the the interface inheritance is implemented in a development brand and not integrated into main branch. not sure if it is the reason. I am using python 2.1.0.dev1. thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From denis.akhiyarov at gmail.com Mon Mar 14 19:18:23 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Mon, 14 Mar 2016 18:18:23 -0500 Subject: [Python.NET] Can Python.Net inherit .Net Interface Class In-Reply-To: References: Message-ID: The key is to define namespace, why is also different behavior from ironpython: Python 2.7.9 |Continuum Analytics, Inc.| (default, Dec 12 2014, 14:56:54) [MSC v .1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. Anaconda is brought to you by Continuum Analytics. Please check out:http://continuum.io/thanks andhttps://binstar.org >>> import clr Attempting to load Python.Runtime using standard binding rules... Attempting to load Python.Runtime from: 'C:\Python\Python27\lib\site-packages\Py thon.Runtime.dll'... >>> import System >>> class ViewModel(System.ComponentModel.INotifyPropertyChanged): ... __namespace__="blabla" ... def __init__(self): ... pass ... >>> ViewModel() <__main__.ViewModel object at 0x028784B0> On Sunday, March 13, 2016, Hansong Huang wrote: > I am attempting to implement a MVVM WPF application in Python.Net. > > The ViewModel class needs to implement the INotifyPropertyChanged > interface. > > class ViewModel(System.ComponentModel.INotifyPropertyChanged): > def __init__(self): > pass > > vm = ViewModel() > > gives exception: > "TypeError: interface takes exactly one argument" > > I am not sure what is the reason. > > I remember a post last year saying the the interface inheritance is > implemented in a development brand and not integrated into main branch. not > sure if it is the reason. > > I am using python 2.1.0.dev1. > > thanks > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sireistwa at gmail.com Mon Mar 14 21:45:06 2016 From: sireistwa at gmail.com (Simone Reis) Date: Mon, 14 Mar 2016 22:45:06 -0300 Subject: [Python.NET] How to make the distribution of python and python in a single exe file? Message-ID: How to make the distribution of python and pythonNet in a single exe file? I tried with py2exe and pyinstaler but always occur error in clr.pyd load. It only works when clr.pyd and Python.Runtime.dll are in the same folder and not compressed. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From denis.akhiyarov at gmail.com Tue Mar 15 21:41:09 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Tue, 15 Mar 2016 20:41:09 -0500 Subject: [Python.NET] How to make the distribution of python and python in a single exe file? In-Reply-To: References: Message-ID: This worked for others in the past (just google pythonnet + pyinstaller) - perhaps you need to provide us with your versions of cpython, pyinstaller, .Net/Mono, pythonnet, spec file? On Monday, March 14, 2016, Simone Reis wrote: > How to make the distribution of python and pythonNet in a single exe file? > I tried with py2exe and pyinstaler but always occur error in clr.pyd load. > It only works when clr.pyd and Python.Runtime.dll are in the same folder > and not compressed. > > Thanks > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nikhilgarg.gju at gmail.com Tue Mar 15 23:10:50 2016 From: nikhilgarg.gju at gmail.com (Nikhil Garg) Date: Wed, 16 Mar 2016 11:10:50 +0800 Subject: [Python.NET] pyinstaller + pythonnet Message-ID: Hi All, I tried to build a very simple executable using pyinstaller, where my script just imported clr module. I managed to build the executable but then the executable doesnt run. I have posted the error below. I think the executable is able to find the runtime dll but it is unable to run it. Unhandled Exception: System.IO.FileLoadException: Could not load file or assembl y 'Python.Runtime, Version=4.0.0.1, Culture=neutral, PublicKeyToken=5000fea6cba7 02dd' or one of its dependencies. The located assembly's manifest definition doe s not match the assembly reference. (Exception from HRESULT: 0x80131040) at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String cod eBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntro spection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName as semblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMar k& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIn trospection, Boolean suppressSecurityChecks) at System.Reflection.Assembly.Load(AssemblyName assemblyRef) at clrModule.initclr() I would appreciate any help -------------- next part -------------- An HTML attachment was scrubbed... URL: From denis.akhiyarov at gmail.com Wed Mar 16 11:15:52 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Wed, 16 Mar 2016 10:15:52 -0500 Subject: [Python.NET] pyinstaller + pythonnet In-Reply-To: References: Message-ID: Just add path to Python.Runtime.dll in your spec file using "datas" option. I guess pyinstaller only adds clr.pyd. On Tuesday, March 15, 2016, Nikhil Garg wrote: > Hi All, > > I tried to build a very simple executable using pyinstaller, where my > script just imported clr module. I managed to build the executable but then > the executable doesnt run. I have posted the error below. I think the > executable is able to find the runtime dll but it is unable to run it. > > > Unhandled Exception: System.IO.FileLoadException: Could not load file or > assembl > y 'Python.Runtime, Version=4.0.0.1, Culture=neutral, > PublicKeyToken=5000fea6cba7 > 02dd' or one of its dependencies. The located assembly's manifest > definition doe > s not match the assembly reference. (Exception from HRESULT: 0x80131040) > at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, > String cod > eBase, Evidence assemblySecurity, RuntimeAssembly locationHint, > StackCrawlMark& > stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean > forIntro > spection, Boolean suppressSecurityChecks) > at > System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName as > semblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, > StackCrawlMar > k& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean > forIn > trospection, Boolean suppressSecurityChecks) > at System.Reflection.Assembly.Load(AssemblyName assemblyRef) > at clrModule.initclr() > > > I would appreciate any help > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hhspiny at pine.cc Wed Mar 16 17:29:15 2016 From: hhspiny at pine.cc (Hansong Huang) Date: Wed, 16 Mar 2016 17:29:15 -0400 Subject: [Python.NET] Can a python class passed back to .Net Message-ID: This might be an obvious problem out of my lack of understanding how Python.Net work. I am exploring the possibility of program WPF ViewModel. After resolving the problem inheriting .Net interface class, class ViewModel(System.ComponentModel.INotifyPropertyChanged): __namespace__ = "WPFPy" .... class MyViewModel(ViewModel): .... here to implement follow ironpython examples then assign it to DataContext self.window = System.Windows.Markup.XamlReader.Load(outStream) self.window.DataContext = MyViewModel() this does not seem to work, the property/method in MyViewModel is never called nor any data binding happened. I was able to get ExpandoObject work well though and binding works fine self.window.DataContext = System.Dynamic.ExpandoObject() so, that makes me asking if it makes sense at all to pass a Python class object back into .Net framework and expect it works -- even if the proper interface is implemented. thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From tony at pyxll.com Thu Mar 17 12:48:45 2016 From: tony at pyxll.com (Tony Roberts) Date: Thu, 17 Mar 2016 16:48:45 +0000 Subject: [Python.NET] Can a python class passed back to .Net In-Reply-To: References: Message-ID: You have to decorate the methods you want to expose to .net with the clrmethod decorator, e.g. class MyClass(IInterface): @clrmethod(int, [str]) def overridden_method(self, x): return len(x) The parameters to the clrmethod decorator are the method return type and argument types. You can expose properties similarly using the clrproperty decorator. See runtime/resources/clr.py for details. regards, Tony On Wed, Mar 16, 2016 at 9:29 PM Hansong Huang wrote: > This might be an obvious problem out of my lack of understanding how > Python.Net work. > > I am exploring the possibility of program WPF ViewModel. > > After resolving the problem inheriting .Net interface class, > > class ViewModel(System.ComponentModel.INotifyPropertyChanged): > __namespace__ = "WPFPy" > .... > > class MyViewModel(ViewModel): > .... here to implement follow ironpython examples > > then assign it to DataContext > > self.window = System.Windows.Markup.XamlReader.Load(outStream) > self.window.DataContext = MyViewModel() > > this does not seem to work, the property/method in MyViewModel is never > called nor any data binding happened. > > I was able to get ExpandoObject work well though and binding works fine > self.window.DataContext = System.Dynamic.ExpandoObject() > > so, that makes me asking if it makes sense at all to pass a Python class > object back into .Net framework and expect it works -- even if the proper > interface is implemented. > > > thanks > > > > > > > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From tony at pyxll.com Thu Mar 17 12:48:45 2016 From: tony at pyxll.com (Tony Roberts) Date: Thu, 17 Mar 2016 16:48:45 +0000 Subject: [Python.NET] Can a python class passed back to .Net In-Reply-To: References: Message-ID: You have to decorate the methods you want to expose to .net with the clrmethod decorator, e.g. class MyClass(IInterface): @clrmethod(int, [str]) def overridden_method(self, x): return len(x) The parameters to the clrmethod decorator are the method return type and argument types. You can expose properties similarly using the clrproperty decorator. See runtime/resources/clr.py for details. regards, Tony On Wed, Mar 16, 2016 at 9:29 PM Hansong Huang wrote: > This might be an obvious problem out of my lack of understanding how > Python.Net work. > > I am exploring the possibility of program WPF ViewModel. > > After resolving the problem inheriting .Net interface class, > > class ViewModel(System.ComponentModel.INotifyPropertyChanged): > __namespace__ = "WPFPy" > .... > > class MyViewModel(ViewModel): > .... here to implement follow ironpython examples > > then assign it to DataContext > > self.window = System.Windows.Markup.XamlReader.Load(outStream) > self.window.DataContext = MyViewModel() > > this does not seem to work, the property/method in MyViewModel is never > called nor any data binding happened. > > I was able to get ExpandoObject work well though and binding works fine > self.window.DataContext = System.Dynamic.ExpandoObject() > > so, that makes me asking if it makes sense at all to pass a Python class > object back into .Net framework and expect it works -- even if the proper > interface is implemented. > > > thanks > > > > > > > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From royalstream at hotmail.com Wed Mar 30 15:38:22 2016 From: royalstream at hotmail.com (Steven Burns) Date: Wed, 30 Mar 2016 19:38:22 +0000 Subject: [Python.NET] PyTuple IDisposable implementation Message-ID: I'm creating PyTuple instances using the constructor. I noticed the constructor calls Runtime.Incref for each of the tuple elements. But PyTuple doesn't override PyObject's implementation of IDisposable. It's not clear to me when this references will be cleared. Thanks, Steven -------------- next part -------------- An HTML attachment was scrubbed... URL: From tony at pyxll.com Thu Mar 31 10:47:44 2016 From: tony at pyxll.com (Tony Roberts) Date: Thu, 31 Mar 2016 14:47:44 +0000 Subject: [Python.NET] PyTuple IDisposable implementation In-Reply-To: References: Message-ID: When the tuple is destroyed each of the members will have their reference count decremented. The tuple 'steals' the references of the members when it's constructed, hence why there's the call to Incref and no need for a corresponding decref. This happens in the Python C API and so there's no need to do anything in the C# code when the tuple is destroyed. On Wed, Mar 30, 2016 at 8:38 PM Steven Burns wrote: > I'm creating PyTuple instances using the constructor. > > I noticed the constructor calls Runtime.Incref for each of the tuple > elements. > > But PyTuple doesn't override PyObject's implementation of IDisposable. > > It's not clear to me when this references will be cleared. > > Thanks, > > Steven > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From royalstream at hotmail.com Thu Mar 31 16:30:35 2016 From: royalstream at hotmail.com (Steven Burns) Date: Thu, 31 Mar 2016 20:30:35 +0000 Subject: [Python.NET] PyTuple IDisposable implementation In-Reply-To: Message-ID: That makes perfect sense. I'm creating many PyTuple instances on the fly so I needed to make sure calling Dispose() was enough. Thanks ------ Original Message ------ From: "Tony Roberts" To: "A list for users and developers of Python for .NET" Sent: 3/31/2016 8:47:44 AM Subject: Re: [Python.NET] PyTuple IDisposable implementation >When the tuple is destroyed each of the members will have their >reference count decremented. The tuple 'steals' the references of the >members when it's constructed, hence why there's the call to Incref and >no need for a corresponding decref. This happens in the Python C API >and so there's no need to do anything in the C# code when the tuple is >destroyed. > >On Wed, Mar 30, 2016 at 8:38 PM Steven Burns >wrote: >>I'm creating PyTuple instances using the constructor. >> >>I noticed the constructor calls Runtime.Incref for each of the tuple >>elements. >> >>But PyTuple doesn't override PyObject's implementation of IDisposable. >> >>It's not clear to me when this references will be cleared. >> >>Thanks, >> >>Steven >> >> >>_________________________________________________ >>Python.NET mailing list - PythonDotNet at python.org >>https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From hhspiny at live.com Thu Mar 31 20:38:38 2016 From: hhspiny at live.com (Hansong Huang) Date: Thu, 31 Mar 2016 20:38:38 -0400 Subject: [Python.NET] How to handle INotifyPropertyChanged interface Message-ID: I am still trying to figure out how to implement WPF MVVM with Python.Net.Previously, I have successfully used System.Dynamic.ExpandoObject as a ViewModel container self.window = System.Windows.Markup.XamlReader.Load(outStream)self.window.DataContext = DotNetExpandoObject() where DotNetExpandoObject is a wrapper class for System.Dynamic.ExpandoObject class DotNetExpandoObject(System.Dynamic.ExpandoObject):... in which I redefined __getattr__ and __setattr__ it works flawlessly as System.Dynamic.ExpandoObject implements INotifyPropertyChange interface already Now, I would like to get away from using System.Dynamic.ExpandoObject but to implement my own I first tried to expose a python class back to .Netclass MyViewModel(System.Object): __namespace__ = "WPFPyDemo" def __init__(self): super(MyViewModel,self).__init__() self._inputText = "Line - in" @clr.clrproperty(str) def inputText(self): return self._inputText @inputText.setter def inputText(self,value): self._inputText = value self.OnPropertyChanged("inputText") self.window.DataContext = MyViewModel() The one direction data binding works fine, and the "Line - in" text correctly shows up in the textblock control.obviously this is not sufficient as there is no INotifyPropertyChange interface. So, I inherit the interface , and tries to implement the typical C# code" public event PropertyChangedEventHandler PropertyChanged" -- not sure how to handle event in Python.Net, the follow code probably is completely wrong class ViewModel(System.ComponentModel.INotifyPropertyChanged): __namespace__ = "WPFPy" def __init__(self): super(ViewModel, self).__init__() self.PropertyChanged = System.ComponentModel.PropertyChangedEventHandler def OnPropertyChanged(self, propertyName): if self.PropertyChanged != None: PropertyChanged(self, System.ComponentModel.PropertyChangedEventArgs(propertyName)) class MyViewModel(ViewModel): __namespace__ = "WPFPyDemo" def __init__(self): super(MyViewModel,self).__init__() self._inputText = "Line - in" @clr.clrproperty(str) def inputText(self): return self._inputText @inputText.setter def inputText(self,value): self._inputText = value self.OnPropertyChanged("inputText") The process terminates due to StackOverflowException. Looks like the error happens when WFP recoganized INotifyPropertyChange interface and tries to access MyViewModel class via it. -------------- next part -------------- An HTML attachment was scrubbed... URL: