Fire event when variable is Set/Get

Mike C. Fletcher mcfletch at rogers.com
Mon Jul 25 00:22:46 EDT 2005


Varghjärta wrote:
...

>But there is something that keeps bugging me, and that keeps me from
>embracing Python even more as a serious alternative to C#(for me). In
>C# I make heavy use of Get & Set, mainly to fire an event that some
>property has changed so that one can act on that _if one would need
>to. I've grown very used to doing it and it feels like the best way to
>make very OO and reusuable and easy to use Classes.
>  
>
It's fairly straightforward to implement observability for any of the 
various "modeling" descriptor systems out there.  Attached you'll find a 
quick demo of how one could use BasicProperty with PyDispatcher to 
produce the effect.  The biggest problem is that normally the particular 
events you want to fire are application specific.  Heck, it's a toss-up 
whether the property or the client should be the sender of a message 
(basically depends on whether you normally want to filter by one or the 
other).

The OpenGLContext vrml scenegraph has PyDispatcher-sending fields 
built-in if you want to see a real-world use.  (We have others which use 
BasicProperty + PyDispatcher, but they're not Open-Source).

Have fun,
Mike

-- 
________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: observable.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20050725/76d18555/attachment.ksh>


More information about the Python-list mailing list