[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Multiple addlistener calls?
From: |
Ben Abbott |
Subject: |
Re: Multiple addlistener calls? |
Date: |
Wed, 29 Jul 2015 17:34:49 -0400 |
> On Jul 29, 2015, at 2:25 PM, Rik <address@hidden> wrote:
>
> All,
>
> Should it be possible to add the same function multiple times as a listener
> on a graphics property?
>
> -- Start Code --
> octave:1> function mycb (~,~)
> > disp ("Executing mycb");
>
> > endfunction
> octave:2> h = plot (1:10);
>
> octave:4> addlistener (h, 'color', @mycb)
> octave:5> set (h, 'color', 'r')
> Executing mycb
> octave:6> addlistener (h, 'color', @mycb)
> octave:7> set (h, 'color', 'g')
> Executing mycb
> Executing mycb
> octave:8> addlistener (h, 'color', @mycb)
> octave:9> set (h, 'color', 'b')
> Executing mycb
> Executing mycb
> Executing mycb
> octave:10> dellistener (h, 'color', @mycb)
> octave:11> set (h, 'color', 'm')
> Executing mycb
> Executing mycb
> Executing mycb
> -- End Code --
>
> It's making things awkward in legend.m where I'm trying to avoid multiple
> listener assignments. If the C++ code were to weed these out it would make
> the m-file simpler. Otherwise, I have to figure out which new legend objects
> were part of an existing legend and avoid adding listeners on just those
> instances.
I don’t recall intending to have the same function registered as a listener on
a property more than once. I do recall worrying about that.
If a change is made, I expect there will be some problems, but I also expect
they will be more manageable than the current implementation.
While you’re modifying this part of the code, would it be possible to add a
getlistener(h,prop) function, and have it return a cell array of the register
listeners? I expect this idea is superficially simple but quite complex to
implement, but just in case it is straight forward, I thought I’d ask.
Ben