GUI toolbar frozen by uiwait command

1 view (last 30 days)
Rachel S.
Rachel S. on 1 Dec 2016
Answered: Daniel Rivera on 31 Jan 2023
I created a GUI in Guide that includes axes and a toolbar to zoom and pan. I added uiwait to OpeningFcn and uiresume on a button callback, to allow user input prior to returning the output to a script from the OutputFcn. But now the toolbar no longer works. I need the toolbar function before the ouput is returned. How can I get the toolbar to work?
  2 Comments
Geoff Hayes
Geoff Hayes on 2 Dec 2016
Rachel - please provide a sample of your code that exhibits the problem so that we can better troubleshoot it.
Rachel S.
Rachel S. on 5 Dec 2016
My code contains the following to postpone the OutputFcn from immediately updating when the GUI is executed. For a while I would get either 1) an immediate output (with a matrix of the initial values) or 2) no output because I was not properly implementing the uiresume prior to closing. The code below is a huge improvement, but the toolbar functions (zoom,pan) do not work.
I used uiwait and the END of my OpeningFcn.
function UserAlignGUI_OpeningFcn(hObject, eventdata,handles)
%code to generate initial graph
guidata(hObject, handles);
uiwait(handles.figure1);
Then to update the output prior to the user closing the GUI, I implemented a button and used uiresume prior to updating the output variable.
function ExitB_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
uiresume(handles.figure1)
varargout{1} = handles.shift;
According to several message strings I should have been able to put this in the closing function, but that did not work for me. Although I left the attempt in my code (shown below),...
function CloseMenuItem_Callback(hObject, eventdata, handles)
selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
['Close ' get(handles.figure1,'Name') '...'],...
'Yes','No','Yes');
if strcmp(selection,'No')
return;
end
if isequal(get(hObject,'waitstatus'),'waiting')
uiresume(handles.figure1)
else
delete(handles.figure1)
end
Perhaps it is because I did not up my output argument immediately, but it should have been updated when it called the OutputFcn.
function varargout = UserAlignGUI_OutputFcn(hObject, eventdata, handles)
handles = guidata(handles.figure1);
varargout{1} = handles.shift;
delete(handles.figure1)
In the process of developing this, I found the uiwait would prevent the generation of the initial graph in the OpeningFcn. Yet, once I place it at the end of the OpeningFcn it allows the graph to be updated as intended with my code. Only the toolbar does not work.
I really appreciate any thoughts or ideas on how to resolve this problem. Thanks!

Sign in to comment.

Answers (3)

Image Analyst
Image Analyst on 2 Dec 2016
I don't have uiwait in my GUIs. I can have my script wait for the GUIDE-based GUI and I still have access to the tool ribbon if I switch back to MATLAB. For example with my threshold GUI:
grayImage = imread('moon.tif');
imshow(grayImage, []);
[lowThreshold, highThreshold] = threshold(83, 255, grayImage); % Wait for user input before continuing.
fprintf('done');
Try taking out the uiwait().
  2 Comments
Rachel S.
Rachel S. on 5 Dec 2016
Edited: Rachel S. on 5 Dec 2016
uiwait() was necessary to postpone the Output from the GUI. The problem is with GUIs generated by Guide. It updates the output immediately upon execution of the GUI and will not update if the variable is changed within the GUI - even if the variable is updated and OutputFcn is called prior to closing. I don't understand it, but there are message strings documenting the problem and all advise to use uiwait().
Image Analyst
Image Analyst on 5 Dec 2016
Edited: Image Analyst on 5 Dec 2016
Are you saying that your main GUI keeps on executing code beyond the call to your second GUI and doesn't wait for you to close the second GUI? Because mine do not. Maybe try making your second GUI modal, but I don't think that should not be necessary.

Sign in to comment.


Simon Morisset
Simon Morisset on 25 Jul 2017
Hello I have the same problem (Matlab 2015b). If I add "uiwait(handles.figure1);" at the end of the function *OpeningFcn(hObject, eventdata, handles, varargin) I can't any more use the zoom toolbar. The figure is like freeze...
  2 Comments
Rachel S.
Rachel S. on 26 Jul 2017
I found that you must add a callback function to the m-script. In Guide, go to the menu Tools-Tool Bar Editor and click View for 'On Callback' for the Zoom button (default was 'Clicked Callback'). This will add the function for a uitoggle tool associated with the button to your m-script. Add the line 'Zoom On' to the function and it will use that code to enable the zoom. The same for the other functions.
Felipe Lima
Felipe Lima on 5 Jan 2021
Rachel
what did you mean by: "Add the line 'Zoom On' to the function". Can you show an example ? I have the same problem...

Sign in to comment.


Daniel Rivera
Daniel Rivera on 31 Jan 2023
A bit late, but I found that instead of using uiwait(), putting in a while loop waiting for a UserData parameter to change works as well. In the opening function, I set the userdata to true.
function myGUI_OpeningFcn(hObject,eventdata,handles,varargin)
...
hObject.UserData = true;
...
end
The output function tries to run immediately so I force it into a while loop until the userdata is set to false by another function, such as the CloseRequestFcn. Since the function started, you'll need to call for the handles to be updated (which I can't figure out right now) or use the getappdata/setappdata on the data you wish to pull.
function varargout = myGUI_OutputFcn(hObject,eventdata,handles)
while hObject.UserData
drawnow
end
% get desired outputs using getappdata
varargout{1} = getappdata(hObject,'VarName');
...
end
function myfigure_CloseRequestFcn(hObject,eventdata,handles)
var = handles.myOutputName % get stored handles variable
setappdata(hObject,'VarName',var) % store variable information for access by the output function
hObject.UserData = false;
end

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!