Azzera filtri
Azzera filtri

GUIDE slider callback within another running callback won't update handles altered during the slider callback

4 visualizzazioni (ultimi 30 giorni)
Hi everyone,
i am currently working on a GUI for a program i have written in Matlab and have come across a problem where i just can't figure out how to resolve it. Researches didn't really help for my specific case. I hope someone here can help me out.
So basically, my GUI has one start pushbutton, when pressed, my program will be started in the pushbutton_Callback. The .m-file contains a for-loop to subsequently display video frames on a axes in the GUI. So it basically looks like a video player, and the code processes some information on the individual frames and displays the results on the frames right away. Now i am trying to add a slide bar, which the user can operate on, even when the pushbutton_Callback is still running. What i am looking for is, when the slide bar is operated during pushbutton_Callback, the slider_Callback should output a handle called handles.slider_moved (value = 1) and the pushbutton_Callback picks up this changed handle and terminates its execution by the use of return. Now the problem is, that the handle slider_moved doesn't get updated after the slider_Callback has finished running (local scope within the slider_Callback), so the "if handles.slider_moved" condition is never met in the pushbutton_Callback(see belowing example code):
function pushbutton_Callback(hObject,eventdata,handles)
handles.slider_moved = 0;
for i = currentFrame:totalFrame
...
if handles.slider_moved
return;
end
end
function slider_Callback(hObject,eventdata,handles)
handles.slider_moved = 1;
calculate frame number corresponding to the new slider value...
guidata(hObject,handles)
I tried
function handles = slider_Callback(hObject,eventdata,handles)
and it didn't change anything.
What i want in the end is the following:
when slide bar is moved during video play (meaning pushbutton_Callback still running), play the video starting from the frame/time corresponding to the new position of the slider. And terminating the current pushbutton_Callback is the first step in doing so.
I'm grateful for any kind of advices. If there are better methods to achieve the end goal, please enlighten me!
Thanks alot in advance.
  2 Commenti
Adam
Adam il 25 Lug 2017
Modificato: Adam il 25 Lug 2017
The handles are being updated in the GUI, the problem is that the handles in the pushbutton callback are local, not the handles in the slider callback.
You may be able to fix it just by putting
for i = currentFrame:totalFrame
...
handles = guidata( hObject )
if handles.slider_moved
return;
end
end
in your pushbutton callback but if you are also adding things to handles in the pushbutton callback that will not work out either as they will just get lost.
In terms of 'better' methods, I would favour using classes and listeners to achieve this kind of thing, but that is too complicated to explain right now!
Jian Zhou
Jian Zhou il 25 Lug 2017
Modificato: Jian Zhou il 25 Lug 2017
Thank you for your quick reply. I tried your suggested solution with updating the handles in the pushbutton_Callback, the callback still doesn't terminate after operating on the slide bar. Maybe i should try out the "class" and "listener" method you mentioned. Thanks anyway.
NOTE: It indeed updated the handles.slidebar_moved in the pushbutton_Callback! The problem seems to be another one, why the return command is not working. Thank you!

Accedi per commentare.

Risposta accettata

Jan
Jan il 25 Lug 2017
Modificato: Jan il 25 Lug 2017
function handles = slider_Callback(hObject,eventdata,handles)
No, callbacks do not have output arguments.
If you change the contents of the handles struct, update it by retrieving it from the fuigure inside the loop:
handles.slider_moved = 0;
for i = currentFrame:totalFrame
...
handles = guidata(hObject); % Get current value
if handles.slider_moved
return;
end
end
Note that each function has its own copy of the handles struct, until you reload the value from the figure again.
  3 Commenti
Adam
Adam il 25 Lug 2017
You should never be manually calling a callback from somewhere. Put the code into a separate function to be called from multiple places if you wish to do this, but you shouldn't having to crowbar in the input arguments that a callback wants rather than the arguments your actual code wants.
Jian Zhou
Jian Zhou il 25 Lug 2017
Do you mean by "manually calling a callback" the process of clicking on the slides bar and then call the pushbutton_Callback? Otherwise I don't understand where I manually called any callbacks. Is it bad practice to call an other callback function within a callback function? Maybe I should start doing some research in listener, looks like it's a much better choice for this kind of GUI feature

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by