GUI toolbar frozen by uiwait command

조회 수: 2 (최근 30일)
Rachel S.
Rachel S. 2016년 12월 1일
답변: Daniel Rivera 2023년 1월 31일
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
Geoff Hayes
Geoff Hayes 2016년 12월 2일
Rachel - please provide a sample of your code that exhibits the problem so that we can better troubleshoot it.
Rachel S.
Rachel S. 2016년 12월 5일
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!

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

답변 (3개)

Image Analyst
Image Analyst 2016년 12월 2일
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
Rachel S.
Rachel S. 2016년 12월 5일
편집: Rachel S. 2016년 12월 5일
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 2016년 12월 5일
편집: Image Analyst 2016년 12월 5일
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.

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


Simon Morisset
Simon Morisset 2017년 7월 25일
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
Rachel S.
Rachel S. 2017년 7월 26일
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 2021년 1월 5일
Rachel
what did you mean by: "Add the line 'Zoom On' to the function". Can you show an example ? I have the same problem...

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


Daniel Rivera
Daniel Rivera 2023년 1월 31일
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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by