GUI radio button issue

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

GUI radio button issue

Grumpulus
I have been trying to get a simple GUI going. It has one button group with
three radio buttons.

Pressing buttons 1 or 2 is intended to imagesc() one of the matrices in the
last two function arguments. Button 3 should display their difference when
pressed. That does not happen, though. Instead, the GUI displays what should
have been shown by the *previous* selection. For example, if I press button
2 and then button 3, it displays what button 2 should have displayed, even
though button 3 is checked.

Also, I had thought that radio button groups are supposed to have one
selection active at all times. That is not the case here. I have to set the
Value field of one button to 1 manually, otherwise none of them will be
selected.

I have tried messing around with ButtonDownFcn, setting the Enable field to
"off" as suggested in other threads, etc. -- nothing seems to work
correctly.

It has been many years since I wrote an Octave GUI, so I am probably making
some rookie mistake, but can't figure it out for the life of me. I am
running Octave 4.4.1 on Centos. Anyways, here's the code:



Any suggestions will be appreciated.
Grump



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: GUI radio button issue

Grumpulus
AAARGH, it looks like the code got left out of my post for some reason. I'll
try again tomorrow.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: GUI radio button issue

Grumpulus
% Args: fHandle is a figure handle.
%       AsC and AsO are numerical matrices with the same size.

function guitest(fHandle, AsC, AsO)

if (!size_equal(AsC, AsO))
  error("Arguments must have equal sizes");
end

set(fHandle,'Position',[300 100 560 880]);

ax1 = axes;

set(ax1, 'Position', [0.13 0.21 0.775 0.715]);

gp = uibuttongroup(fHandle, 'Position', [0.05 0.02 0.15 0.15]);

b1 = uicontrol(gp, "Style",     "Radiobutton", "String", "1", ...
                   "Position",  [0 67 100 32], ...
                   "Value",     1, ...
                   "CreateFcn", {@cbackfcn, ax1, AsC}, ...
                   "Callback",  {@cbackfcn, ax1, AsC});

b2 = uicontrol(gp, "Style",     "Radiobutton", "String", "2", ...
                   "Position",  [0 34 100 32], ...
                   "Callback",  {@cbackfcn, ax1, AsO});

b3 = uicontrol(gp, "Style",     "Radiobutton", "String", "3", ...
                   "Position",  [0  1 100 32], ...
                   "Callback",  {@cbackfcn, ax1, AsC-AsO});
endfunction

function cbackfcn(src, eventdata, ax1, Asm)

  imagesc(ax1, Asm);

endfunction





--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

RE: GUI radio button issue

Tony Richardson
I am top posting because the last post in this thread (the one containing code) has no context.

The callback function is called for the deselected button and the newly selected button (add a line to display Asm in your callback and you will see that it is displayed twice every time you select a new button).  An easy fix is to change your callback to:

function cbackfcn(src, eventdata, ax1, Asm)
  if(get(src,"value") == 1)
    imagesc(ax1, Asm);
  end
endfunction

This ensures that the image corresponding to the newly selected button is shown.

Tony Richardson

> Sent: Wednesday, November 7, 2018 6:51 PM
> To: [hidden email]
> Subject: Re: GUI radio button issue
>
> % Args: fHandle is a figure handle.
> %       AsC and AsO are numerical matrices with the same size.
>
> function guitest(fHandle, AsC, AsO)
>
> if (!size_equal(AsC, AsO))
>   error("Arguments must have equal sizes"); end
>
> set(fHandle,'Position',[300 100 560 880]);
>
> ax1 = axes;
>
> set(ax1, 'Position', [0.13 0.21 0.775 0.715]);
>
> gp = uibuttongroup(fHandle, 'Position', [0.05 0.02 0.15 0.15]);
>
> b1 = uicontrol(gp, "Style",     "Radiobutton", "String", "1", ...
>                    "Position",  [0 67 100 32], ...
>                    "Value",     1, ...
>                    "CreateFcn", {@cbackfcn, ax1, AsC}, ...
>                    "Callback",  {@cbackfcn, ax1, AsC});
>
> b2 = uicontrol(gp, "Style",     "Radiobutton", "String", "2", ...
>                    "Position",  [0 34 100 32], ...
>                    "Callback",  {@cbackfcn, ax1, AsO});
>
> b3 = uicontrol(gp, "Style",     "Radiobutton", "String", "3", ...
>                    "Position",  [0  1 100 32], ...
>                    "Callback",  {@cbackfcn, ax1, AsC-AsO}); endfunction
>
> function cbackfcn(src, eventdata, ax1, Asm)
>
>   imagesc(ax1, Asm);
>
> endfunction
>
>
>
>
>
> --
> Sent from: http://octave.1599824.n4.nabble.com/Octave-General-
> f1599825.html
>



Reply | Threaded
Open this post in threaded view
|

RE: GUI radio button issue

Grumpulus
Thanks for your help Tony. I did notice that the callback function was
running twice each time, and had figured out why that was, but never thought
of using the Value field to discriminate between the two calls.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html