MATLAB Answers

Evan
2

Preventing uiwait from opening a figure window when none exists

Asked by Evan
on 14 Feb 2012
Latest activity Commented on by Marek Svoboda on 24 Aug 2019 at 14:31
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

  0 Comments

Sign in to comment.

2 Answers

Answer by Evan
on 14 Feb 2012
 Accepted Answer

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!

  0 Comments

Sign in to comment.


Answer by Sean de Wolski
on 14 Feb 2012

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 Comments

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!!!

Sign in to comment.