help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Function handle with arguments for GUI callback


From: Arnaud Miege
Subject: Re: Function handle with arguments for GUI callback
Date: Mon, 11 Mar 2013 18:13:50 +0000


On 11 March 2013 17:34, Michael Goffioul <address@hidden> wrote:


Using a cell array is the right approach. It is supported. What error do you get and what code are you using? Also please note that a GUI callback always get the object handle and an event data as first 2 arguments. Whatever arguments you specify in the cell array starts at position 3 in the callback argument list.

Michael.


Thanks, I have made some progress since my initial email.

In my main function, I create a variable called "gui" as the output of a sub-function called create_interface:

gui = create_interface;

In the sub-function create_interface, I add various fields to the gui structure which are handles to the various UI components, such as:

% Add pop-up menus for dimension choice of each input
strings = {'Nominal dimensions|Measurement file'};
width = [0.5 0.5 0.5];
gui.dim_choices = cell(size(gui.inputs_txt));
for k=1:length(gui.inputs_txt)
gui.dim_choices{k} = uicontrol('Style','popupmenu','String',strings,...
        'Units','normalized','Position',[0.23 y_pos(k) width(k) 0.1],...
        'BackgroundColor','w','Parent',gui.inputs_panel,'Callback',...
address@hidden,num2str(k),gui});
end

I have worked out that the first argument to the function handle callback needs to be converted to a string. I am also passing the gui structure as a second argument because I couldn't figure out a way of using the second default argument (eventdata - there doesn't seem to be much documentation about it).

If we then come out of create_interface, I have various functions for the callbacks, all at the same level as create_interface. The one of interest is (I have only put some trivial commands to debug what is going on):

function update_browse_btn(src,data,k,gui)
% Called when user activates popup menu 
disp(['k = ' num2str(k)]);
        val = get(src,'Value')
gui
end

That works well and displays the following in the console when I change the drop-down menu:

>> k = 1
val =  2
gui =

  scalar structure containing the fields:

    Window =  1
    outputs_panel = -28.293
    inputs_panel = -27.709
    graph_panel = -26.338
    HelpMenu = -25.343
    inputs_txt =
    {
      [1,1] = -23.566
      [2,1] = -22.087
      [3,1] = -21.487
    }
    browse_btns =
    {
      [1,1] = -20.863
      [2,1] = -19.427
      [3,1] = -18.260
    }
    dim_choices =
    {
      [1,1] = [](0x0)
      [2,1] = [](0x0)
      [3,1] = [](0x0)
    }

If I then change the callback function slightly to:

function update_browse_btn(src,data,k,gui)
% Called when user activates popup menu 
disp(['k = ' num2str(k)]);
        val = get(src,'Value')
gui.browse_btns
end

I am still getting the expected output:

>> k = 1
val =  2
ans =
{
  [1,1] = -20.090
  [2,1] = -19.064
  [3,1] = -18.774
}

However, if I start using the index k (which has a sensible value between 1 and 3), as in:

function update_browse_btn(src,data,k,gui)
% Called when user activates popup menu 
disp(['k = ' num2str(k)]);
        val = get(src,'Value')
gui.browse_btns(k,1)
end

I get the following error:

>> k = 1
val =  2
error: update_browse_btn: A(I,J): row index out of bounds; value 49 out of bound
 3
error: called from:
error:   <path_to_my_file> at line 185, colu
mn 3

I can't then close the GUI, I need to click on the console to activate it, which triggers the following error message:

error: octave_base_value::convert_to_str_internal (): wrong type argument `<unkn
own type>'
error: octave_base_value::convert_to_str_internal (): wrong type argument `<unkn
own type>'
error: octave_base_value::convert_to_str_internal (): wrong type argument `<unkn
own type>'
error: octave_base_value::double_value (): wrong type argument `<unknown type>'
error: octave_base_value::convert_to_str_internal (): wrong type argument `<unkn
own type>'
error: octave_base_value::convert_to_str_internal (): wrong type argument `<unkn
own type>'
error: octave_base_value::convert_to_str_internal (): wrong type argument `<unkn
own type>'

I then need to press Enter to regain control and close the figure with the close command.

The syntax gui.browse_btns{k} results in a similar behaviour.

Any idea why although k is definitely equal to 1, it says it's 49 when trying to index the structure?

Many thanks,

Arnaud

reply via email to

[Prev in Thread] Current Thread [Next in Thread]