Make a test on UI CONTROL , style popupmenu
2 次查看(过去 30 天)
显示 更早的评论
Hi everybody, i'm new on Mathswork and i have one question :
I'm making a GUI interface with lot of popupmenu (50)
i would like to make in a Button a test about these :
1 : Check the (each one) Popumenu with "ENABLE" "ON".
2: if they're ON , do a second test.
3: i would like to check if they got "blank string" i mean : a string like this < '' > just a blank without space.
4: if there is a blank : say "ERROR, select something in the popupmenu "
My popupmenu got similar name like this : Modele_1 to 10 , Type_1 to 10 etc... i got 5 name and 10 number per name. ( 5 * 10 = 50 )
I ask someone before, and they said to create a boucle FOR but i don't know how to create it. And i don't know how to make the test clearly.
i show the beginning of my code :
function Continuer_Callback(~, ~, handles)
i=1;
for i=1:10
?????
H = findobj('Style','popupmenu','Enable','on');
if H = ??
G = findobj('Style','popupmenu','String','');
if (isempty(G))
disp('Problème: case blanche');
set(handles.Continuer,'Enable','off')
end
end
end
Thank you ,and help me ....
(sorry for my English if i make some mistake)
0 个评论
采纳的回答
Jan
2014-7-13
编辑:Jan
2014-7-13
It is not clear where the names "Modele_10", "Type_1" etc appear and what "I got 5 names and 10 numbers per name" mean. But let me guess:
function Continuer_Callback(~, ~, handles)
nameList = {'Modele', 'Type', 'Name', 'Flame', 'Shame'};
for iIndex = 1:10
for iName = 1:5
Field = sprintf('%s_%d', nameList{iName});
H = handles.(Field); % Handle of the popupmenu
String = get(H, 'String');
Value = get(H, 'Value');
EmptyStringSelected = cellfun('isempty', String(Value == 1));
if any(EmptyStringSelected)
fprintf(2, 'Problem: Empty string in: %s\n', Field);
set(handles.Continuer, 'Enable', 'off');
end
end
end
I guessed, that you mean if a selected string in empty, and not if this is set to 'Enabled'='on'.
5 个评论
Joseph Cheng
2014-7-21
编辑:Joseph Cheng
2014-7-21
Taking what Jan Simon wrote and my understanding of the problem, here is a uicontrol method to do what you're trying. Very Simplified you'll have to modify it for your stuff especially if you're using GUIDE.
function main()
%my stuff to generate some popup boxes
YPos_offset=-65; %offset in y
fig_hand = figure; %figure handles
%loop to generate popups.
for i=1:5
Type(i)=uicontrol('Style', 'popup',...
'String', '|1|2|3|4|5',...
'Position', [20 340+(i-1)*YPos_offset 100 50],'tag',['TYPE' num2str(i)]);
end
%setting some to enable off;
set(Type(1),'Enable','off');
set(Type(3),'Enable','off');
%disp(Type) %my debuging
%generate pushbutton.
Pbutton=uicontrol('Style', 'pushbutton',...
'String', 'check',...
'Position', [220 340 100 20],...
'Callback', {@check, fig_hand});
end
function check(~,~,fig_hand)
TYPE=findobj(fig_hand,'Style','popup') %this is just to see if the popup numbers match what i have above for Type.
popup_tag = get(TYPE,'tag'); %get the tags
popup_enabled = get(TYPE,'Enable'); %get enabled
popup_stuff = get(TYPE,'String'); %get whats inside the pop up boxes
popup_select = get(TYPE,'Value'); %get which item was selected
for ind = 1:length(TYPE)
if strcmp(popup_enabled{ind},'on'); %check which popups are enabled
if strcmp(popup_stuff{ind}(popup_select{ind}),' ') %check if empty
fprintf(2, 'Problem: Empty string in: %s\n', popup_tag{ind});
else
fprintf(1,'Good: Valid string in: %s is %s\n', popup_tag{ind}, popup_stuff{ind}(popup_select{ind}));
end
else
fprintf(1,'Enable Off for Popup: %s\n', popup_tag{ind});
end
end
end
更多回答(2 个)
Joakim Magnusson
2014-7-18
编辑:Joakim Magnusson
2014-7-18
A pop-up menu with a empty string will not be rendered, it will not be visible.
But maybe you want something like this?
% --- Executes on button press in Continuer.
function Continuer_Callback(~, ~, handles)
%I don´t understand why you want to find all popupmenus with "Enable on" but this %will do it and put them in a list
list_popupmenu = findobj(0,'Style', 'popupmenu', 'Enable', 'On');
%Iterate through the whole list
for i = 1:size(list_popupmenu)
%It's not clear what condition you want to test here
if get(list_popupmenu(i), 'String', '')
errordlg('ERROR, select something in the popupmenu','Empty pop-up menu');
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!