From denis.akhiyarov at gmail.com Fri Apr 1 22:32:23 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Fri, 1 Apr 2016 21:32:23 -0500 Subject: [Python.NET] How to handle INotifyPropertyChanged interface In-Reply-To: References: Message-ID: All stackoverflow exceptions should be posted on stackoverflow! On Thursday, March 31, 2016, Hansong Huang wrote: > 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 .Net > class 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: From hhspiny at live.com Sat Apr 2 10:38:50 2016 From: hhspiny at live.com (Hansong Huang) Date: Sat, 2 Apr 2016 10:38:50 -0400 Subject: [Python.NET] How to handle INotifyPropertyChanged interface In-Reply-To: References: Message-ID: It seems inheriting from INotifyPropertyChanged is the cause self.window = System.Windows.Markup.XamlReader.Load(outStream)self.window.DataContext = MyViewModel()class 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") The above code works fine. but if switch inheritance to class MyViewModel(System.ComponentModel.INotifyPropertyChanged):and nothing else changed, python gives "The process terminates due to StackOverflowException" Not sure why. Thanks for the help From: hhspiny at live.com To: pythondotnet at python.org Subject: How to handle INotifyPropertyChanged interface Date: Thu, 31 Mar 2016 20:38:38 -0400 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: From tony at pyxll.com Sun Apr 3 11:20:47 2016 From: tony at pyxll.com (Tony Roberts) Date: Sun, 03 Apr 2016 15:20:47 +0000 Subject: [Python.NET] How to handle INotifyPropertyChanged interface In-Reply-To: References: Message-ID: What's the full stack trace? I suspect it's something to do with the event declared on the interface not being implemented. The managed type constructed doesn't define any events, so that would cause the construction of the type of fail - which is probably the error you're getting (although without the stack trace it's just an educated guess). It shouldn't be too hard to add events to the derived type if someone wanted to have a go at implementing it. The code is in the CreateDerivedType method in src/runtime/classderived.cs. To be consistent with how methods and properties work, it would need a clrevent function adding to the clr module (src/runtime/resource/clr.py) - maybe it could work like this: class MyClass(INotifyPropertyChanged): OnPropertyChanged = clr.clrevent(event_attributes, event_type) Then in classderived.cs the class any clrevents on the python class could be added to the managed type using TypeBuilder.DefineEvent. So, anyway - short answer is that what you're trying to do won't work without changes to pythonnet; but the changes required shouldn't be too hard if you wanted to have a go. Best regards, Tony On Sun, Apr 3, 2016 at 3:37 PM Hansong Huang wrote: > It seems inheriting from INotifyPropertyChanged is the cause > > self.window = System.Windows.Markup.XamlReader.Load(outStream) > self.window.DataContext = MyViewModel() > class 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") > > The above code works fine. > > but if switch inheritance to > class MyViewModel(System.ComponentModel.INotifyPropertyChanged): > and nothing else changed, python gives > > "The process terminates due to StackOverflowException" > > Not sure why. > > > Thanks for the help > > ------------------------------ > From: hhspiny at live.com > To: pythondotnet at python.org > Subject: How to handle INotifyPropertyChanged interface > Date: Thu, 31 Mar 2016 20:38:38 -0400 > > > 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 .Net > class 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. > _________________________________________________ > 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 Sun Apr 3 11:40:17 2016 From: tony at pyxll.com (Tony Roberts) Date: Sun, 03 Apr 2016 15:40:17 +0000 Subject: [Python.NET] How to handle INotifyPropertyChanged interface In-Reply-To: References: Message-ID: Yeah, it looks like the crash is probably because of the missing event implementation as suspected. I'm a bit surprised that it didn't fail earlier when trying to instantiate the type. If you do get a chance to take a look at adding that functionality be sure to submit a pull request! Best regards, Tony On Sun, Apr 3, 2016 at 4:30 PM Hansong Huang wrote: > Tony, > > thanks for the hint. > > the event PropertyChanged was declared in INotifyPropertyChanged interface > by pythonnet, but obviously not implemented. > [('PropertyChanged', ), > > anyway, the stackoverflow only happens if both following are present > 1. the class is derived from INotifyPropertyChanged interface > 2. the class exposes property back to .Net vis @clrproperty > > which seems to prove that it is the PropertyChanged event that is not > implemented in python class resulted in the crash. > > I was not sure if .Net event can be handled by pythonnet. I found a few > examples with IronPython, but there, a python class of "event" seems to be > implemented instead. > > Below is the stack trace > > > [External Code] > clr.dll!CallDescrWorkerInternal () Unknown > clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown > clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class > Frame *) Unknown > clr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class PtrArray > *,class SignatureNative *,bool) Unknown > mscorlib.ni.dll!00007fffb86e1ca4() Unknown > mscorlib.ni.dll!00007fffb8618272() Unknown > mscorlib.ni.dll!00007fffb867fc4a() Unknown > [External Code] > mscorlib.ni.dll!00007fffb86dbaf5() Unknown > mscorlib.ni.dll!00007fffb86d281f() Unknown > System.ni.dll!00007fffb77556d4() Unknown > System.ni.dll!00007fffb7755637() Unknown > System.ni.dll!00007fffb775541d() Unknown > PresentationFramework.ni.dll!00007fff96c1ca70() Unknown > PresentationFramework.ni.dll!00007fff96c23902() Unknown > PresentationFramework.ni.dll!00007fff96c22ea1() Unknown > PresentationFramework.ni.dll!00007fff96c22693() Unknown > PresentationFramework.ni.dll!00007fff96c223c9() Unknown > PresentationFramework.ni.dll!00007fff96c21a03() Unknown > PresentationFramework.ni.dll!00007fff96c0d84c() Unknown > PresentationFramework.ni.dll!00007fff96b97299() Unknown > PresentationFramework.ni.dll!00007fff96b9720e() Unknown > PresentationFramework.ni.dll!00007fff96c852f0() Unknown > WindowsBase.ni.dll!00007fff9f6f9bc9() Unknown > WindowsBase.ni.dll!00007fff9f6f9ac6() Unknown > WindowsBase.ni.dll!00007fff9f6fca2b() Unknown > mscorlib.ni.dll!00007fffb86ca79e() Unknown > mscorlib.ni.dll!00007fffb86ca637() Unknown > mscorlib.ni.dll!00007fffb86ca5f2() Unknown > WindowsBase.ni.dll!00007fff9f913810() Unknown > WindowsBase.ni.dll!00007fff9f6fc784() Unknown > WindowsBase.ni.dll!00007fff9f6f7c24() Unknown > WindowsBase.ni.dll!00007fff9f6f8061() Unknown > WindowsBase.ni.dll!00007fff9f6f9e53() Unknown > WindowsBase.ni.dll!00007fff9f6f9d82() Unknown > WindowsBase.ni.dll!00007fff9f6f9bc9() Unknown > WindowsBase.ni.dll!00007fff9f6f9ac6() Unknown > WindowsBase.ni.dll!00007fff9f6f7583() Unknown > WindowsBase.ni.dll!00007fff9f6f94ff() Unknown > WindowsBase.ni.dll!00007fff9f8c496a() Unknown > clr.dll!UMThunkStub () Unknown > user32.dll!UserCallWinProcCheckWow() Unknown > user32.dll!DispatchMessageWorker() Unknown > WindowsBase.ni.dll!00007fff9f730ee8() Unknown > WindowsBase.ni.dll!00007fff9f70d8fc() Unknown > PresentationFramework.ni.dll!00007fff96af98b3() Unknown > PresentationFramework.ni.dll!00007fff96af969d() Unknown > clr.dll!CallDescrWorkerInternal () Unknown > clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown > clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class > Frame *) Unknown > clr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class PtrArray > *,class SignatureNative *,bool) Unknown > mscorlib.ni.dll!00007fffb86e1c20() Unknown > mscorlib.ni.dll!00007fffb8618272() Unknown > [External Code] > clr.dll!UMThunkStub () Unknown > [External Code] > > WPFPy.py!threadStart Line 256 Python > [External Code] > > > ------------------------------ > From: tony at pyxll.com > Date: Sun, 3 Apr 2016 15:20:47 +0000 > Subject: Re: [Python.NET] How to handle INotifyPropertyChanged interface > To: hhspiny at pine.cc; pythondotnet at python.org > > > What's the full stack trace? > > I suspect it's something to do with the event declared on the interface > not being implemented. The managed type constructed doesn't define any > events, so that would cause the construction of the type of fail - which is > probably the error you're getting (although without the stack trace it's > just an educated guess). > > It shouldn't be too hard to add events to the derived type if someone > wanted to have a go at implementing it. The code is in the > CreateDerivedType method in src/runtime/classderived.cs. To be consistent > with how methods and properties work, it would need a clrevent function > adding to the clr module (src/runtime/resource/clr.py) - maybe it could > work like this: > > class MyClass(INotifyPropertyChanged): > OnPropertyChanged = clr.clrevent(event_attributes, event_type) > > Then in classderived.cs the class any clrevents on the python class could > be added to the managed type using TypeBuilder.DefineEvent. > > So, anyway - short answer is that what you're trying to do won't work > without changes to pythonnet; but the changes required shouldn't be too > hard if you wanted to have a go. > > Best regards, > Tony > > > On Sun, Apr 3, 2016 at 3:37 PM Hansong Huang wrote: > > It seems inheriting from INotifyPropertyChanged is the cause > > self.window = System.Windows.Markup.XamlReader.Load(outStream) > self.window.DataContext = MyViewModel() > class 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") > > The above code works fine. > > but if switch inheritance to > class MyViewModel(System.ComponentModel.INotifyPropertyChanged): > and nothing else changed, python gives > > "The process terminates due to StackOverflowException" > > Not sure why. > > > Thanks for the help > > ------------------------------ > From: hhspiny at live.com > To: pythondotnet at python.org > Subject: How to handle INotifyPropertyChanged interface > Date: Thu, 31 Mar 2016 20:38:38 -0400 > > > 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 .Net > class 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. > _________________________________________________ > 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 Sun Apr 3 11:30:49 2016 From: hhspiny at live.com (Hansong Huang) Date: Sun, 3 Apr 2016 11:30:49 -0400 Subject: [Python.NET] How to handle INotifyPropertyChanged interface In-Reply-To: References: , Message-ID: Tony, thanks for the hint. the event PropertyChanged was declared in INotifyPropertyChanged interface by pythonnet, but obviously not implemented. [('PropertyChanged', ), anyway, the stackoverflow only happens if both following are present1. the class is derived from INotifyPropertyChanged interface2. the class exposes property back to .Net vis @clrproperty which seems to prove that it is the PropertyChanged event that is not implemented in python class resulted in the crash. I was not sure if .Net event can be handled by pythonnet. I found a few examples with IronPython, but there, a python class of "event" seems to be implemented instead. Below is the stack trace [External Code] clr.dll!CallDescrWorkerInternal () Unknown clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class Frame *) Unknown clr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class PtrArray *,class SignatureNative *,bool) Unknown mscorlib.ni.dll!00007fffb86e1ca4() Unknown mscorlib.ni.dll!00007fffb8618272() Unknown mscorlib.ni.dll!00007fffb867fc4a() Unknown [External Code] mscorlib.ni.dll!00007fffb86dbaf5() Unknown mscorlib.ni.dll!00007fffb86d281f() Unknown System.ni.dll!00007fffb77556d4() Unknown System.ni.dll!00007fffb7755637() Unknown System.ni.dll!00007fffb775541d() Unknown PresentationFramework.ni.dll!00007fff96c1ca70() Unknown PresentationFramework.ni.dll!00007fff96c23902() Unknown PresentationFramework.ni.dll!00007fff96c22ea1() Unknown PresentationFramework.ni.dll!00007fff96c22693() Unknown PresentationFramework.ni.dll!00007fff96c223c9() Unknown PresentationFramework.ni.dll!00007fff96c21a03() Unknown PresentationFramework.ni.dll!00007fff96c0d84c() Unknown PresentationFramework.ni.dll!00007fff96b97299() Unknown PresentationFramework.ni.dll!00007fff96b9720e() Unknown PresentationFramework.ni.dll!00007fff96c852f0() Unknown WindowsBase.ni.dll!00007fff9f6f9bc9() Unknown WindowsBase.ni.dll!00007fff9f6f9ac6() Unknown WindowsBase.ni.dll!00007fff9f6fca2b() Unknown mscorlib.ni.dll!00007fffb86ca79e() Unknown mscorlib.ni.dll!00007fffb86ca637() Unknown mscorlib.ni.dll!00007fffb86ca5f2() Unknown WindowsBase.ni.dll!00007fff9f913810() Unknown WindowsBase.ni.dll!00007fff9f6fc784() Unknown WindowsBase.ni.dll!00007fff9f6f7c24() Unknown WindowsBase.ni.dll!00007fff9f6f8061() Unknown WindowsBase.ni.dll!00007fff9f6f9e53() Unknown WindowsBase.ni.dll!00007fff9f6f9d82() Unknown WindowsBase.ni.dll!00007fff9f6f9bc9() Unknown WindowsBase.ni.dll!00007fff9f6f9ac6() Unknown WindowsBase.ni.dll!00007fff9f6f7583() Unknown WindowsBase.ni.dll!00007fff9f6f94ff() Unknown WindowsBase.ni.dll!00007fff9f8c496a() Unknown clr.dll!UMThunkStub () Unknown user32.dll!UserCallWinProcCheckWow() Unknown user32.dll!DispatchMessageWorker() Unknown WindowsBase.ni.dll!00007fff9f730ee8() Unknown WindowsBase.ni.dll!00007fff9f70d8fc() Unknown PresentationFramework.ni.dll!00007fff96af98b3() Unknown PresentationFramework.ni.dll!00007fff96af969d() Unknown clr.dll!CallDescrWorkerInternal () Unknown clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class Frame *) Unknown clr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class PtrArray *,class SignatureNative *,bool) Unknown mscorlib.ni.dll!00007fffb86e1c20() Unknown mscorlib.ni.dll!00007fffb8618272() Unknown [External Code] clr.dll!UMThunkStub () Unknown [External Code] > WPFPy.py!threadStart Line 256 Python [External Code] From: tony at pyxll.com Date: Sun, 3 Apr 2016 15:20:47 +0000 Subject: Re: [Python.NET] How to handle INotifyPropertyChanged interface To: hhspiny at pine.cc; pythondotnet at python.org What's the full stack trace? I suspect it's something to do with the event declared on the interface not being implemented. The managed type constructed doesn't define any events, so that would cause the construction of the type of fail - which is probably the error you're getting (although without the stack trace it's just an educated guess). It shouldn't be too hard to add events to the derived type if someone wanted to have a go at implementing it. The code is in the CreateDerivedType method in src/runtime/classderived.cs. To be consistent with how methods and properties work, it would need a clrevent function adding to the clr module (src/runtime/resource/clr.py) - maybe it could work like this: class MyClass(INotifyPropertyChanged): OnPropertyChanged = clr.clrevent(event_attributes, event_type) Then in classderived.cs the class any clrevents on the python class could be added to the managed type using TypeBuilder.DefineEvent. So, anyway - short answer is that what you're trying to do won't work without changes to pythonnet; but the changes required shouldn't be too hard if you wanted to have a go. Best regards, Tony On Sun, Apr 3, 2016 at 3:37 PM Hansong Huang wrote: It seems inheriting from INotifyPropertyChanged is the cause self.window = System.Windows.Markup.XamlReader.Load(outStream)self.window.DataContext = MyViewModel()class 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") The above code works fine. but if switch inheritance to class MyViewModel(System.ComponentModel.INotifyPropertyChanged):and nothing else changed, python gives "The process terminates due to StackOverflowException" Not sure why. Thanks for the help From: hhspiny at live.com To: pythondotnet at python.org Subject: How to handle INotifyPropertyChanged interface Date: Thu, 31 Mar 2016 20:38:38 -0400 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. _________________________________________________ Python.NET mailing list - PythonDotNet at python.org https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From denis.akhiyarov at gmail.com Sun Apr 3 12:08:50 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Sun, 3 Apr 2016 11:08:50 -0500 Subject: [Python.NET] How to handle INotifyPropertyChanged interface In-Reply-To: References: Message-ID: is it possible to workaround this non-implemented feature by using ___setattr__() hook? seems like people were able to do this in ironpython: http://stackoverflow.com/questions/3856905/ On Sun, Apr 3, 2016 at 10:40 AM, Tony Roberts wrote: > Yeah, it looks like the crash is probably because of the missing event > implementation as suspected. I'm a bit surprised that it didn't fail > earlier when trying to instantiate the type. > > If you do get a chance to take a look at adding that functionality be sure > to submit a pull request! > > Best regards, > Tony > > > On Sun, Apr 3, 2016 at 4:30 PM Hansong Huang wrote: > >> Tony, >> >> thanks for the hint. >> >> the event PropertyChanged was declared in INotifyPropertyChanged >> interface by pythonnet, but obviously not implemented. >> [('PropertyChanged', ), >> >> anyway, the stackoverflow only happens if both following are present >> 1. the class is derived from INotifyPropertyChanged interface >> 2. the class exposes property back to .Net vis @clrproperty >> >> which seems to prove that it is the PropertyChanged event that is not >> implemented in python class resulted in the crash. >> >> I was not sure if .Net event can be handled by pythonnet. I found a few >> examples with IronPython, but there, a python class of "event" seems to be >> implemented instead. >> >> Below is the stack trace >> >> >> [External Code] >> clr.dll!CallDescrWorkerInternal () Unknown >> clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown >> clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class >> Frame *) Unknown >> clr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class >> PtrArray *,class SignatureNative *,bool) Unknown >> mscorlib.ni.dll!00007fffb86e1ca4() Unknown >> mscorlib.ni.dll!00007fffb8618272() Unknown >> mscorlib.ni.dll!00007fffb867fc4a() Unknown >> [External Code] >> mscorlib.ni.dll!00007fffb86dbaf5() Unknown >> mscorlib.ni.dll!00007fffb86d281f() Unknown >> System.ni.dll!00007fffb77556d4() Unknown >> System.ni.dll!00007fffb7755637() Unknown >> System.ni.dll!00007fffb775541d() Unknown >> PresentationFramework.ni.dll!00007fff96c1ca70() Unknown >> PresentationFramework.ni.dll!00007fff96c23902() Unknown >> PresentationFramework.ni.dll!00007fff96c22ea1() Unknown >> PresentationFramework.ni.dll!00007fff96c22693() Unknown >> PresentationFramework.ni.dll!00007fff96c223c9() Unknown >> PresentationFramework.ni.dll!00007fff96c21a03() Unknown >> PresentationFramework.ni.dll!00007fff96c0d84c() Unknown >> PresentationFramework.ni.dll!00007fff96b97299() Unknown >> PresentationFramework.ni.dll!00007fff96b9720e() Unknown >> PresentationFramework.ni.dll!00007fff96c852f0() Unknown >> WindowsBase.ni.dll!00007fff9f6f9bc9() Unknown >> WindowsBase.ni.dll!00007fff9f6f9ac6() Unknown >> WindowsBase.ni.dll!00007fff9f6fca2b() Unknown >> mscorlib.ni.dll!00007fffb86ca79e() Unknown >> mscorlib.ni.dll!00007fffb86ca637() Unknown >> mscorlib.ni.dll!00007fffb86ca5f2() Unknown >> WindowsBase.ni.dll!00007fff9f913810() Unknown >> WindowsBase.ni.dll!00007fff9f6fc784() Unknown >> WindowsBase.ni.dll!00007fff9f6f7c24() Unknown >> WindowsBase.ni.dll!00007fff9f6f8061() Unknown >> WindowsBase.ni.dll!00007fff9f6f9e53() Unknown >> WindowsBase.ni.dll!00007fff9f6f9d82() Unknown >> WindowsBase.ni.dll!00007fff9f6f9bc9() Unknown >> WindowsBase.ni.dll!00007fff9f6f9ac6() Unknown >> WindowsBase.ni.dll!00007fff9f6f7583() Unknown >> WindowsBase.ni.dll!00007fff9f6f94ff() Unknown >> WindowsBase.ni.dll!00007fff9f8c496a() Unknown >> clr.dll!UMThunkStub () Unknown >> user32.dll!UserCallWinProcCheckWow() Unknown >> user32.dll!DispatchMessageWorker() Unknown >> WindowsBase.ni.dll!00007fff9f730ee8() Unknown >> WindowsBase.ni.dll!00007fff9f70d8fc() Unknown >> PresentationFramework.ni.dll!00007fff96af98b3() Unknown >> PresentationFramework.ni.dll!00007fff96af969d() Unknown >> clr.dll!CallDescrWorkerInternal () Unknown >> clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown >> clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class >> Frame *) Unknown >> clr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class >> PtrArray *,class SignatureNative *,bool) Unknown >> mscorlib.ni.dll!00007fffb86e1c20() Unknown >> mscorlib.ni.dll!00007fffb8618272() Unknown >> [External Code] >> clr.dll!UMThunkStub () Unknown >> [External Code] >> > WPFPy.py!threadStart Line 256 Python >> [External Code] >> >> >> ------------------------------ >> From: tony at pyxll.com >> Date: Sun, 3 Apr 2016 15:20:47 +0000 >> Subject: Re: [Python.NET] How to handle INotifyPropertyChanged interface >> To: hhspiny at pine.cc; pythondotnet at python.org >> >> >> What's the full stack trace? >> >> I suspect it's something to do with the event declared on the interface >> not being implemented. The managed type constructed doesn't define any >> events, so that would cause the construction of the type of fail - which is >> probably the error you're getting (although without the stack trace it's >> just an educated guess). >> >> It shouldn't be too hard to add events to the derived type if someone >> wanted to have a go at implementing it. The code is in the >> CreateDerivedType method in src/runtime/classderived.cs. To be consistent >> with how methods and properties work, it would need a clrevent function >> adding to the clr module (src/runtime/resource/clr.py) - maybe it could >> work like this: >> >> class MyClass(INotifyPropertyChanged): >> OnPropertyChanged = clr.clrevent(event_attributes, event_type) >> >> Then in classderived.cs the class any clrevents on the python class could >> be added to the managed type using TypeBuilder.DefineEvent. >> >> So, anyway - short answer is that what you're trying to do won't work >> without changes to pythonnet; but the changes required shouldn't be too >> hard if you wanted to have a go. >> >> Best regards, >> Tony >> >> >> On Sun, Apr 3, 2016 at 3:37 PM Hansong Huang wrote: >> >> It seems inheriting from INotifyPropertyChanged is the cause >> >> self.window = System.Windows.Markup.XamlReader.Load(outStream) >> self.window.DataContext = MyViewModel() >> class 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") >> >> The above code works fine. >> >> but if switch inheritance to >> class MyViewModel(System.ComponentModel.INotifyPropertyChanged): >> and nothing else changed, python gives >> >> "The process terminates due to StackOverflowException" >> >> Not sure why. >> >> >> Thanks for the help >> >> ------------------------------ >> From: hhspiny at live.com >> To: pythondotnet at python.org >> Subject: How to handle INotifyPropertyChanged interface >> Date: Thu, 31 Mar 2016 20:38:38 -0400 >> >> >> 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 .Net >> class 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. >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> https://mail.python.org/mailman/listinfo/pythondotnet >> >> > _________________________________________________ > 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 Sun Apr 3 21:55:29 2016 From: hhspiny at live.com (Hansong Huang) Date: Sun, 3 Apr 2016 21:55:29 -0400 Subject: [Python.NET] PythonDotNet Digest, Vol 141, Issue 6 In-Reply-To: References: Message-ID: Here is how I understand IronPython's implementation .Net expects an event to be defined by the class that implements INotifyPropertyChanged interface. However, as python does not support event type, IronPython created two methods at its interface with .Net: add_PropertyChanged and remove_PropertyChanged. hence, whenever .Net would add or remove a handler from this event, these two methods are called instead. then a separate python class is created within IronPython to actual track and invoke callback functions. well, looks like Python.Net implemented exactly the same as IronPython. dir(System.ComponentModel.INotifyPropertyChanged) ==>['PropertyChanged', '__class__', '__cmp__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__iter__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'add_PropertyChanged', 'remove_PropertyChanged']so, in principle the same implementation as in IronPython should work. but instead, I got stackoverflow here is my implementation:make_event() and event() and even_handler() classes are copied from IronPython examples, used to track and invoke callback functions class ViewModel(System.ComponentModel.INotifyPropertyChanged): ''' this does not work. PropertyChanged event can not be implemented yet''' __namespace__ = "ViewModel" PropertyChanged == None def __init__(self): super(ViewModel, self).__init__() self.PropertyChanged, self._propertyChangedCaller = make_event() @clr.clrmethod(None, [System.ComponentModel.PropertyChangedEventHandler]) def add_PropertyChanged(self, value): self.PropertyChanged += value @clr.clrmethod(None, [System.ComponentModel.PropertyChangedEventHandler]) def remove_PropertyChanged(self, value): self.PropertyChanged -= value def OnPropertyChanged(self, propertyName): if self.PropertyChanged != None: self._propertyChangedCaller(self, System.ComponentModel.PropertyChangedEventArgs(propertyName)) One possible reason might be that the types specified in @clr.clrmethod is not correct, therefore, .Net could not find the right method to call. Hansong > ---------------------------------------------------------------------- > > Message: 1 > Date: Sun, 3 Apr 2016 11:08:50 -0500 > From: Denis Akhiyarov > To: "A list for users and developers of Python for .NET" > > Subject: Re: [Python.NET] How to handle INotifyPropertyChanged > interface > Message-ID: > > Content-Type: text/plain; charset="utf-8" > > is it possible to workaround this non-implemented feature by using > ___setattr__() hook? seems like people were able to do this in ironpython: > > http://stackoverflow.com/questions/3856905/ > > On Sun, Apr 3, 2016 at 10:40 AM, Tony Roberts wrote: > > > Yeah, it looks like the crash is probably because of the missing event > > implementation as suspected. I'm a bit surprised that it didn't fail > > earlier when trying to instantiate the type. > > > > If you do get a chance to take a look at adding that functionality be sure > > to submit a pull request! > > > > Best regards, > > Tony > > > > > > On Sun, Apr 3, 2016 at 4:30 PM Hansong Huang wrote: > > > >> Tony, > >> > >> thanks for the hint. > >> > >> the event PropertyChanged was declared in INotifyPropertyChanged > >> interface by pythonnet, but obviously not implemented. > >> [('PropertyChanged', ), > >> > >> anyway, the stackoverflow only happens if both following are present > >> 1. the class is derived from INotifyPropertyChanged interface > >> 2. the class exposes property back to .Net vis @clrproperty > >> > >> which seems to prove that it is the PropertyChanged event that is not > >> implemented in python class resulted in the crash. > >> > >> I was not sure if .Net event can be handled by pythonnet. I found a few > >> examples with IronPython, but there, a python class of "event" seems to be > >> implemented instead. > >> > >> Below is the stack trace > >> > >> > >> [External Code] > >> clr.dll!CallDescrWorkerInternal () Unknown > >> clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown > >> clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class > >> Frame *) Unknown > >> clr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class > >> PtrArray *,class SignatureNative *,bool) Unknown > >> mscorlib.ni.dll!00007fffb86e1ca4() Unknown > >> mscorlib.ni.dll!00007fffb8618272() Unknown > >> mscorlib.ni.dll!00007fffb867fc4a() Unknown > >> [External Code] > >> mscorlib.ni.dll!00007fffb86dbaf5() Unknown > >> mscorlib.ni.dll!00007fffb86d281f() Unknown > >> System.ni.dll!00007fffb77556d4() Unknown > >> System.ni.dll!00007fffb7755637() Unknown > >> System.ni.dll!00007fffb775541d() Unknown > >> PresentationFramework.ni.dll!00007fff96c1ca70() Unknown > >> PresentationFramework.ni.dll!00007fff96c23902() Unknown > >> PresentationFramework.ni.dll!00007fff96c22ea1() Unknown > >> PresentationFramework.ni.dll!00007fff96c22693() Unknown > >> PresentationFramework.ni.dll!00007fff96c223c9() Unknown > >> PresentationFramework.ni.dll!00007fff96c21a03() Unknown > >> PresentationFramework.ni.dll!00007fff96c0d84c() Unknown > >> PresentationFramework.ni.dll!00007fff96b97299() Unknown > >> PresentationFramework.ni.dll!00007fff96b9720e() Unknown > >> PresentationFramework.ni.dll!00007fff96c852f0() Unknown > >> WindowsBase.ni.dll!00007fff9f6f9bc9() Unknown > >> WindowsBase.ni.dll!00007fff9f6f9ac6() Unknown > >> WindowsBase.ni.dll!00007fff9f6fca2b() Unknown > >> mscorlib.ni.dll!00007fffb86ca79e() Unknown > >> mscorlib.ni.dll!00007fffb86ca637() Unknown > >> mscorlib.ni.dll!00007fffb86ca5f2() Unknown > >> WindowsBase.ni.dll!00007fff9f913810() Unknown > >> WindowsBase.ni.dll!00007fff9f6fc784() Unknown > >> WindowsBase.ni.dll!00007fff9f6f7c24() Unknown > >> WindowsBase.ni.dll!00007fff9f6f8061() Unknown > >> WindowsBase.ni.dll!00007fff9f6f9e53() Unknown > >> WindowsBase.ni.dll!00007fff9f6f9d82() Unknown > >> WindowsBase.ni.dll!00007fff9f6f9bc9() Unknown > >> WindowsBase.ni.dll!00007fff9f6f9ac6() Unknown > >> WindowsBase.ni.dll!00007fff9f6f7583() Unknown > >> WindowsBase.ni.dll!00007fff9f6f94ff() Unknown > >> WindowsBase.ni.dll!00007fff9f8c496a() Unknown > >> clr.dll!UMThunkStub () Unknown > >> user32.dll!UserCallWinProcCheckWow() Unknown > >> user32.dll!DispatchMessageWorker() Unknown > >> WindowsBase.ni.dll!00007fff9f730ee8() Unknown > >> WindowsBase.ni.dll!00007fff9f70d8fc() Unknown > >> PresentationFramework.ni.dll!00007fff96af98b3() Unknown > >> PresentationFramework.ni.dll!00007fff96af969d() Unknown > >> clr.dll!CallDescrWorkerInternal () Unknown > >> clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown > >> clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class > >> Frame *) Unknown > >> clr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class > >> PtrArray *,class SignatureNative *,bool) Unknown > >> mscorlib.ni.dll!00007fffb86e1c20() Unknown > >> mscorlib.ni.dll!00007fffb8618272() Unknown > >> [External Code] > >> clr.dll!UMThunkStub () Unknown > >> [External Code] > >> > WPFPy.py!threadStart Line 256 Python > >> [External Code] > >> > >> > >> ------------------------------ > >> From: tony at pyxll.com > >> Date: Sun, 3 Apr 2016 15:20:47 +0000 > >> Subject: Re: [Python.NET] How to handle INotifyPropertyChanged interface > >> To: hhspiny at pine.cc; pythondotnet at python.org > >> > >> > >> What's the full stack trace? > >> > >> I suspect it's something to do with the event declared on the interface > >> not being implemented. The managed type constructed doesn't define any > >> events, so that would cause the construction of the type of fail - which is > >> probably the error you're getting (although without the stack trace it's > >> just an educated guess). > >> > >> It shouldn't be too hard to add events to the derived type if someone > >> wanted to have a go at implementing it. The code is in the > >> CreateDerivedType method in src/runtime/classderived.cs. To be consistent > >> with how methods and properties work, it would need a clrevent function > >> adding to the clr module (src/runtime/resource/clr.py) - maybe it could > >> work like this: > >> > >> class MyClass(INotifyPropertyChanged): > >> OnPropertyChanged = clr.clrevent(event_attributes, event_type) > >> > >> Then in classderived.cs the class any clrevents on the python class could > >> be added to the managed type using TypeBuilder.DefineEvent. > >> > >> So, anyway - short answer is that what you're trying to do won't work > >> without changes to pythonnet; but the changes required shouldn't be too > >> hard if you wanted to have a go. > >> > >> Best regards, > >> Tony > >> > >> > >> On Sun, Apr 3, 2016 at 3:37 PM Hansong Huang wrote: > >> > >> It seems inheriting from INotifyPropertyChanged is the cause > >> > >> self.window = System.Windows.Markup.XamlReader.Load(outStream) > >> self.window.DataContext = MyViewModel() > >> class 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") > >> > >> The above code works fine. > >> > >> but if switch inheritance to > >> class MyViewModel(System.ComponentModel.INotifyPropertyChanged): > >> and nothing else changed, python gives > >> > >> "The process terminates due to StackOverflowException" > >> > >> Not sure why. > >> > >> > >> Thanks for the help > >> > >> ------------------------------ > >> From: hhspiny at live.com > >> To: pythondotnet at python.org > >> Subject: How to handle INotifyPropertyChanged interface > >> Date: Thu, 31 Mar 2016 20:38:38 -0400 > >> > >> > >> 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 .Net > >> class 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. > >> _________________________________________________ > >> Python.NET mailing list - PythonDotNet at python.org > >> https://mail.python.org/mailman/listinfo/pythondotnet > >> > >> > > _________________________________________________ > > Python.NET mailing list - PythonDotNet at python.org > > https://mail.python.org/mailman/listinfo/pythondotnet > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > PythonDotNet mailing list > PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet > > > ------------------------------ > > End of PythonDotNet Digest, Vol 141, Issue 6 > ******************************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: From tony at pyxll.com Mon Apr 4 08:31:06 2016 From: tony at pyxll.com (Tony Roberts) Date: Mon, 04 Apr 2016 12:31:06 +0000 Subject: [Python.NET] How to handle INotifyPropertyChanged interface In-Reply-To: References: Message-ID: I've fixed the crash bug and added a couple of tests (see PR #196, already merged into develop). For an example of how to implement an event declared on an interface see testEvents in src/tests/test_subclass.py. Note that it's a pretty simple implementation and isn't thread safe so may need modifying if you need it to be. This could be wrapped up into something a bit more friendly, but it works for now. Best regards, Tony On Sun, Apr 3, 2016 at 6:57 PM Denis Akhiyarov wrote: > is it possible to workaround this non-implemented feature by using > ___setattr__() hook? seems like people were able to do this in ironpython: > > http://stackoverflow.com/questions/3856905/ > > On Sun, Apr 3, 2016 at 10:40 AM, Tony Roberts wrote: > >> Yeah, it looks like the crash is probably because of the missing event >> implementation as suspected. I'm a bit surprised that it didn't fail >> earlier when trying to instantiate the type. >> >> If you do get a chance to take a look at adding that functionality be >> sure to submit a pull request! >> >> Best regards, >> Tony >> >> >> On Sun, Apr 3, 2016 at 4:30 PM Hansong Huang wrote: >> >>> Tony, >>> >>> thanks for the hint. >>> >>> the event PropertyChanged was declared in INotifyPropertyChanged >>> interface by pythonnet, but obviously not implemented. >>> [('PropertyChanged', ), >>> >>> anyway, the stackoverflow only happens if both following are present >>> 1. the class is derived from INotifyPropertyChanged interface >>> 2. the class exposes property back to .Net vis @clrproperty >>> >>> which seems to prove that it is the PropertyChanged event that is not >>> implemented in python class resulted in the crash. >>> >>> I was not sure if .Net event can be handled by pythonnet. I found a few >>> examples with IronPython, but there, a python class of "event" seems to be >>> implemented instead. >>> >>> Below is the stack trace >>> >>> >>> [External Code] >>> clr.dll!CallDescrWorkerInternal () Unknown >>> clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown >>> clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class >>> Frame *) Unknown >>> clr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class >>> PtrArray *,class SignatureNative *,bool) Unknown >>> mscorlib.ni.dll!00007fffb86e1ca4() Unknown >>> mscorlib.ni.dll!00007fffb8618272() Unknown >>> mscorlib.ni.dll!00007fffb867fc4a() Unknown >>> [External Code] >>> mscorlib.ni.dll!00007fffb86dbaf5() Unknown >>> mscorlib.ni.dll!00007fffb86d281f() Unknown >>> System.ni.dll!00007fffb77556d4() Unknown >>> System.ni.dll!00007fffb7755637() Unknown >>> System.ni.dll!00007fffb775541d() Unknown >>> PresentationFramework.ni.dll!00007fff96c1ca70() Unknown >>> PresentationFramework.ni.dll!00007fff96c23902() Unknown >>> PresentationFramework.ni.dll!00007fff96c22ea1() Unknown >>> PresentationFramework.ni.dll!00007fff96c22693() Unknown >>> PresentationFramework.ni.dll!00007fff96c223c9() Unknown >>> PresentationFramework.ni.dll!00007fff96c21a03() Unknown >>> PresentationFramework.ni.dll!00007fff96c0d84c() Unknown >>> PresentationFramework.ni.dll!00007fff96b97299() Unknown >>> PresentationFramework.ni.dll!00007fff96b9720e() Unknown >>> PresentationFramework.ni.dll!00007fff96c852f0() Unknown >>> WindowsBase.ni.dll!00007fff9f6f9bc9() Unknown >>> WindowsBase.ni.dll!00007fff9f6f9ac6() Unknown >>> WindowsBase.ni.dll!00007fff9f6fca2b() Unknown >>> mscorlib.ni.dll!00007fffb86ca79e() Unknown >>> mscorlib.ni.dll!00007fffb86ca637() Unknown >>> mscorlib.ni.dll!00007fffb86ca5f2() Unknown >>> WindowsBase.ni.dll!00007fff9f913810() Unknown >>> WindowsBase.ni.dll!00007fff9f6fc784() Unknown >>> WindowsBase.ni.dll!00007fff9f6f7c24() Unknown >>> WindowsBase.ni.dll!00007fff9f6f8061() Unknown >>> WindowsBase.ni.dll!00007fff9f6f9e53() Unknown >>> WindowsBase.ni.dll!00007fff9f6f9d82() Unknown >>> WindowsBase.ni.dll!00007fff9f6f9bc9() Unknown >>> WindowsBase.ni.dll!00007fff9f6f9ac6() Unknown >>> WindowsBase.ni.dll!00007fff9f6f7583() Unknown >>> WindowsBase.ni.dll!00007fff9f6f94ff() Unknown >>> WindowsBase.ni.dll!00007fff9f8c496a() Unknown >>> clr.dll!UMThunkStub () Unknown >>> user32.dll!UserCallWinProcCheckWow() Unknown >>> user32.dll!DispatchMessageWorker() Unknown >>> WindowsBase.ni.dll!00007fff9f730ee8() Unknown >>> WindowsBase.ni.dll!00007fff9f70d8fc() Unknown >>> PresentationFramework.ni.dll!00007fff96af98b3() Unknown >>> PresentationFramework.ni.dll!00007fff96af969d() Unknown >>> clr.dll!CallDescrWorkerInternal () Unknown >>> clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown >>> clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class >>> Frame *) Unknown >>> clr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class >>> PtrArray *,class SignatureNative *,bool) Unknown >>> mscorlib.ni.dll!00007fffb86e1c20() Unknown >>> mscorlib.ni.dll!00007fffb8618272() Unknown >>> [External Code] >>> clr.dll!UMThunkStub () Unknown >>> [External Code] >>> > WPFPy.py!threadStart Line 256 Python >>> [External Code] >>> >>> >>> ------------------------------ >>> From: tony at pyxll.com >>> Date: Sun, 3 Apr 2016 15:20:47 +0000 >>> Subject: Re: [Python.NET] How to handle INotifyPropertyChanged interface >>> To: hhspiny at pine.cc; pythondotnet at python.org >>> >>> >>> What's the full stack trace? >>> >>> I suspect it's something to do with the event declared on the interface >>> not being implemented. The managed type constructed doesn't define any >>> events, so that would cause the construction of the type of fail - which is >>> probably the error you're getting (although without the stack trace it's >>> just an educated guess). >>> >>> It shouldn't be too hard to add events to the derived type if someone >>> wanted to have a go at implementing it. The code is in the >>> CreateDerivedType method in src/runtime/classderived.cs. To be consistent >>> with how methods and properties work, it would need a clrevent function >>> adding to the clr module (src/runtime/resource/clr.py) - maybe it could >>> work like this: >>> >>> class MyClass(INotifyPropertyChanged): >>> OnPropertyChanged = clr.clrevent(event_attributes, event_type) >>> >>> Then in classderived.cs the class any clrevents on the python class >>> could be added to the managed type using TypeBuilder.DefineEvent. >>> >>> So, anyway - short answer is that what you're trying to do won't work >>> without changes to pythonnet; but the changes required shouldn't be too >>> hard if you wanted to have a go. >>> >>> Best regards, >>> Tony >>> >>> >>> On Sun, Apr 3, 2016 at 3:37 PM Hansong Huang wrote: >>> >>> It seems inheriting from INotifyPropertyChanged is the cause >>> >>> self.window = System.Windows.Markup.XamlReader.Load(outStream) >>> self.window.DataContext = MyViewModel() >>> class 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") >>> >>> The above code works fine. >>> >>> but if switch inheritance to >>> class MyViewModel(System.ComponentModel.INotifyPropertyChanged): >>> and nothing else changed, python gives >>> >>> "The process terminates due to StackOverflowException" >>> >>> Not sure why. >>> >>> >>> Thanks for the help >>> >>> ------------------------------ >>> From: hhspiny at live.com >>> To: pythondotnet at python.org >>> Subject: How to handle INotifyPropertyChanged interface >>> Date: Thu, 31 Mar 2016 20:38:38 -0400 >>> >>> >>> 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 .Net >>> class 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. >>> _________________________________________________ >>> Python.NET mailing list - PythonDotNet at python.org >>> https://mail.python.org/mailman/listinfo/pythondotnet >>> >>> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> https://mail.python.org/mailman/listinfo/pythondotnet >> > > _________________________________________________ > 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 Mon Apr 4 21:47:30 2016 From: hhspiny at live.com (Hansong Huang) Date: Mon, 4 Apr 2016 21:47:30 -0400 Subject: [Python.NET] How to handle INotifyPropertyChanged interface In-Reply-To: References: , , Message-ID: New update: I found why the stackoverflow happened, and how to avoid it and make MVVM model work. however, it did not entirely solve the problem. The StackOverFlow was not directly because of the INotifyPropertyChanged interface, but because I used a class derived from it. if I define my ViewModel as class ViewModel(System.ComponentModel.INotifyPropertyChanged):and implement all components such as clr.clrproperty, PropertyChanged, add_PropertyChanged, remove_PropertyChanged etc as previous posted, and assign this class to window.DataContext, everything actually worked. The problem is that I used a derived classclass ViewModelBase(System.ComponentModel.INotifyPropertyChanged): where PropertyChanged, add_PropertyChanged, remove_PropertyChanged are implementedthenclass ViewModel(ViewModelBase): where clr.clrproperty is implemented. This results in the StackOverflow.... To make a simpler case, I tested out the following code that is entirely self-contained. import clr, Systemclass DotNetINotifyPropertyChanged(System.ComponentModel.INotifyPropertyChanged): __namespace__ = "DotNetINotifyPropertyChanged" def __init__(self): super(DotNetINotifyPropertyChanged, self).__init__() def add_PropertyChanged(self, value): pass def remove_PropertyChanged(self, value): passc1=DotNetINotifyPropertyChanged()c1.add_PropertyChanged("text")print "C1 success" class A(DotNetINotifyPropertyChanged): __namespace__ = "A" def __init__(self): super(A,self).__init__()a1 = A()a1.add_PropertyChanged("text")print "a1 success" if you run it, you can see that "C1 success" is printed, but python can not find a1.add_PropertyChanged method and throws exception. which I believe is the direct cause of StackOverflow above. Obviously, if DotNetINotifyPropertyChanged is derived from "object", the above code runs fine. Therefore the question is, what is it that inheriting from .NET interface that is unique, that the method defined in base class is not inherited by child class? Hansong From: tony at pyxll.com Date: Sun, 3 Apr 2016 15:40:17 +0000 Subject: Re: [Python.NET] How to handle INotifyPropertyChanged interface To: hhspiny at pine.cc; pythondotnet at python.org Yeah, it looks like the crash is probably because of the missing event implementation as suspected. I'm a bit surprised that it didn't fail earlier when trying to instantiate the type. If you do get a chance to take a look at adding that functionality be sure to submit a pull request! Best regards,Tony On Sun, Apr 3, 2016 at 4:30 PM Hansong Huang wrote: Tony, thanks for the hint. the event PropertyChanged was declared in INotifyPropertyChanged interface by pythonnet, but obviously not implemented. [('PropertyChanged', ), anyway, the stackoverflow only happens if both following are present1. the class is derived from INotifyPropertyChanged interface2. the class exposes property back to .Net vis @clrproperty which seems to prove that it is the PropertyChanged event that is not implemented in python class resulted in the crash. I was not sure if .Net event can be handled by pythonnet. I found a few examples with IronPython, but there, a python class of "event" seems to be implemented instead. Below is the stack trace [External Code] clr.dll!CallDescrWorkerInternal () Unknown clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class Frame *) Unknown clr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class PtrArray *,class SignatureNative *,bool) Unknown mscorlib.ni.dll!00007fffb86e1ca4() Unknown mscorlib.ni.dll!00007fffb8618272() Unknown mscorlib.ni.dll!00007fffb867fc4a() Unknown [External Code] mscorlib.ni.dll!00007fffb86dbaf5() Unknown mscorlib.ni.dll!00007fffb86d281f() Unknown System.ni.dll!00007fffb77556d4() Unknown System.ni.dll!00007fffb7755637() Unknown System.ni.dll!00007fffb775541d() Unknown PresentationFramework.ni.dll!00007fff96c1ca70() Unknown PresentationFramework.ni.dll!00007fff96c23902() Unknown PresentationFramework.ni.dll!00007fff96c22ea1() Unknown PresentationFramework.ni.dll!00007fff96c22693() Unknown PresentationFramework.ni.dll!00007fff96c223c9() Unknown PresentationFramework.ni.dll!00007fff96c21a03() Unknown PresentationFramework.ni.dll!00007fff96c0d84c() Unknown PresentationFramework.ni.dll!00007fff96b97299() Unknown PresentationFramework.ni.dll!00007fff96b9720e() Unknown PresentationFramework.ni.dll!00007fff96c852f0() Unknown WindowsBase.ni.dll!00007fff9f6f9bc9() Unknown WindowsBase.ni.dll!00007fff9f6f9ac6() Unknown WindowsBase.ni.dll!00007fff9f6fca2b() Unknown mscorlib.ni.dll!00007fffb86ca79e() Unknown mscorlib.ni.dll!00007fffb86ca637() Unknown mscorlib.ni.dll!00007fffb86ca5f2() Unknown WindowsBase.ni.dll!00007fff9f913810() Unknown WindowsBase.ni.dll!00007fff9f6fc784() Unknown WindowsBase.ni.dll!00007fff9f6f7c24() Unknown WindowsBase.ni.dll!00007fff9f6f8061() Unknown WindowsBase.ni.dll!00007fff9f6f9e53() Unknown WindowsBase.ni.dll!00007fff9f6f9d82() Unknown WindowsBase.ni.dll!00007fff9f6f9bc9() Unknown WindowsBase.ni.dll!00007fff9f6f9ac6() Unknown WindowsBase.ni.dll!00007fff9f6f7583() Unknown WindowsBase.ni.dll!00007fff9f6f94ff() Unknown WindowsBase.ni.dll!00007fff9f8c496a() Unknown clr.dll!UMThunkStub () Unknown user32.dll!UserCallWinProcCheckWow() Unknown user32.dll!DispatchMessageWorker() Unknown WindowsBase.ni.dll!00007fff9f730ee8() Unknown WindowsBase.ni.dll!00007fff9f70d8fc() Unknown PresentationFramework.ni.dll!00007fff96af98b3() Unknown PresentationFramework.ni.dll!00007fff96af969d() Unknown clr.dll!CallDescrWorkerInternal () Unknown clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class Frame *) Unknown clr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class PtrArray *,class SignatureNative *,bool) Unknown mscorlib.ni.dll!00007fffb86e1c20() Unknown mscorlib.ni.dll!00007fffb8618272() Unknown [External Code] clr.dll!UMThunkStub () Unknown [External Code] > WPFPy.py!threadStart Line 256 Python [External Code] From: tony at pyxll.com Date: Sun, 3 Apr 2016 15:20:47 +0000 Subject: Re: [Python.NET] How to handle INotifyPropertyChanged interface To: hhspiny at pine.cc; pythondotnet at python.org What's the full stack trace? I suspect it's something to do with the event declared on the interface not being implemented. The managed type constructed doesn't define any events, so that would cause the construction of the type of fail - which is probably the error you're getting (although without the stack trace it's just an educated guess). It shouldn't be too hard to add events to the derived type if someone wanted to have a go at implementing it. The code is in the CreateDerivedType method in src/runtime/classderived.cs. To be consistent with how methods and properties work, it would need a clrevent function adding to the clr module (src/runtime/resource/clr.py) - maybe it could work like this: class MyClass(INotifyPropertyChanged): OnPropertyChanged = clr.clrevent(event_attributes, event_type) Then in classderived.cs the class any clrevents on the python class could be added to the managed type using TypeBuilder.DefineEvent. So, anyway - short answer is that what you're trying to do won't work without changes to pythonnet; but the changes required shouldn't be too hard if you wanted to have a go. Best regards, Tony On Sun, Apr 3, 2016 at 3:37 PM Hansong Huang wrote: It seems inheriting from INotifyPropertyChanged is the cause self.window = System.Windows.Markup.XamlReader.Load(outStream)self.window.DataContext = MyViewModel()class 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") The above code works fine. but if switch inheritance to class MyViewModel(System.ComponentModel.INotifyPropertyChanged):and nothing else changed, python gives "The process terminates due to StackOverflowException" Not sure why. Thanks for the help From: hhspiny at live.com To: pythondotnet at python.org Subject: How to handle INotifyPropertyChanged interface Date: Thu, 31 Mar 2016 20:38:38 -0400 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. _________________________________________________ Python.NET mailing list - PythonDotNet at python.org https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From denis.akhiyarov at gmail.com Tue Apr 5 14:09:15 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Tue, 5 Apr 2016 13:09:15 -0500 Subject: [Python.NET] How to handle INotifyPropertyChanged interface In-Reply-To: References: Message-ID: I think this is related to another issue that I'm experiencing: https://github.com/pythonnet/pythonnet/issues/148 In your case I was very interested what is difference between 2 calls to add_PropertyChanged and uploaded a notebook showing the difference: https://gist.github.com/denfromufa/8ef691ca571b736278d751b1b256e814 Note that from console the results are hard crashes! I'm using the current development branch. ::## this is with interface python MVVM.py ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__format__', '__ func__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__re duce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', ' __str__', '__subclasshook__', 'im_class', 'im_func', 'im_self'] success: text ['__call__', '__class__', '__delattr__', '__delete__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__module__', '__new_ _', '__reduce__', '__reduce_ex__', '__repr__', '__set__', '__setattr__', '__size of__', '__str__', '__subclasshook__'] Traceback (most recent call last): File "MVVM.py", line 57, in a1.add_PropertyChanged("text") TypeError: No method matches given arguments Unhandled Exception: System.InvalidOperationException: Handle is not initialized . at System.Runtime.InteropServices.GCHandle.Free() at Python.Runtime.PythonDerivedType.Finalize(IPythonDerivedType obj) at A.A.Finalize() ::## this is with System.Object python MVVM.py ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__format__', '__ func__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__re duce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', ' __str__', '__subclasshook__', 'im_class', 'im_func', 'im_self'] success: text ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__format__', '__ func__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__re duce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', ' __str__', '__subclasshook__', 'im_class', 'im_func', 'im_self'] success: text Unhandled Exception: System.InvalidOperationException: Handle is not initialized . at System.Runtime.InteropServices.GCHandle.Free() at Python.Runtime.PythonDerivedType.Finalize(IPythonDerivedType obj) at A.A.Finalize() On Mon, Apr 4, 2016 at 8:47 PM, Hansong Huang wrote: > New update: > > I found why the stackoverflow happened, and how to avoid it and make MVVM > model work. however, it did not entirely solve the problem. > > The StackOverFlow was not directly because of the INotifyPropertyChanged > interface, but because I used a class derived from it. > > if I define my ViewModel as > > class ViewModel(System.ComponentModel.INotifyPropertyChanged): > and implement all components such as clr.clrproperty, PropertyChanged, > add_PropertyChanged, remove_PropertyChanged etc as previous posted, and > assign this class to window.DataContext, everything actually worked. > > The problem is that I used a derived class > class ViewModelBase(System.ComponentModel.INotifyPropertyChanged): where PropertyChanged, > add_PropertyChanged, remove_PropertyChanged are implemented > then > class ViewModel(ViewModelBase): where clr.clrproperty is implemented. > This results in the StackOverflow.... > > To make a simpler case, I tested out the following code that is entirely > self-contained. > > import clr, System > class > DotNetINotifyPropertyChanged(System.ComponentModel.INotifyPropertyChanged): > __namespace__ = "DotNetINotifyPropertyChanged" > def __init__(self): > super(DotNetINotifyPropertyChanged, self).__init__() > def add_PropertyChanged(self, value): > pass > def remove_PropertyChanged(self, value): > pass > c1=DotNetINotifyPropertyChanged() > c1.add_PropertyChanged("text") > print "C1 success" > > class A(DotNetINotifyPropertyChanged): > __namespace__ = "A" > def __init__(self): > super(A,self).__init__() > a1 = A() > a1.add_PropertyChanged("text") > print "a1 success" > > if you run it, you can see that "C1 success" is printed, but python can > not find a1.add_PropertyChanged method and throws exception. which I > believe is the direct cause of StackOverflow above. > > Obviously, if DotNetINotifyPropertyChanged is derived from "object", the > above code runs fine. > > Therefore the question is, what is it that inheriting from .NET interface > that is unique, that the method defined in base class is not inherited by > child class? > > Hansong > > > > ------------------------------ > From: tony at pyxll.com > Date: Sun, 3 Apr 2016 15:40:17 +0000 > Subject: Re: [Python.NET] How to handle INotifyPropertyChanged interface > To: hhspiny at pine.cc; pythondotnet at python.org > > Yeah, it looks like the crash is probably because of the missing event > implementation as suspected. I'm a bit surprised that it didn't fail > earlier when trying to instantiate the type. > > If you do get a chance to take a look at adding that functionality be sure > to submit a pull request! > > Best regards, > Tony > > > On Sun, Apr 3, 2016 at 4:30 PM Hansong Huang wrote: > > Tony, > > thanks for the hint. > > the event PropertyChanged was declared in INotifyPropertyChanged interface > by pythonnet, but obviously not implemented. > [('PropertyChanged', ), > > anyway, the stackoverflow only happens if both following are present > 1. the class is derived from INotifyPropertyChanged interface > 2. the class exposes property back to .Net vis @clrproperty > > which seems to prove that it is the PropertyChanged event that is not > implemented in python class resulted in the crash. > > I was not sure if .Net event can be handled by pythonnet. I found a few > examples with IronPython, but there, a python class of "event" seems to be > implemented instead. > > Below is the stack trace > > > [External Code] > clr.dll!CallDescrWorkerInternal () Unknown > clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown > clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class > Frame *) Unknown > clr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class PtrArray > *,class SignatureNative *,bool) Unknown > mscorlib.ni.dll!00007fffb86e1ca4() Unknown > mscorlib.ni.dll!00007fffb8618272() Unknown > mscorlib.ni.dll!00007fffb867fc4a() Unknown > [External Code] > mscorlib.ni.dll!00007fffb86dbaf5() Unknown > mscorlib.ni.dll!00007fffb86d281f() Unknown > System.ni.dll!00007fffb77556d4() Unknown > System.ni.dll!00007fffb7755637() Unknown > System.ni.dll!00007fffb775541d() Unknown > PresentationFramework.ni.dll!00007fff96c1ca70() Unknown > PresentationFramework.ni.dll!00007fff96c23902() Unknown > PresentationFramework.ni.dll!00007fff96c22ea1() Unknown > PresentationFramework.ni.dll!00007fff96c22693() Unknown > PresentationFramework.ni.dll!00007fff96c223c9() Unknown > PresentationFramework.ni.dll!00007fff96c21a03() Unknown > PresentationFramework.ni.dll!00007fff96c0d84c() Unknown > PresentationFramework.ni.dll!00007fff96b97299() Unknown > PresentationFramework.ni.dll!00007fff96b9720e() Unknown > PresentationFramework.ni.dll!00007fff96c852f0() Unknown > WindowsBase.ni.dll!00007fff9f6f9bc9() Unknown > WindowsBase.ni.dll!00007fff9f6f9ac6() Unknown > WindowsBase.ni.dll!00007fff9f6fca2b() Unknown > mscorlib.ni.dll!00007fffb86ca79e() Unknown > mscorlib.ni.dll!00007fffb86ca637() Unknown > mscorlib.ni.dll!00007fffb86ca5f2() Unknown > WindowsBase.ni.dll!00007fff9f913810() Unknown > WindowsBase.ni.dll!00007fff9f6fc784() Unknown > WindowsBase.ni.dll!00007fff9f6f7c24() Unknown > WindowsBase.ni.dll!00007fff9f6f8061() Unknown > WindowsBase.ni.dll!00007fff9f6f9e53() Unknown > WindowsBase.ni.dll!00007fff9f6f9d82() Unknown > WindowsBase.ni.dll!00007fff9f6f9bc9() Unknown > WindowsBase.ni.dll!00007fff9f6f9ac6() Unknown > WindowsBase.ni.dll!00007fff9f6f7583() Unknown > WindowsBase.ni.dll!00007fff9f6f94ff() Unknown > WindowsBase.ni.dll!00007fff9f8c496a() Unknown > clr.dll!UMThunkStub () Unknown > user32.dll!UserCallWinProcCheckWow() Unknown > user32.dll!DispatchMessageWorker() Unknown > WindowsBase.ni.dll!00007fff9f730ee8() Unknown > WindowsBase.ni.dll!00007fff9f70d8fc() Unknown > PresentationFramework.ni.dll!00007fff96af98b3() Unknown > PresentationFramework.ni.dll!00007fff96af969d() Unknown > clr.dll!CallDescrWorkerInternal () Unknown > clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown > clr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class > Frame *) Unknown > clr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class PtrArray > *,class SignatureNative *,bool) Unknown > mscorlib.ni.dll!00007fffb86e1c20() Unknown > mscorlib.ni.dll!00007fffb8618272() Unknown > [External Code] > clr.dll!UMThunkStub () Unknown > [External Code] > > WPFPy.py!threadStart Line 256 Python > [External Code] > > > ------------------------------ > From: tony at pyxll.com > Date: Sun, 3 Apr 2016 15:20:47 +0000 > Subject: Re: [Python.NET] How to handle INotifyPropertyChanged interface > To: hhspiny at pine.cc; pythondotnet at python.org > > > What's the full stack trace? > > I suspect it's something to do with the event declared on the interface > not being implemented. The managed type constructed doesn't define any > events, so that would cause the construction of the type of fail - which is > probably the error you're getting (although without the stack trace it's > just an educated guess). > > It shouldn't be too hard to add events to the derived type if someone > wanted to have a go at implementing it. The code is in the > CreateDerivedType method in src/runtime/classderived.cs. To be consistent > with how methods and properties work, it would need a clrevent function > adding to the clr module (src/runtime/resource/clr.py) - maybe it could > work like this: > > class MyClass(INotifyPropertyChanged): > OnPropertyChanged = clr.clrevent(event_attributes, event_type) > > Then in classderived.cs the class any clrevents on the python class could > be added to the managed type using TypeBuilder.DefineEvent. > > So, anyway - short answer is that what you're trying to do won't work > without changes to pythonnet; but the changes required shouldn't be too > hard if you wanted to have a go. > > Best regards, > Tony > > > On Sun, Apr 3, 2016 at 3:37 PM Hansong Huang wrote: > > It seems inheriting from INotifyPropertyChanged is the cause > > self.window = System.Windows.Markup.XamlReader.Load(outStream) > self.window.DataContext = MyViewModel() > class 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") > > The above code works fine. > > but if switch inheritance to > class MyViewModel(System.ComponentModel.INotifyPropertyChanged): > and nothing else changed, python gives > > "The process terminates due to StackOverflowException" > > Not sure why. > > > Thanks for the help > > ------------------------------ > From: hhspiny at live.com > To: pythondotnet at python.org > Subject: How to handle INotifyPropertyChanged interface > Date: Thu, 31 Mar 2016 20:38:38 -0400 > > > 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 .Net > class 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. > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet > > > _________________________________________________ > 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 Sun Apr 10 22:30:08 2016 From: hhspiny at live.com (Hansong Huang) Date: Sun, 10 Apr 2016 22:30:08 -0400 Subject: [Python.NET] "Incorrect" behavior of inheriting from class which is inherited from .Net class Message-ID: Hello, This is related to previous investigation of inheriting from .NET interface class to create WPF MVVM structure. As now I believe it has nothing to do with interface class, but instead caused by inheriting from .Net class overall. please see the following code import clr, Systemclass baseNA(System.Random): __namespace__ = "BaseNA" def __init__(self): super(baseNA,self).__init__()# @clr.clrmethod(System.String,[]) def ToString(self): return "string" class baseNB(baseNA): __namespace__ = "BaseNB" def __init__(self): super(baseNB,self).__init__()bna = baseNA()print bna.ToString()print bna._Random__ToString()bnb = baseNB()print bnb.ToString()print bnb._baseNA__ToString()print bnb._Random__ToString() This produces the following outputstringBaseNA.baseNABaseNB.baseNBBaseNB.baseNBBaseNB.baseNB as you see, while baseNA -- the first level inherited class works fine. ToString() overrides System.Random.ToString() But baseNB inherited from baseNA did not inherit ToString() method from baseNA, but rather inherited from System.Random. Not sure if it is a bug in python.net or was intended. regards, Hansong -------------- next part -------------- An HTML attachment was scrubbed... URL: From tony at pyxll.com Mon Apr 11 03:04:17 2016 From: tony at pyxll.com (Tony Roberts) Date: Mon, 11 Apr 2016 07:04:17 +0000 Subject: [Python.NET] "Incorrect" behavior of inheriting from class which is inherited from .Net class In-Reply-To: References: Message-ID: Hi, yes, deriving from a python class in Python that itself is derived from a .net class doesn't work. Apologies, if I'd known that was what you were doing I could have saved you some time by telling you that earlier. AFAIK this hasn't been created as an issue in github, so please if you could do that that would be helpful. It's probably not that hard to make work, but it's not something I've got time to look at myself right now I'm afraid. If anyone else wants to have a go and needs pointing in the right direction let me know. Tony On Mon, Apr 11, 2016 at 3:41 AM Hansong Huang wrote: > Hello, > > This is related to previous investigation of inheriting from .NET > interface class to create WPF MVVM structure. As now I believe it has > nothing to do with interface class, but instead caused by inheriting from > .Net class overall. > > please see the following code > > import clr, System > class baseNA(System.Random): > __namespace__ = "BaseNA" > def __init__(self): > super(baseNA,self).__init__() > # @clr.clrmethod(System.String,[]) > def ToString(self): > return "string" > > class baseNB(baseNA): > __namespace__ = "BaseNB" > def __init__(self): > super(baseNB,self).__init__() > bna = baseNA() > print bna.ToString() > print bna._Random__ToString() > bnb = baseNB() > print bnb.ToString() > print bnb._baseNA__ToString() > print bnb._Random__ToString() > > > This produces the following output > string > BaseNA.baseNA > BaseNB.baseNB > BaseNB.baseNB > BaseNB.baseNB > > as you see, while baseNA -- the first level inherited class works fine. > ToString() overrides System.Random.ToString() > > But baseNB inherited from baseNA did not inherit ToString() method from > baseNA, but rather inherited from System.Random. > > Not sure if it is a bug in python.net or was intended. > > regards, > > Hansong > > > > > _________________________________________________ > 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 Tue Apr 12 07:50:23 2016 From: tony at pyxll.com (Tony Roberts) Date: Tue, 12 Apr 2016 12:50:23 +0100 Subject: [Python.NET] Python.NET 2.1 released Message-ID: Hi, Python.NET 2.1 has now been released and can be installed using pip: pip install --upgrade pythonnet Or alternatively dowloaded manually from PyPI ( https://pypi.python.org/pypi/pythonnet/2.1.0) The headline new feature of this release support for Python 3. It also contains many other smaller enhancements and bug fixes. If you are still using an older version from sourceforge or the 2.1.0.dev1 pre-release I would highly recommend upgrading to this release. Many thanks to all the contributors for their efforts to make this release happen. It was a long time coming and wouldn't have happened without a lot of work from them. Development continues on github here https://github.com/pythonnet/pythonnet and I would encourage anyone who would like to get involved. One important thing this project is currently lacking is documentation, so if anyone would like to help there that would be particularly appreciated. Contributors/github users: please note I have merged the develop branch back into master and pull requests will now be accepted against the master branch. Best regards, Tony Roberts www.pyxll.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From cameron.hayne at introspect.ca Tue Apr 19 15:09:02 2016 From: cameron.hayne at introspect.ca (Cameron Hayne) Date: Tue, 19 Apr 2016 15:09:02 -0400 Subject: [Python.NET] calling Python via Python.Runtime DLL from IronPython Message-ID: <49F98A3E-A756-43B1-B678-4A9D6261A11E@introspect.ca> Should it be possible to call Python (CPython) code from IronPython (an IronPython script) via the Python.Runtime DLL ? I.e. an IronPython script that imports the Python.Runtime DLL and then calls the functions provided by that DLL. In my preliminary tests, I get an error about ?copy_reg? not being found. This error seems to happen when calling PythonEngine.Initialize(). -- Cameron Hayne cameron.hayne at introspect.ca From denis.akhiyarov at gmail.com Tue Apr 19 16:28:03 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Tue, 19 Apr 2016 15:28:03 -0500 Subject: [Python.NET] calling Python via Python.Runtime DLL from IronPython In-Reply-To: <49F98A3E-A756-43B1-B678-4A9D6261A11E@introspect.ca> References: <49F98A3E-A756-43B1-B678-4A9D6261A11E@introspect.ca> Message-ID: Did you try this code? http://www.voidspace.org.uk/ironpython/cpython_extensions.shtml On Tue, Apr 19, 2016 at 2:09 PM, Cameron Hayne wrote: > Should it be possible to call Python (CPython) code from IronPython (an > IronPython script) via the Python.Runtime DLL ? > I.e. an IronPython script that imports the Python.Runtime DLL and then > calls the functions provided by that DLL. > In my preliminary tests, I get an error about ?copy_reg? not being found. > This error seems to happen when calling PythonEngine.Initialize(). > > -- > Cameron Hayne > cameron.hayne at introspect.ca > > > > _________________________________________________ > 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 Tue Apr 19 16:37:47 2016 From: tony at pyxll.com (Tony Roberts) Date: Tue, 19 Apr 2016 20:37:47 +0000 Subject: [Python.NET] calling Python via Python.Runtime DLL from IronPython In-Reply-To: References: <49F98A3E-A756-43B1-B678-4A9D6261A11E@introspect.ca> Message-ID: No need to import the c Python extension - from IronPython you would be able to reference the Python.runtime assembly without it. The problem you're having sounds like the python path isn't correct for cPython. You could try setting the PYTHONHOME environment variable and see if that gets you any further. Best regards, Tony On Tue, Apr 19, 2016 at 9:30 PM Denis Akhiyarov wrote: > Did you try this code? > > http://www.voidspace.org.uk/ironpython/cpython_extensions.shtml > > On Tue, Apr 19, 2016 at 2:09 PM, Cameron Hayne < > cameron.hayne at introspect.ca> wrote: > >> Should it be possible to call Python (CPython) code from IronPython (an >> IronPython script) via the Python.Runtime DLL ? >> I.e. an IronPython script that imports the Python.Runtime DLL and then >> calls the functions provided by that DLL. >> In my preliminary tests, I get an error about ?copy_reg? not being found. >> This error seems to happen when calling PythonEngine.Initialize(). >> >> -- >> Cameron Hayne >> cameron.hayne at introspect.ca >> >> >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> https://mail.python.org/mailman/listinfo/pythondotnet >> > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From cameron.hayne at introspect.ca Thu Apr 21 14:01:32 2016 From: cameron.hayne at introspect.ca (Cameron Hayne) Date: Thu, 21 Apr 2016 14:01:32 -0400 Subject: [Python.NET] calling Python via Python.Runtime DLL from IronPython In-Reply-To: References: <49F98A3E-A756-43B1-B678-4A9D6261A11E@introspect.ca> Message-ID: <1F41CBA3-ADBA-4B2F-A175-5874DA302E28@introspect.ca> I tried calling Py_SetPythonHome("C:\\Python27") before calling PythonEngine.Initialize(), but I got the same problem (re ?copy_reg? not found). Any other suggestions? -- Cameron Hayne cameron.hayne at introspect.ca On Apr 19, 2016, at 4:37 PM, Tony Roberts wrote: > No need to import the c Python extension - from IronPython you would be able to reference the Python.runtime assembly without it. The problem you're having sounds like the python path isn't correct for cPython. You could try setting the PYTHONHOME environment variable and see if that gets you any further. > > Best regards, > Tony > On Tue, Apr 19, 2016 at 9:30 PM Denis Akhiyarov wrote: > Did you try this code? > > http://www.voidspace.org.uk/ironpython/cpython_extensions.shtml > > On Tue, Apr 19, 2016 at 2:09 PM, Cameron Hayne wrote: > Should it be possible to call Python (CPython) code from IronPython (an IronPython script) via the Python.Runtime DLL ? > I.e. an IronPython script that imports the Python.Runtime DLL and then calls the functions provided by that DLL. > In my preliminary tests, I get an error about ?copy_reg? not being found. This error seems to happen when calling PythonEngine.Initialize(). From denis.akhiyarov at gmail.com Thu Apr 21 23:27:58 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Thu, 21 Apr 2016 22:27:58 -0500 Subject: [Python.NET] calling Python via Python.Runtime DLL from IronPython In-Reply-To: <1F41CBA3-ADBA-4B2F-A175-5874DA302E28@introspect.ca> References: <49F98A3E-A756-43B1-B678-4A9D6261A11E@introspect.ca> <1F41CBA3-ADBA-4B2F-A175-5874DA302E28@introspect.ca> Message-ID: Are you able to run PythonEngine.Initialize() from c#, not ironpython? On Thursday, April 21, 2016, Cameron Hayne wrote: > I tried calling Py_SetPythonHome("C:\\Python27") before calling > PythonEngine.Initialize(), but I got the same problem (re ?copy_reg? not > found). > Any other suggestions? > -- > Cameron Hayne > cameron.hayne at introspect.ca > > > On Apr 19, 2016, at 4:37 PM, Tony Roberts > > wrote: > > > No need to import the c Python extension - from IronPython you would be > able to reference the Python.runtime assembly without it. The problem > you're having sounds like the python path isn't correct for cPython. You > could try setting the PYTHONHOME environment variable and see if that gets > you any further. > > > > Best regards, > > Tony > > On Tue, Apr 19, 2016 at 9:30 PM Denis Akhiyarov < > denis.akhiyarov at gmail.com > wrote: > > Did you try this code? > > > > http://www.voidspace.org.uk/ironpython/cpython_extensions.shtml > > > > On Tue, Apr 19, 2016 at 2:09 PM, Cameron Hayne < > cameron.hayne at introspect.ca > wrote: > > Should it be possible to call Python (CPython) code from IronPython (an > IronPython script) via the Python.Runtime DLL ? > > I.e. an IronPython script that imports the Python.Runtime DLL and then > calls the functions provided by that DLL. > > In my preliminary tests, I get an error about ?copy_reg? not being > found. This error seems to happen when calling PythonEngine.Initialize(). > > > > > > _________________________________________________ > 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 Fri Apr 22 10:41:10 2016 From: tony at pyxll.com (Tony Roberts) Date: Fri, 22 Apr 2016 14:41:10 +0000 Subject: [Python.NET] calling Python via Python.Runtime DLL from IronPython In-Reply-To: References: <49F98A3E-A756-43B1-B678-4A9D6261A11E@introspect.ca> <1F41CBA3-ADBA-4B2F-A175-5874DA302E28@introspect.ca> Message-ID: This problem could be caused by two different incompatible CPython interpreters being installed. Possibly it's a .pyc file generated from another version of Python is being imported (and failing to import). Can you check what python27.dll is being used? You should be able to see it in visual studio in the modules window, or with a tool like sysinternals process explorer. If that dll is one left over from an old install of Python try either removing it, or setting your PATH so the correct one is picked up. One other thing you might want to try is a fresh install of Python (making sure that no old python27.dll files are being used) as your pyc caches might be in a weird state if the problem is caused by conflicting Python installs. A quick check to see if it is something like that would be to delete copy_reg.pyc and see if it gets any further. Best regards, Tony On Fri, Apr 22, 2016 at 3:19 PM Denis Akhiyarov wrote: > Are you able to run PythonEngine.Initialize() from c#, not ironpython? > > > On Thursday, April 21, 2016, Cameron Hayne > wrote: > >> I tried calling Py_SetPythonHome("C:\\Python27") before calling >> PythonEngine.Initialize(), but I got the same problem (re ?copy_reg? not >> found). >> Any other suggestions? >> -- >> Cameron Hayne >> cameron.hayne at introspect.ca >> >> >> On Apr 19, 2016, at 4:37 PM, Tony Roberts wrote: >> >> > No need to import the c Python extension - from IronPython you would be >> able to reference the Python.runtime assembly without it. The problem >> you're having sounds like the python path isn't correct for cPython. You >> could try setting the PYTHONHOME environment variable and see if that gets >> you any further. >> > >> > Best regards, >> > Tony >> > On Tue, Apr 19, 2016 at 9:30 PM Denis Akhiyarov < >> denis.akhiyarov at gmail.com> wrote: >> > Did you try this code? >> > >> > http://www.voidspace.org.uk/ironpython/cpython_extensions.shtml >> > >> > On Tue, Apr 19, 2016 at 2:09 PM, Cameron Hayne < >> cameron.hayne at introspect.ca> wrote: >> > Should it be possible to call Python (CPython) code from IronPython (an >> IronPython script) via the Python.Runtime DLL ? >> > I.e. an IronPython script that imports the Python.Runtime DLL and then >> calls the functions provided by that DLL. >> > In my preliminary tests, I get an error about ?copy_reg? not being >> found. This error seems to happen when calling PythonEngine.Initialize(). >> >> >> >> >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> https://mail.python.org/mailman/listinfo/pythondotnet >> > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From denis.akhiyarov at gmail.com Thu Apr 28 10:43:40 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Thu, 28 Apr 2016 09:43:40 -0500 Subject: [Python.NET] calling Python via Python.Runtime DLL from IronPython In-Reply-To: References: <49F98A3E-A756-43B1-B678-4A9D6261A11E@introspect.ca> <1F41CBA3-ADBA-4B2F-A175-5874DA302E28@introspect.ca> Message-ID: Actually I tried embedding cpython with pythonnet 2.1 in ironpython 2.7.5 and hit the same issue! The weird thing is that copy_reg is actually importable in regular ironpython code. According to FePy project, which developed this embedding technology, this used to work with ironpython 2, which was released around 2008-2009. Since then both Ironpython and pythonnet (Python.Runtime.DLL) seem to have gone through significant changes. Maybe someone can test with the old combination of both ironpython and pythonnet running on .NET 2.0. http://ironpython.codeplex.com/releases/view/8365 https://sourceforge.net/projects/pythonnet/files/pythonnet/pythonnet-1.0-rc2-py2.3-clr1.1/pythonnet-1.0-rc2-py2.3-clr1.1.exe On Fri, Apr 22, 2016 at 9:41 AM, Tony Roberts wrote: > This problem could be caused by two different incompatible CPython > interpreters being installed. Possibly it's a .pyc file generated from > another version of Python is being imported (and failing to import). > > Can you check what python27.dll is being used? You should be able to see > it in visual studio in the modules window, or with a tool like sysinternals > process explorer. If that dll is one left over from an old install of > Python try either removing it, or setting your PATH so the correct one is > picked up. > > One other thing you might want to try is a fresh install of Python (making > sure that no old python27.dll files are being used) as your pyc caches > might be in a weird state if the problem is caused by conflicting Python > installs. > > A quick check to see if it is something like that would be to delete > copy_reg.pyc and see if it gets any further. > > Best regards, > Tony > > On Fri, Apr 22, 2016 at 3:19 PM Denis Akhiyarov > wrote: > >> Are you able to run PythonEngine.Initialize() from c#, not ironpython? >> >> >> On Thursday, April 21, 2016, Cameron Hayne >> wrote: >> >>> I tried calling Py_SetPythonHome("C:\\Python27") before calling >>> PythonEngine.Initialize(), but I got the same problem (re ?copy_reg? not >>> found). >>> Any other suggestions? >>> -- >>> Cameron Hayne >>> cameron.hayne at introspect.ca >>> >>> >>> On Apr 19, 2016, at 4:37 PM, Tony Roberts wrote: >>> >>> > No need to import the c Python extension - from IronPython you would >>> be able to reference the Python.runtime assembly without it. The problem >>> you're having sounds like the python path isn't correct for cPython. You >>> could try setting the PYTHONHOME environment variable and see if that gets >>> you any further. >>> > >>> > Best regards, >>> > Tony >>> > On Tue, Apr 19, 2016 at 9:30 PM Denis Akhiyarov < >>> denis.akhiyarov at gmail.com> wrote: >>> > Did you try this code? >>> > >>> > http://www.voidspace.org.uk/ironpython/cpython_extensions.shtml >>> > >>> > On Tue, Apr 19, 2016 at 2:09 PM, Cameron Hayne < >>> cameron.hayne at introspect.ca> wrote: >>> > Should it be possible to call Python (CPython) code from IronPython >>> (an IronPython script) via the Python.Runtime DLL ? >>> > I.e. an IronPython script that imports the Python.Runtime DLL and then >>> calls the functions provided by that DLL. >>> > In my preliminary tests, I get an error about ?copy_reg? not being >>> found. This error seems to happen when calling PythonEngine.Initialize(). >>> >>> >>> >>> >>> >>> _________________________________________________ >>> Python.NET mailing list - PythonDotNet at python.org >>> https://mail.python.org/mailman/listinfo/pythondotnet >>> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> https://mail.python.org/mailman/listinfo/pythondotnet > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: