help-octave
[Top][All Lists]
Advanced

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

Re: Help-octave Digest, Vol 84, Issue 26


From: Sandeep Kumar
Subject: Re: Help-octave Digest, Vol 84, Issue 26
Date: Tue, 12 Mar 2013 11:57:28 +0530

Respected Sir,
      I want to unsubscribe from this group. Please help me in doing this.
    Thanking you,
Kind regards.


On Tue, Mar 12, 2013 at 12:01 AM, <address@hidden> wrote:
Send Help-octave mailing list submissions to
        address@hidden

To subscribe or unsubscribe via the World Wide Web, visit
        https://mailman.cae.wisc.edu/listinfo/help-octave
or, via email, send a message with subject or body 'help' to
        address@hidden

You can reach the person managing the list at
        address@hidden

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Help-octave digest..."


Today's Topics:

   1. Re: Function handle with arguments for GUI callback
      (Michael Goffioul)
   2. Re: Function handle with arguments for GUI callback (Arnaud Miege)
   3. Re: Function handle with arguments for GUI callback
      (Michael Goffioul)


----------------------------------------------------------------------

Message: 1
Date: Mon, 11 Mar 2013 13:34:24 -0400
From: Michael Goffioul <address@hidden>
To: Arnaud Miege <address@hidden>
Cc: address@hidden
Subject: Re: Function handle with arguments for GUI callback
Message-ID:
        <address@hidden>
Content-Type: text/plain; charset="iso-8859-1"

On Mon, Mar 11, 2013 at 12:43 PM, Arnaud Miege <address@hidden>wrote:

> On 11 March 2013 16:32, Jordi Guti?rrez Hermoso <address@hidden>
>  wrote:
>
>
>> You might be interested in knowing that the current development branch
>> of Octave has changed nested functions:
>>
>>     http://hg.savannah.gnu.org/hgweb/octave/rev/fa3989fbb1b5#l1.57
>>
>> - Jordi G. H.
>>
>
> Thanks. Even though I mentioned nested functions, I am not currently using
> any. My code is structured as follows:
>
> - Main GUI function
>   - Sub-function to create the UI controls
>   - Sub-function for first callback
>   - Sub-function for second callback
>   - etc...
> end
>
> I just need to find a mechanism to pass (and modify) data to/from the
> callback functions to the main GUI function where the information is stored
> (in a struct).
>
> It's good to know about nested functions though, I'll give them a try when
> I upgrade to the next stable release of Octave (hopefully there will have
> some improvement to the Octave GUI by then, fingers crossed). Right now, I
> need a solution for 3.6.2. I have tried defining the callback as a cell
> array, i.e. address@hidden,gui,k} or even
> address@hidden,"gui","k"}, but that didn't work either.
>

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cae.wisc.edu/pipermail/help-octave/attachments/20130311/adf64143/attachment-0001.html>

------------------------------

Message: 2
Date: Mon, 11 Mar 2013 18:13:50 +0000
From: Arnaud Miege <address@hidden>
To: Michael Goffioul <address@hidden>
Cc: address@hidden
Subject: Re: Function handle with arguments for GUI callback
Message-ID:
        <address@hidden>
Content-Type: text/plain; charset="iso-8859-1"

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cae.wisc.edu/pipermail/help-octave/attachments/20130311/27251807/attachment-0001.html>

------------------------------

Message: 3
Date: Mon, 11 Mar 2013 14:31:04 -0400
From: Michael Goffioul <address@hidden>
To: Arnaud Miege <address@hidden>
Cc: address@hidden
Subject: Re: Function handle with arguments for GUI callback
Message-ID:
        <CAB-99LvmhO9VgyGx+VD4MMi5YeBVd9jnQMnuELV8hYj=address@hidden>
Content-Type: text/plain; charset="iso-8859-1"

On Mon, Mar 11, 2013 at 2:13 PM, Arnaud Miege <address@hidden>wrote:

>
> 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).
>

This is standard Matlab behavior:
http://www.mathworks.com/help/matlab/creating_guis/writing-code-for-callbacks.html
(look for  "Use Cell Arrays with Strings")



> 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.
>

As the object is a cell array, you need to index it with {}, but from what
you saying, it doesn't work either. Does it change anything if you do an
assignment instead:

x = gui.browse_btns{k}
x

Michael.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cae.wisc.edu/pipermail/help-octave/attachments/20130311/0eae0988/attachment.html>

------------------------------

_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave


End of Help-octave Digest, Vol 84, Issue 26
*******************************************


reply via email to

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