<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-2" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
__setattr__ is not clean and easy readable piece of code. That's why I
dive into decorators and create a <b>notify_property</b>:<br>
<pre>class notify_property(property):

    def __init__(self, getter):
        def newgetter(slf):
            #return None when the property does not exist yet
            try:
                return getter(slf)
            except AttributeError:
                return None
        super(notify_property, self).__init__(newgetter)

    def setter(self, setter):
        def newsetter(slf, newvalue):
            # do not change value if the new value is the same
            # trigger PropertyChanged event when value changes
            oldvalue = self.fget(slf)
            if oldvalue != newvalue:
                setter(slf, newvalue)
                slf.OnPropertyChanged(setter.__name__)
        return property(
            fget=self.fget,
            fset=newsetter,
            fdel=self.fdel,
            doc=self.__doc__)

</pre>
The usage is the same as for @property - see details on my blog:<br>
<a
 href="http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html">http://gui-at.blogspot.com/2009/11/inotifypropertychanged-in-ironpython.html</a><br>
<br>
Unfortunately, this does not work in Silverlight - probably because
such properties are not CLR fields. I'd like to find a way to make it
work in Silverlight too.<br>
<br>
--<br>
-- Lukáš<br>
<br>
<br>
Curt Hagenlocher wrote:
<blockquote
 cite="mid:d2155e360911061414x2b7afa83q2fda5d816a137bb6@mail.gmail.com"
 type="cite">
  <div>Why don't you think that __setattr__ is a good approach? The
alternative (as shown in the linked Japanese-language blog) is to
implement setters for the properties you care about and to manually
trigger the event.<br>
  </div>
  <div class="gmail_quote">2009/11/6 Lukas Cenovsky <span dir="ltr">&lt;<a
 moz-do-not-send="true" href="mailto:cenovsky@bakalari.cz">cenovsky@bakalari.cz</a>&gt;</span><br>
  <blockquote
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;"
 class="gmail_quote">Hi all,<br>
I was looking for WPF data binding in IronPython and I have found nice
Japanese blog about it:<br>
    <a moz-do-not-send="true"
 href="http://palepoli.skr.jp/wp/2009/06/28/wpf-listview-databinding-for-ironpython/"
 target="_blank">http://palepoli.skr.jp/wp/2009/06/28/wpf-listview-databinding-for-ironpython/</a><br>
    <br>
It links to <a moz-do-not-send="true"
 href="http://sdlsdk.codeplex.com/Thread/View.aspx?ThreadId=30322"
 target="_blank">http://sdlsdk.codeplex.com/Thread/View.aspx?ThreadId=30322</a>
that should have more information about how to implement
INotifyPropertyChanged in IronPython which I am also interested in.
Unfortunately this page is no more available. Does the guideline exist
somewhere else? Thanks.<br>
    <br>
PS: I know about <a moz-do-not-send="true"
 href="http://lists.ironpython.com/pipermail/users-ironpython.com/2009-August/010938.html"
 target="_blank">http://lists.ironpython.com/pipermail/users-ironpython.com/2009-August/010938.html</a>
but I don't think using __setattr__ is good approach. Also implementing
the PropertyChanged event is different on the blog.<br>
    <font color="#888888"><br>
--<br>
-- Lukáš<br>
_______________________________________________<br>
Users mailing list<br>
    <a moz-do-not-send="true" href="mailto:Users@lists.ironpython.com"
 target="_blank">Users@lists.ironpython.com</a><br>
    <a moz-do-not-send="true"
 href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com"
 target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
    </font></blockquote>
  </div>
  <br>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a>
<a class="moz-txt-link-freetext" href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a>
  </pre>
</blockquote>
<br>
</body>
</html>