Reset GUI executable to initial state

17 visualizaciones (últimos 30 días)
Jared
Jared el 4 de Feb. de 2013
Respondida: Gabriella Panuccio el 5 de Mzo. de 2019
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.

Respuestas (4)

Image Analyst
Image Analyst el 4 de Feb. de 2013
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.

Voulgarakis Georgios
Voulgarakis Georgios el 4 de Feb. de 2013
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.
  1 comentario
Jared
Jared el 4 de Feb. de 2013
I am indeed using guide. Can you elaborate a little more on this? I don't want to save anything other that what is absolutely necessary for the program to run (whatever guide initially created). Any variables I create, I want to clear.

Iniciar sesión para comentar.


Voulgarakis Georgios
Voulgarakis Georgios el 5 de Feb. de 2013
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!

Gabriella Panuccio
Gabriella Panuccio el 5 de Mzo. de 2019
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.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by