Make a test on UI CONTROL , style popupmenu

6 visualizaciones (últimos 30 días)
Hugo
Hugo el 13 de Jul. de 2014
Respondida: Hugo el 31 de Jul. de 2014
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)

Respuesta aceptada

Jan
Jan el 13 de Jul. de 2014
Editada: Jan el 13 de Jul. de 2014
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 comentarios
Joseph Cheng
Joseph Cheng el 21 de Jul. de 2014
Editada: Joseph Cheng el 21 de Jul. de 2014
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
Hugo
Hugo el 22 de Jul. de 2014
Editada: Hugo el 22 de Jul. de 2014
I try to explain again :
i got lot of popup menu :
they're ALL in mode : ENABLE OFF.
When i begin my GUI, i can select to put some ON .
1) I would to FIND the popupmenu with mode : ENABLE ON , because the POPUPMENU OFF get the string : ' ' , (empty/blank).
2) After Find the Popup "ON", Check the BLANK/EMPTY in the CELL of THIS popupmenu (ENABLE ON).
3)
- If any BLANK/EMPTY is FIND => Activate a Pushbutton
- If a popupmenu is find with BLANK EMPTY => Say ERROR
.
The tags of my popup are :
Type_X
typeX
Modele_X
ModeleX
Essieu_X
Where X are the number : 1 to 10
.
Joseph Cheng : i don't know how to use your code for my GUI.
.
This code work , but i don't know how to add the code : to select ONLY The Popupmenu mode : ENABLE ON
function Test_Callback(hObject, eventdata, handles)
nameList = {'Essieu_', 'Type_', 'modele_', 'type', 'modele'};
for iName = 1:5
for iIndex = 1:10
Field = sprintf('%s%d', nameList{iName},iIndex);
H = handles.(Field);
String = get(H, 'String');
Value = get(H, 'Value');
EmptyStringSelected = cellfun('size', String(Value == 1),1);
if any(EmptyStringSelected)
fprintf(2, 'Problem: Empty string in: %s\n', Field);
end
end
end
end
The help i need is :
How to select only the popupmenu with mode : ENABLE ON in my CODE.
Or , Is it better to change the code ?
Thank you :)

Iniciar sesión para comentar.

Más respuestas (2)

Joakim Magnusson
Joakim Magnusson el 18 de Jul. de 2014
Editada: Joakim Magnusson el 18 de Jul. de 2014
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
  1 comentario
Jan
Jan el 21 de Jul. de 2014
"Error bla bal" is not helpful. Please post the complete message.

Iniciar sesión para comentar.


Hugo
Hugo el 31 de Jul. de 2014
Thanks you Jan simon you're code is near what i would :
function Test_Callback(~, ~, handles) % test sur les popups
nameList = {'Essieu_', 'Type_', 'modele_', 'type', 'modele'};
for iName = 1:5
for iIndex = 1:10
Field = sprintf('%s%d', nameList{iName},iIndex);
if findobj('Tag',Field,'Enable','on')
H = handles.(Field);
String = get(H, 'String');
Value = get(H, 'Value');
EmptyStringSelected = cellfun('size', String(Value == 1),1);
if any(EmptyStringSelected)
fprintf(2, 'Case vide dans: %s\n', Field);
end
end
end
end
if any(EmptyStringSelected) % vérification final du contenu
set(handles.Continuer,'Enable','off')
else
set(handles.Continuer,'Enable','on')
end

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by