App Designer - Code that runs whenever a callback function is executed

조회 수: 4 (최근 30일)
Gwendal Marrec
Gwendal Marrec 2022년 4월 29일
편집: Gwendal Marrec 2022년 5월 3일
Hello,
I am working on an App Designer app.
I have dozens of callback functions in my app and and all of them do computations that take a long time. For now, they all look like this :
function myfunction(app, event)
set(app.UIFigure, 'pointer', 'watch')
drawnow;
%some code
set(app.UIFigure, 'pointer', 'arrow')
drawnow;
end
I would like to know if it is possible to have a code that runs whenever a callback function is executed, so that I only write these lines once.
Thanks in advance,
Gwendal

답변 (1개)

Kevin Holly
Kevin Holly 2022년 4월 29일
편집: Kevin Holly 2022년 4월 29일
You can create a function/script MATLAB file that you can call from MATLAB. Alternatively, you can create a function within the app that can be called by multiple callbacks. You can insert a function within App Designer when it is in code view by clicking the "Function" button on the toolstrip under the Editor tab. You can send all the property variables within the app to the function's workspace by using "app" as the input.
foo(app)
  댓글 수: 1
Gwendal Marrec
Gwendal Marrec 2022년 5월 3일
편집: Gwendal Marrec 2022년 5월 3일
Hello, thank you for your answer.
I have coded this function :
methods (Access = public)
function pointer_change(app)
if app.UIFigure.Pointer == 'arrow'
set(app.UIFigure, 'pointer', 'watch');
else
set(app.UIFigure, 'pointer', 'arrow');
end
drawnow()
end
end
So now, all my functions look like this :
function myfunction(app, event)
pointer_change(app);
%some code
pointer_change(app);
end
It looks better than before, but a problem i didn't mention in my original post still persists. When I change the pointer from 'watch' to 'arrow' (which corresponds to the second call of pointer_change), the pointer is not updated until I move the mouse, as if the drawnow statement was not executed. As soon as I move the mouse, the pointer becomes an arrow.
Have you got any idea why ? Maybe this needs a new post ?
Many thanks,
Gwendal

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by