
Icon Editor
12-39
Returning Only After the User Makes a Choice
At the end of the initialization code, and just before returning, iconEditor calls
uiwait with the handle of the main figure to make the GUI blocking.
% Make the GUI blocking
uiwait(hMainFigure);
% Return the edited icon CData if it is requested
mOutputArgs{1} =hMainFigure;
mOutputArgs{2} =mIconCData;
if nargout>0
[varargout{1:nargout}] = mOutputArgs{:};
end
Placement of the call to uiwait is important. Calling uiwait stops the
sequential execution of the
iconEdit M-file after the GUI is initialized and just
before the file would return the edited icon data.
When the user clicks the
OK button, its callback, hOKButtonCallback, calls
uiresume which enables the M-file to resume execution where it stopped and
return the edited icon data.
function hOKButtonCallback(hObject, eventdata)
% Callback called when the OK button is pressed
uiresume;
delete(hMainFigure);
end
When the user clicks the Cancel button, its callback,
hOCancelButtonCallback, effectively deletes the icon data then calls
uiresume. This enables the M-file to resume execution where it stopped but it
returns a null matrix.
function hCancelButtonCallback(hObject, eventdata)
% Callback called when the Cancel button is pressed
mIconCData =[];
uiresume;
delete(hMainFigure);
end
Kommentare zu diesen Handbüchern