Using uialert with uiwait and uiresume

Hi all, I have a GUI where asks the user to save a file. I check the filename and depending on the result either carry on or ask the user to change it. All of this is contained within a while loop so that it will continually loop around until the checks have passed or the user has cancelled.
Within this loop I have the alert that pops up stating the error
uialert(app.mainGuiUIFigure,{'New file name must not be the same as the default name, choose another'},'File name error','Icon','warning');
I want this to block execution of the code until the user presses ok. So I have tried using uiwait
uialert(app.mainGuiUIFigure,{'New file name must not be the same as the default name, choose another'},'File name error','Icon','warning','CloseFcn','uiresume');
uiwait
but it creates a blank figure window first. It will stop execution and will only resume once I close the alert window, but this new figure has popped up. How do I prevent this figure window from popping up? Is there a better way to do what I want?
I have successfully used waitfor(warndlg(...)); before, but as this is in appdesigner, I thought I'd use the new dialogue boxes to match the newer GUI graphics stlye.
Matlab 2017b, Windows 7-64bit

 채택된 답변

Alexander Kornegay
Alexander Kornegay 2019년 7월 26일

2 개 추천

Try this instead:
uialert(app.mainGuiUIFigure,{'New file name must not be the same as the default name, choose another'},'File name error','Icon','warning','CloseFcn','uiresume(gcbf)');
uiwait(gcbf)
This will use the current figure instead of creating a new one in the process.

댓글 수: 5

Vas
Vas 2019년 7월 29일
This works great. I have had to make some changes to my code to get around this, but I can definately use this in the future. Thanks
Andrew Diamond
Andrew Diamond 2020년 5월 27일
This doesn't seem to work for me as calling uiwait(gcbf) waits on my app window and so the only way to get past the uiwait(gbcf) is to close the app itself (gbcf being isequal to my app's main figure so in the given example , isequal(app.mainGuiUIFigure, gbcf)). Am I missing something?
Adam Gogacz
Adam Gogacz 2020년 10월 3일
편집: Adam Gogacz 2020년 10월 3일
I don't believe this answers the OP question. Assume you have a figure with a whole bunch of buttons and other controllers. Now, assume that when you press one of the buttons, the callback executes some code and checks for data conditions, assume now that you pop up an "uialert" dialog, BUT you don't want to proceed with the code UNTIL the alert dialog box is closed. Unlike "warndlg", which returns the hosting figure's handle, uialert returns nothing that we can use to "waitfor".
Adam Gogacz
Adam Gogacz 2020년 10월 3일
편집: Adam Gogacz 2020년 10월 3일
Actually, "uiconfirm" with the "Option" set to "OK" will do. Make sure you are assigning the call to "uiconfirm" to a dummy variable to pause the execution.
David Young
David Young 2021년 3월 1일
Thank you Adam Gogacz, both for the analysis and the suggestion to use uiconfirm. But what a shame that uialert doesn't return an object to wait for - that greatly limits the situations where it's useful.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

lihiniya
lihiniya 2022년 1월 21일

1 개 추천

You can use uiconfirm instead of uialert.
answr=uiconfirm(app.AiDAAnalysisV201alphaUIFigure,...
"New file name must not be the same as the default name, Choose another",...
"Warning",'Options',"OK",'Icon','warning');
You don't need to do anything with returned selection, because there's one possible option "OK".

댓글 수: 1

important, however, that there is an assignment to something ('answr' in the example ablve). If you keep it as simple as
uiconfirm(app.AiDAAnalysisV201alphaUIFigure,...
"New file name must not be the same as the default name, Choose another",...
"Warning",'Options',"OK",'Icon','warning');
the application continues, without pause on the opening of the confirmation dialog

댓글을 달려면 로그인하십시오.

Ron Fredericks
Ron Fredericks 2022년 4월 26일
편집: Ron Fredericks 2022년 4월 26일

0 개 추천

I thank that Vas almost had the correct answer with:
uialert(app.mainGuiUIFigure,{'New file name must not be the same as the default name, choose another'},'File name error','Icon','warning','CloseFcn','uiresume');
Try this instead, it works for me when I need to wait for a response then close out the window (Note the @ sign). Also no uiwait required:
uialert(app.mainGuiUIFigure,{'New file name must not be the same as the default name, choose another'},'File name error','Icon','warning','CloseFcn',@(h,e) close(app.mainGuiUIFigure));
More details here:
https://www.mathworks.com/matlabcentral/answers/503729-how-to-close-the-figure-contain-the-uifigure-after-the-alert-is-closed#answer_413884
Marco Avalos
Marco Avalos 2024년 3월 8일
편집: Marco Avalos 2024년 3월 8일

0 개 추천

I use a line creating a variable which is the uifigure that I am using for the app, and then use UIconfirm and that did the job. these are the lines I used
fig = app.figure1; % In app designer this is the main UIfigure for your GUI
uiconfirm(fig,'Please select one option','Selection error');

카테고리

도움말 센터File Exchange에서 Maintain or Transition figure-Based Apps에 대해 자세히 알아보기

제품

릴리스

R2017b

질문:

Vas
2019년 5월 21일

댓글:

2025년 10월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by