Reset GUI executable to initial state

17 ビュー (過去 30 日間)
Jared
Jared 2013 年 2 月 4 日
回答済み: Gabriella Panuccio 2019 年 3 月 5 日
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.

回答 (4 件)

Image Analyst
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.

Voulgarakis Georgios
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.
  1 件のコメント
Jared
Jared 2013 年 2 月 4 日
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.

サインインしてコメントする。


Voulgarakis Georgios
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!

Gabriella Panuccio
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.

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by