Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
addlistener for gui object

Subject: addlistener for gui object

From: Clemens

Date: 4 Nov, 2010 12:44:04

Message: 1 of 6

Hei guys,

i want to add a listener for 'WindowButtonMotion', and omit the use of the inbuild callback function because there is the posibility to add a large amount of function instead of writing it in one function....

now i have a strange problem:
here the test code:

function blub
  fh=figure('Pos', [400 400 300 300]);
  graph=axes('parent',fh, 'units', 'pixel','pos',[30 50 250 220]);
  lbl1=uicontrol(fh,'style', 'text', 'pos',[0 0 100 20]);

  lh=addlistener(fh, 'WindowButtonMotion',@lbl1_cb);
  function lbl1_cb(src, eventdata)
    pos=get(graph,'currentpoint');
    set(lbl1,'string', pos(1,1));
  end
end

it always gives me "??? Error using ==> addlistener
Too many input arguments."

i have no idea why it isn't working.
Do you have any suggestions? or other techniques were it is possible to add more functions to an event?

Thank you in advance!
Clemens

Subject: addlistener for gui object

From: Clemens

Date: 4 Nov, 2010 12:55:05

Message: 2 of 6

ok, sorry, again i'm stupid, it works now, there was a file named after "addlistener.m" in one of my include folders.

but now still there is a problem:

it seems like the WindowButtonMotion only throws this event after clicking at the graph once and is not constantly thrown many times?

Subject: addlistener for gui object

From: Walter Roberson

Date: 4 Nov, 2010 13:35:27

Message: 3 of 6

On 04/11/10 7:44 AM, Clemens wrote:

> lh=addlistener(fh, 'WindowButtonMotion',@lbl1_cb);

> it always gives me "??? Error using ==> addlistener
> Too many input arguments."

'WindowButtonMotion' is not one of the valid properties that can be set
by addlistener. See
http://www.mathworks.com/help/techdoc/ref/meta.property.html

 > i want to add a listener for 'WindowButtonMotion', and omit the use
 > of the inbuild callback function because there is the posibility to
 > add a large amount of function instead of writing it in one
 > function....

I don't think I understand? There is no requirement that all the
functionality for a single callback must be written into a single
function: the called-back function can call upon other functions as needed.

Are you trying to say that you intend to be adding a large number of
WindowButtonMotion callbacks, all of which are to be triggered when
button motion is detected? If so, then why not just store their
descriptions in a single (cell) array and have a single callback
function that loops through that array triggering each of the stored
callbacks? At the moment I cannot think of a reason _why_ one would want
"a large number" of simultaneous button motion callbacks though.

Subject: addlistener for gui object

From: Clemens

Date: 4 Nov, 2010 14:27:04

Message: 4 of 6

thank you for your suggestion. I want to add functionality to the callback of the mouse movement, just in specific times when the state of the program has changed. (for example picking specific data, or drawing lines or whatever) if all of this is in one callback function it gets messy for a big program since you need to have case or if switches for every possible state (or combinations of them).

this cellarray thing works fine, thanks.

I also managed to fix the addlistener problem. In order to get the event thrown all time the mouse is moving there is a need of a "dummy callback" in the definition of the figure.

i don't know what will be the best solution but i will try both...

in the end its just about overview and managing of the code:)

Thank you
Clemens

Subject: addlistener for gui object

From: Yair Altman

Date: 6 Nov, 2010 16:26:04

Message: 5 of 6

Walter Roberson <roberson@hushmail.com> wrote...
> On 04/11/10 7:44 AM, Clemens wrote:
>
> > lh=addlistener(fh, 'WindowButtonMotion',@lbl1_cb);
> > it always gives me "??? Error using ==> addlistener Too many input arguments."
>
> 'WindowButtonMotion' is not one of the valid properties that can be set by
> addlistener. See http://www.mathworks.com/help/techdoc/ref/meta.property.html

Actually Walter, addlistener(fh, 'WindowButtonMotion',@lbl1_cb) works splendidly, since addlistener works on events, not just properties - the link you mentioned only refers to property listeners. I'm going to carry a series on UDD on my website (courtesy of Donn Shull) in December, and one of its planned articles will be about UDD events and listeners.

In any case, as the OP noted, his specific error was due to overriding addlistener.m with a user function. Without it, he has a second error of setting the uicontrol's String property to a numeric value. other than these, it works ok...

Yair Altman
http://UndocumentedMatlab.com

Subject: addlistener for gui object

From: Clemens

Date: 6 Nov, 2010 20:46:03

Message: 6 of 6

i just want to point out that setting the 'string' value to a numeric value doesn't throws an error, it works fine.:)

Clemens

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us