enable/disable menu next to radiobuttons when those are selected/deselected
1 view (last 30 days)
Show older comments
Hi,
I have a gui which takes 7 parameter which are associated with 2 radiobutton groups. What i have managed to do is read the parameters value and enable the radiobuttons and there associated popmenus that are linked to these parameters.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1148385/image.jpeg)
Here is my gui here for exemple i have the parameters Indx which value is 4 associated with the radiobutton G5/3 so this radiobutton takes the value 1 and with it i have the parameter ParamStr which value is 1 which enable the popmenu linked to radiobutton and select the first element of the popmenu. Then i have the parameter Indx2 which value is 3 associated with the radiobutton EN50160 and same i have a parameter ParamStr5 of value 2 which enable the popmenu and takes it's second value.
Here is my program :
function kgexec4n(Init,action)
%KGEXEC4N boite de dialogue "norme" associée à kgexec4
%CAVIAR2, © ALSTOM + OL 2000/04-2003/03
error(nargchk(0,1,nargin));
persistent blkParamNorm
%%%% ouverture boite
if nargin==1
%"full block path name" du bloc ParamNorme
blkParamNorm=gcb;
if ~strcmp(get_param(blkParamNorm,'MaskType'),'ParamNor')
errordlg(kverranorm(14),'Caviar3','modal')
return
end
%création figure
hf=kgui4n;
%en cas de librairie verrouillée on interdit OK
%x=get_param(get_param(gcs,'Parent'),'Lock'); %modif2.4 10/03/2006
rep=findstr(gcs,'/');
if isempty(rep)
active_sys=gcs;
else
active_sys=gcs(1:rep-1)
end
x=get_param(active_sys,'Lock')
set( findobj(hf,'Tag','NormeOK'), 'Enable', onoff(~onoff(x)) )
else
hf=gcbf;
end
%%%% handle des contrôles et dévalidation de tout
hrb=[findobj(hf,'Tag','Norme0')
findobj(hf,'Tag','NormeEm')
findobj(hf,'Tag','NormeG53')
findobj(hf,'Tag','NormeCh')
findobj(hf,'Tag','NormeUsrI')
findobj(hf,'Tag','Norme519')];%First radiobutton group
hrbVal=get(hrb,'Value');
set(hrb,'Value',0)
hrt=[findobj(hf,'Tag','Norme1022')
findobj(hf,'Tag','NormeUsrV')
findobj(hf,'Tag','Norme50160')];%Second radiobutton group
hrtVal=get(hrt,'Value');
set(hrt,'Value',0)
hno=[findobj(hf,'Tag','Param0')
findobj(hf,'Tag','Param1022')
findobj(hf,'Tag','ParamEm')
findobj(hf,'Tag','ParamG53')
findobj(hf,'Tag','ParamCh')
findobj(hf,'Tag','ParamUsrV')
findobj(hf,'Tag','ParamUsrI')
findobj(hf,'Tag','Param50160')
findobj(hf,'Tag','Param519-1')
findobj(hf,'Tag','Param519-2')
findobj(hf,'Tag','Param519-3')
findobj(hf,'Tag','Param519-4')];%all popmenu and edit box handles
set(hno,'Enable','off')
if nargin==1
try
no=str2num(get_param(blkParamNorm,'Indx'));%look the parameter Indx in the block which tells what radiobutton of the first group need to be selected
set(hrb(no),'Value',1) %Select the radiobutton(one of the first group) (no=2 select Emeraude, no=3 select G5/3 ....)
switch no
case 2%Emeraude
x=get_param(blkParamNorm,'ParamStr');
set(hno(3),'String',x,'Enable','on')% Enable the popmenu or edit box associated with the radiobutton emeraude
case 5%UsrI
x=get_param(blkParamNorm,'ParamStr');
set(hno(7),'String',x,'Enable','on')
case 3%G5/3
x=get_param(blkParamNorm,'ParamStr');
set(hno(4),'Value',str2num(x),'Enable','on')
case 4%Chine
x=get_param(blkParamNorm,'ParamStr');
set(hno(5),'Value',str2num(x),'Enable','on')
case 6%IEEE519
x=get_param(blkParamNorm,'ParamStr');
set(hno(9),'Value',str2num(x))
x=get_param(blkParamNorm,'ParamStr2');
set(hno(10),'String',x)
x=get_param(blkParamNorm,'ParamStr3');
set(hno(11),'Value',str2num(x))
x=get_param(blkParamNorm,'ParamStr4');
set(hno(12),'Value',str2num(x))
Scr519(hno(9:12))
end
no1=str2num(get_param(blkParamNorm,'Indx2'));%look the parameter Indx in the block which tells what radiobutton of the second group need to be selected
set(hrt(no1),'Value',1)%Select the radiobutton(one of the second group) (no=2 select UsrV, no=3 select EN50160 ....)
switch no1
case 2%UsrV
x1=get_param(blkParamNorm,'ParamStr5');
set(hno(6),'String',x1,'Enable','on')
case 3%EN50160
x1=get_param(blkParamNorm,'ParamStr5');
set(hno(8),'Value',str2num(x1),'Enable','on')
end
catch
error(kverranorm(7))
end%try
return
end
function enable(h)
set(h,'Enable','on')
%%%%%%%%%%%%
function Scr519(h)
enable(h)
x=get(h(3),'Value');%n° ISC/IL en cours
switch get(h(1),'Value')
case {1,2}
if (x<1)||(x>5),x=1;end
ch='Iscr<20|20<Iscr<50|50<Iscr<100|100<Iscr<1k|1000<Iscr';
case 3
if (x<1)||(x>2),x=1;end
ch='Iscr<25|25<Iscr>50|Iscr>=50';
otherwise
error(kverranorm(6))
end
set(h(3),'String',ch,'Value',x)
What i would like to do now is for each of my buttongroups when i select one of the radiobuttons it enables the popmenu or edit box that is beside the radiobutton. I have no idea how to do that as i have two radiobuttongroups and i tried using a switch but it doesn't work with 2 groups but works when i have one :
%%%% gestion dynamique de la boite
switch get(gcbo,'Tag'); %l'objet ayant provoqué l'appel
%dialogue dynamique
case 'Norme0'
set(gcbo,'Value',1)
case 'Norme1022'
set(gcbo,'Value',1)
case 'NormeUsrV'
set(gcbo,'Value',1),enable(hno(6))
case 'Norme50160'
set(gcbo,'Value',1),enable(hno(8))
case 'NormeEm'
set(gcbo,'Value',1),enable(hno(3))
case 'NormeG53'
set(gcbo,'Value',1),enable(hno(4))
case 'NormeCh'
set(gcbo,'Value',1),enable(hno(5))
case 'NormeUsrI'
set(gcbo,'Value',1),enable(hno(7))
case {'Norme519','Param519-1'}
set(hrb(9),'Value',1),Scr519(hno(9:12))
end
If anyone could suggest me some way to make it work for two buttongroups i would help a lot.
0 Comments
Accepted Answer
J. Alex Lee
on 7 Oct 2022
You are hiding how you created the radio buttons in the gui creation, but a big question is whether when you say "2 button groups", do you really mean you created radio buttons within matlab button groups (uibuttongroup), or do you mean you created radio buttons, and some of them belong in your mind to 1 group, and the rest to another?
If you use uifigure and uibuttongroup, below seems to be Matlab's recommended way(do doc uiradiobutton).
But this is somewhat annoying because you can't automatically place children of a buttongroup in a grid layout.
fig = uifigure
uig = uigridlayout(fig,[1,2])
bgA = uibuttongroup(uig,"SelectionChangedFcn",@bgAChangedFcn,"Title","GrpA")
bgB = uibuttongroup(uig,"SelectionChangedFcn",@bgBChangedFcn,"Title","GrpA")
uigA = uigridlayout(bgA,[3,1])
uigB = uigridlayout(bgB,[3,1])
rbA(1) = uiradiobutton(bgA,"Text","GrpA 1","Position",[10,10,100,22])
rbA(2) = uiradiobutton(bgA,"Text","GrpA 2","Position",[10,42,100,22])
rbA(3) = uiradiobutton(bgA,"Text","GrpA 3","Position",[10,74,100,22])
rbB(1) = uiradiobutton(bgB,"Text","GrpB 1","Position",[10,10,100,22])
rbB(2) = uiradiobutton(bgB,"Text","GrpB 2","Position",[10,42,100,22])
rbB(3) = uiradiobutton(bgB,"Text","GrpB 3","Position",[10,74,100,22])
function bgAChangedFcn(src,evnt)
src
evnt
evnt.NewValue
end
function bgBChangedFcn(src,evnt)
src
evnt
evnt.NewValue
end
7 Comments
More Answers (0)
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!