Preventing uiwait from opening a figure window when none exists

I'm currently creating a GUI in which operations need to be halted until a user clicks a pushbutton which calls uiresume. Uiwait creates a figure window if none exists, however, and if the user closes this, uiresume is called whether or not the user hits the button. Is there a way to prevent this, or is uiwait/uiresume not the best way of going about this?
Note that there also may be other figure windows open (depending on the user's actions) at the time, and if possible I would like to have whether or not the program resumes dependent solely on the pushbutton.
Thanks in advance!
Evan

 채택된 답변

Evan
Evan 2012년 2월 14일

0 개 추천

It looks like what I noted in response to your answer fixed it, so I suppose I'll go with that (unless it is for some reason inadvisable). Thanks for the help, and apologies again for the ambiguous question!

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 2월 14일
So you're putting a uiwait() on the figure and then you want them to hit the button before closing the figure?
If so, I would set the closerequestfcn of the figure to [] until the button is pushed, in the button's callback change the closerequestfcn to something useful. Example:
H = figure('closereq',[]);
uicontrol('style','push','string','Push me!','callback',{@(src,evt,H)set(H,'closereq',{@(~,~,H)delete(gcf),H}),H});
uiwait(H);

댓글 수: 3

Evan
Evan 2012년 2월 14일
편집: Evan 2013년 7월 22일
Sorry, I should have explained a bit better. A little background: I have a GUI in which a pushbutton callback calls a function twice to perform the same operations on two sets of data. However, I want to essentially pause the execution of the callback to allow the user to look at some data. It looks something like like this:
function PushButton_Callback(hObject, eventdata, handles)
output1 = somefunction(inputs1)
uiwait
output2 = somefunction(inputs2)
function Resume_Callback(hObject, eventdata, handles)
uiresume
However, I think I may have solved it by making the below changes (not completely sure--just sort of messing around with it at this point):
function PushButton_Callback(hObject, eventdata, handles)
output1 = somefunction(inputs1)
uiwait(handles.mainfighandle)
output2 = somefunction(inputs2)
function Resume_Callback(hObject, eventdata, handles)
uiresume(gcbf)
"Resume_Callback(hObject, eventdata, handles)" being a callback for another pushbutton
I had almost an identical problem and your solution worked for me - thanks!!!

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

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

2012년 2월 14일

댓글:

2019년 8월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by