Thread Subject: Callback problems within GUI

Subject: Callback problems within GUI

From: Phil

Date: 8 Apr, 2009 15:51:01

Message: 1 of 2

As part of a class I generate a GUI which allows the user to input data which is held in the class object and processed later. As part of this GUI I want to assign a callback function to a drop down menu. I have set up the test class below which basically summarises the callback element of this problem.

When I run the class and attempt to call the dropdown menu callback it returns a 'Too many input arguments' error. I have checked which arguments are being passed to listboxUpdate in varargin and there are two fields (the source handle and an empty event data field). I have the callback function set up to recieve these two arguments but I still receive this error. When I set up the gui as a function rather than as a method within a class this error doesn't occur. I'm stumped, any help gratefully received.

Dummy class:

%Snip

    methods
        function newtest = listUpdateTest()
            figHan = figure;
            
            popupText = [{'option 1'} {'option 2'}];
            puHan = uicontrol(figHan, 'style' , 'popupmenu', 'string', popupText);
            set(puHan, 'callback', {@newtest.listboxUpdate});
            
            newtest.lbHanText{1} = [{'option1'} {'dog'} {'cat'}];
            newtest.lbHanText{2} = [{'option2'} {'monkey'}];
            
            lbHan = uicontrol(figHan, 'style', 'listbox', 'string', newtest.lbHanText{1}, 'units', 'normalized', 'position', [0.5 0.5 0.2 0.2]);
        end
        
        function listboxUpdate(source, event)
            set(lbHan, 'string', newtest.lbHanText{get(source, 'value)})
        end

Subject: Callback problems within GUI

From: Jonathan

Date: 9 Apr, 2009 00:56:02

Message: 2 of 2

"Phil " <northern69@yahoo.com> wrote in message <grih55$m8j$1@fred.mathworks.com>...
> As part of a class I generate a GUI which allows the user to input data which is held in the class object and processed later. As part of this GUI I want to assign a callback function to a drop down menu. I have set up the test class below which basically summarises the callback element of this problem.
>
> When I run the class and attempt to call the dropdown menu callback it returns a 'Too many input arguments' error. I have checked which arguments are being passed to listboxUpdate in varargin and there are two fields (the source handle and an empty event data field). I have the callback function set up to recieve these two arguments but I still receive this error. When I set up the gui as a function rather than as a method within a class this error doesn't occur. I'm stumped, any help gratefully received.
>
> Dummy class:
>
> %Snip
>
> methods
> function newtest = listUpdateTest()
> figHan = figure;
>
> popupText = [{'option 1'} {'option 2'}];
> puHan = uicontrol(figHan, 'style' , 'popupmenu', 'string', popupText);
> set(puHan, 'callback', {@newtest.listboxUpdate});
>
> newtest.lbHanText{1} = [{'option1'} {'dog'} {'cat'}];
> newtest.lbHanText{2} = [{'option2'} {'monkey'}];
>
> lbHan = uicontrol(figHan, 'style', 'listbox', 'string', newtest.lbHanText{1}, 'units', 'normalized', 'position', [0.5 0.5 0.2 0.2]);
> end
>
> function listboxUpdate(source, event)
> set(lbHan, 'string', newtest.lbHanText{get(source, 'value)})
> end

Phil-

In classes, you must remember that every that any function must have the object as the first input argument. Thus your callback should look like this:

function listboxUpdate(newtest,source,event)
    set(lbHan, 'string', newtest.lbHanText{get(source, 'value)})
end

Where newtest is the object.

-Jonathan

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com