Reset GUI executable to initial state
16 次查看(过去 30 天)
显示 更早的评论
Is it possible to reset a GUI to the initial state it is in when it's first loaded without closing it and reopening? Upon hitting a "Reset" button, I want a clean slate...all variables and memory cleared, with just whatever the GUI creates when first loaded left.
0 个评论
回答(4 个)
Image Analyst
2013-2-4
I have functions called LoadUserSettings() and SaveUserSettings().
SaveUserSettings() takes the value of all checkboxes, last folder used, radio buttons, and anything else I want to save from session to session and calls save() to save it to a mat file. You can call this function either every time you change a setting that you want to save, or just when you click the OK button to close down the application, whichever way you want to do it.
LoadUserSettings() calls load() to retrieve those variables. For the settings connected with a control (slider, checkbox, etc.), it sends the setting to the control with the set() command. I call this in the OpenFcn function so that it runs on startup.
0 个评论
Voulgarakis Georgios
2013-2-4
I'd suggest you save all the values of the objects you wish to restore, (do it in the openingfcn if you are using the guide), and then under the reset callback, assign them back to the objects you wish to reset.
Voulgarakis Georgios
2013-2-5
Let's say you want when you press reset to restore the state of a text and of a popup:
call in the openingfcn of your gui the save_state():
% --- Executes just before Board is made visible.
function Board_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Board (see VARARGIN)
% Choose default command line output for Board
handles.output = hObject;
save_state(handles);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Board wait for user response (see UIRESUME)
% uiwait(handles.Board);
and in the save_state() function:
function save_state(handles)
%get the data
data.textbox1=get(handles.textbox1,'String');
data.popup1=get(handles.popup1,'Value');
%save the data
%note handles.Board is the handle of my GUI figure
setappdata(handles.Board,'data',data);
end
and for the handles=load_state(handles)
function handles=load_state(handles)
%retrieve the data
data=getappdata(handles.Board,'data');
%load the data to the uicomponents
set(handles.textbox1,'String',data.textbox1);
set(handles.popup1,'Value',data.popup1);
end
Hope I helped!
0 个评论
Gabriella Panuccio
2019-3-5
Hi everyone,
I don't know if the reset function has been then implemented, but apparently it is not there yet.
Since my GUI has many elements, I have written this small 'reset' function:
function GUI_default(tag,GUI_name)
% GUI_DEFAULT closes the current GUI instance and loads a new one.
% This is done in order to reinitialize the GUI parameters upon reset req
% Gabriella Panuccio - March 2019
current_GUI_instance = findobj('Type', 'Figure', 'Tag', tag);
close(current_GUI_instance)
feval(GUI_name)
end
I still have to closed and reopen the GUI, but this shows up as a brief blinking and does not force to user to do it manually. I hope this helps. Any more elegant solution?
Thanks.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!