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

 Réponse acceptée

Evan
Evan le 14 Fév 2012
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!

Plus de réponses (1)

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 commentaires

Evan
Evan le 14 Fév 2012
Modifié(e) : Evan le 22 Juil 2013
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!!!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by