Tony,thanks for the hint.the event PropertyChanged was declared in INotifyPropertyChanged interface by pythonnet, but obviously not implemented.[('PropertyChanged', <unbound event '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 @clrpropertywhich 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 () Unknownclr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknownclr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class Frame *) Unknownclr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class PtrArray *,class SignatureNative *,bool) Unknownmscorlib.ni.dll!00007fffb86e1ca4() Unknownmscorlib.ni.dll!00007fffb8618272() Unknownmscorlib.ni.dll!00007fffb867fc4a() Unknown[External Code]mscorlib.ni.dll!00007fffb86dbaf5() Unknownmscorlib.ni.dll!00007fffb86d281f() UnknownSystem.ni.dll!00007fffb77556d4() UnknownSystem.ni.dll!00007fffb7755637() UnknownSystem.ni.dll!00007fffb775541d() UnknownPresentationFramework.ni.dll!00007fff96c1ca70() UnknownPresentationFramework.ni.dll!00007fff96c23902() UnknownPresentationFramework.ni.dll!00007fff96c22ea1() UnknownPresentationFramework.ni.dll!00007fff96c22693() UnknownPresentationFramework.ni.dll!00007fff96c223c9() UnknownPresentationFramework.ni.dll!00007fff96c21a03() UnknownPresentationFramework.ni.dll!00007fff96c0d84c() UnknownPresentationFramework.ni.dll!00007fff96b97299() UnknownPresentationFramework.ni.dll!00007fff96b9720e() UnknownPresentationFramework.ni.dll!00007fff96c852f0() UnknownWindowsBase.ni.dll!00007fff9f6f9bc9() UnknownWindowsBase.ni.dll!00007fff9f6f9ac6() UnknownWindowsBase.ni.dll!00007fff9f6fca2b() Unknownmscorlib.ni.dll!00007fffb86ca79e() Unknownmscorlib.ni.dll!00007fffb86ca637() Unknownmscorlib.ni.dll!00007fffb86ca5f2() UnknownWindowsBase.ni.dll!00007fff9f913810() UnknownWindowsBase.ni.dll!00007fff9f6fc784() UnknownWindowsBase.ni.dll!00007fff9f6f7c24() UnknownWindowsBase.ni.dll!00007fff9f6f8061() UnknownWindowsBase.ni.dll!00007fff9f6f9e53() UnknownWindowsBase.ni.dll!00007fff9f6f9d82() UnknownWindowsBase.ni.dll!00007fff9f6f9bc9() UnknownWindowsBase.ni.dll!00007fff9f6f9ac6() UnknownWindowsBase.ni.dll!00007fff9f6f7583() UnknownWindowsBase.ni.dll!00007fff9f6f94ff() UnknownWindowsBase.ni.dll!00007fff9f8c496a() Unknownclr.dll!UMThunkStub () Unknownuser32.dll!UserCallWinProcCheckWow() Unknownuser32.dll!DispatchMessageWorker() UnknownWindowsBase.ni.dll!00007fff9f730ee8() UnknownWindowsBase.ni.dll!00007fff9f70d8fc() UnknownPresentationFramework.ni.dll!00007fff96af98b3() UnknownPresentationFramework.ni.dll!00007fff96af969d() Unknownclr.dll!CallDescrWorkerInternal () Unknownclr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknownclr.dll!CallDescrWorkerReflectionWrapper(struct CallDescrData *,class Frame *) Unknownclr.dll!RuntimeMethodHandle::InvokeMethod(class Object *,class PtrArray *,class SignatureNative *,bool) Unknownmscorlib.ni.dll!00007fffb86e1c20() Unknownmscorlib.ni.dll!00007fffb8618272() Unknown[External Code]clr.dll!UMThunkStub () Unknown[External Code]> WPFPy.py!threadStart Line 256 Python[External Code]
From: tony@pyxll.com
Date: Sun, 3 Apr 2016 15:20:47 +0000
Subject: Re: [Python.NET] How to handle INotifyPropertyChanged interface
To: hhspiny@pine.cc; pythondotnet@python.orgWhat'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,TonyOn Sun, Apr 3, 2016 at 3:37 PM Hansong Huang <hhspiny@live.com> wrote:It seems inheriting from INotifyPropertyChanged is the causeself.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.setterdef inputText(self,value):self._inputText = valueself.OnPropertyChanged("inputText")The above code works fine.but if switch inheritance toclass 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@live.com
To: pythondotnet@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 containerself.window = System.Windows.Markup.XamlReader.Load(outStream)self.window.DataContext = DotNetExpandoObject()where DotNetExpandoObject is a wrapper class for System.Dynamic.ExpandoObjectclass DotNetExpandoObject(System.Dynamic.ExpandoObject):... in which I redefined __getattr__ and __setattr__it works flawlessly as System.Dynamic.ExpandoObject implements INotifyPropertyChange interface alreadyNow, I would like to get away from using System.Dynamic.ExpandoObject but to implement my ownI 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.setterdef inputText(self,value):self._inputText = valueself.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 wrongclass ViewModel(System.ComponentModel.INotifyPropertyChanged):__namespace__ = "WPFPy"def __init__(self):super(ViewModel, self).__init__()self.PropertyChanged = System.ComponentModel.PropertyChangedEventHandlerdef 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.setterdef inputText(self,value):self._inputText = valueself.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@python.org
https://mail.python.org/mailman/listinfo/pythondotnet