Get gui to run a command when getting an error from trying to rewrite a file that is open, or the user cancel during save.
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi
I have this GUI where the user gets to save a print of the GUI to a PDF, during that process some of the popup-menu, edit-boxes and check-boxes are changed to invisible due to the fact I don't want the "client" to see the input. And after the user has saved the file, the code makes them visible again. But this leaves me with a little problem.
Because if the user tries to overwrite a PDF that is already open, this leaves an error, and the code behind the save function doesn't run, and thereby it doesn't make the popup-menu visible again.
The same occurs of the user cancels the save during the process, here again the different, popup-menu's, edit-boxes and check-boxes are left invisible.
My question is:
Is there a way to catch the error, show it to the user so they know that they are trying to rewrite a file that is open, and then afterwards run the rest of the code so the popup-menu's, edit-boxes and check-boxes becomes visible again?
[FileName,PathName] = uiputfile('*.pdf','Save Print',[handles.workingPath '\Mydata');
I've tried reading try and catch commands, but don't understand what to do.
댓글 수: 0
채택된 답변
Jan
2018년 1월 19일
편집: Jan
2018년 1월 19일
... Your code to make the GUI parts invisible comes here
Folder = fullfile(handles.workingPath, 'Mydata'); % FULLFILE is safer than []
[FileName, PathName] = uiputfile('*.pdf', 'Save Print', Folder);
if ~isequal(FileName, 0) % User did not hit Cancel
try
... Your code to save the file as PDF
catch ME
% Inform the user about the problem:
fprintf('PDF export failed: %s\n', ME.message);
end
end
... the code to re-enable the visibility again comes here
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dialog Boxes에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!