0

I'm currently creating a GUI using mathlab GUIDE. Since the GUI is very slow I'd like to add an edit_text uicontrol in order to show whether the GUI is running or not.

For instance I have a push_button that changes the plot in an axes. When the user click on this button the GUI takes several seconds to perform the new plot. What I want to do is setting the edit_text with the string 'running' as soon as the button was pressed. When the callback is done and the plot plotted I'd like to set the edit_text with another string : 'ready'.

I used the following code :

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

set(handles.edit_text,'String','Running...');
%a bunch of code...
set(handles.edit_text,'String','Ready.');
guidata(hObject,handles);

I hoped that once the callback is called, the GUI would display 'running...' on my edit_text. Apparently I was wrong. When running the GUI and pressing the push_button the plot changes but the edit_text remains the same.

Then I tried something else using the ButtonDownFcn callback. My idea was that the latter callback would be executed before the actual callback (written above). Here is the code :

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

set(handles.edit_text,'String','Running...');
guidata(hObject,handles);

The problem is that the ButtonDownFcn callback isn't executed every time. As GUIDE says about the latter callback :

% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over str22.

Obviously I want my push_button to be enabled, otherwise it won't work the way I want. So I don't know what else to try.

Has someone any idea how I could manage to do that ?

ChocoPouce
  • 173
  • 7
  • In your original attempt, `edit_text` should indeed display "running..." when the callback starts. I would try to investigate why this is not happening. Perhaps a the command `drawnow`, after the first `set`, would force the GUI to redraw itself and update the `edit_text` string. – Sam Roberts Jun 12 '13 at 09:56
  • @SamRoberts It worked. Thank you very much. Well, it was pretty simple after all... – ChocoPouce Jun 12 '13 at 10:01

1 Answers1

1

You could try doing

set(handles.edit_text,'String','Running...');
drawnow;
%a bunch of code...

The GUI might not be updated until you get to

set(handles.edit_text,'String','Ready.');

So forcing it to update with drawnow might work for you.

Hugh Nolan
  • 2,508
  • 13
  • 15