Kobi Guetta
Kobi Guetta

Reputation: 105

matlab gui - callling the same gui screen

I'm trying to do in matlab, GUI that the the user enters points as input and connection between them.

I have 5 matlab files - screen1.m, screen2.m, screen3.m, screen4.m, globalParams.m

in globalParams I have global params so I can use them from screen GUI to screen GUI. in screen1 the user enters the number of nodes(for example 5). when he press the Next button the callback function calls "screen2();". in screen2.m the user enters the (x,y) coordiante and when he press the Next button the callback function calls "screen3();".

Now I'm asking him to fill the connection between Node i to Node j.(he need to fill the numbers of node i and j). if there is only 1 connection he will press the Finish button, and the callback function will call "screen4(); and everthing is good. Else(there is more then 1 connection) he press the Next button and the callback function calls "screen3();". So when we have more than 1 connection I have problem calling screen3 again...

Also is there some way when I'm calling the next screen to close the last screen? because when we find a way to call screen3 again and again, there will be a lot of GUI open and it can confuse and annoy the user.

some code:

in screen1, the next button:

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
screen2();

in screen2, the next button:

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

screen3();

in screen3, the next button and then the finish button:

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
screen3();

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
screen4();

in screen3 how I'm using the connection between 2 nodes:

function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double

global hopsMatrix;
i = str2num(get(handles.edit2, 'string'));
j = str2num(get(handles.edit1, 'string'));
hopsMatrix(i,j) = 1;

Upvotes: 3

Views: 145

Answers (1)

scenia
scenia

Reputation: 1629

I wouldn't call screen3() again. You can just clear the edit fields, display a success message and make him go again.

Move your data evaluation (the part you currently have in the edit2_Callback) to the "Next" button, then after you have the data,

set(handles.edit1, 'String', '');
set(handles.edit2, 'String', '');
set(handles.text1, 'String', sprintf('Connection (%d, %d) was added.',i,j));

Don't forget to add a static text field somewhere to display the message (it should automatically receive the handle text1).

This way, the user can add as many nodes as he wants, click "Next" to clear the fields and add another connection, or click "Finish" to go on.
There's no need to add the connection to your data in the edit2 Callback already (and this also brings some problems, for example if the user enters the second point first or notices an error in the first point when he has already entered something in the second edit field).


As for deleting, each GUI has a handle to its parent figure in handles.figure1 which you can simply close before calling the next one. So instead of just screen2();, write

close(handles.figure1);
screen2();

Upvotes: 1

Related Questions