0

I'm trying to setup a static notification if a value in an array gets changed, but so far I've had no success... I found an earlier question about notifications on changes to a List that used the _items_changed wording that looked like it might work, but alas, it didn't :(

Anyone have a suggestion how I should go about setting up a static notification handler whenever an element of an array gets changed?

BTW, I'm using Enthought Canopy V1.4.1.1975

Steve76063
  • 317
  • 2
  • 10
  • possible duplicate of [How can I fire a Traits static event notification on a List?](http://stackoverflow.com/questions/8371980/how-can-i-fire-a-traits-static-event-notification-on-a-list) – smac89 Nov 14 '14 at 00:02
  • Well, that 'is' where I got the title, but the method used for List notifications didn't work for me, hence my post. – Steve76063 Nov 14 '14 at 14:36

1 Answers1

0

Have you taken a look at how most event driven applications work? You can make a custom list class for yourself, then override the __setitem__ method to notify all listeners that the list has been modified.

class eventList(list):
    def __init__(self, ...):
        self.listeners = []
        ...
    def __setitem__(self, i, val):
        ret = super.__setitem__(self, i, val)
        for l in listeners:
            if isinstance(l, eventListListener):
                l.actionPerformed(self)
        return ret

Where objects that will be notified of this event have to inherit from the eventListListener class and have implemented a method called actionPerformed.

... means incomplete

Note this should be done in a multithreaded environment for it to yield any real benefits

Community
  • 1
  • 1
smac89
  • 39,374
  • 15
  • 132
  • 179
  • Wow, that'll take a lot more understanding of Python than I have right now :) (still somewhat of a noob). I was hoping that there would be an equivalent notification handler to _xx_changed(): for arrays/array elements. – Steve76063 Nov 13 '14 at 21:52