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!