App Designer - Pointer update issue

Hello,
I am working on an App Designer app.
I have coded the function below. It is supposed to change the pointer to watch if it is an arrow or to arrow if it is a watch.
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
All my callbacks look like this :
function callback1(app, event)
pointer_change(app);
%some code that takes a long time to run so I need to change the cursor
%to indicate that matlab is busy running
pointer_change(app);
end
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.
Does anyone know why ?
Many thanks,
Gwendal

댓글 수: 6

Geoff Hayes
Geoff Hayes 2022년 5월 5일
@Gwendal Marrec - how or when is your callback1 method called? If I put the code from pointer_change into a button callback, then the mouse pointer changes immediately (without the need even for the drawnow.
Gwendal Marrec
Gwendal Marrec 2022년 5월 6일
@Geoff Hayes, callback1 is called when pushing a button. My app will contain about 100 callbacks so I would like to have a clean code by using a function to change the pointer appearance. At first, I put the code from pointer_change into every callbacks but the problem was the same : the pointer was not updated until I moved the mouse.
it works well to change from 'arrow' to 'watch' but the opposite way does not work properly.
@Gwendal Marrec - it isn't clear to me why the pointer doesn't immediately change. I'm using R2021a and the pointer does change without the need to move the mouse pointer
function ButtonPushed(app, event)
if app.UIFigure.Pointer == 'arrow'
set(app.UIFigure, 'pointer','watch');
else
set(app.UIFigure, 'pointer','arrow');
end
for k = 1:30
pause(1);
end
if app.UIFigure.Pointer == 'arrow'
set(app.UIFigure, 'pointer','watch');
else
set(app.UIFigure, 'pointer','arrow');
end
end
The above automatically changes the mouse pointer after the simulated work (30 seconds) completes.
Geoff Hayes
Geoff Hayes 2022년 6월 13일
@Gwendal Marrec - can you provide a small working example that exhibits this behaviour?
Here is a callback function where i call pointer_chang(app) before and after the calculations.
function N_Parcourir1Pushed(app, event)
pointer_change(app);
[filename1,path1] = uigetfile({'*.lim'},'Choose file',app.curpath);
if filename1~=0
app.curpath = path1;
app.N_FieldFichierOriginal.Value = filename1;
app.N_original_file = [path1,filename1];
[app.N_freq1,app.N_gain1] = normalisation(app.UIFigure,[path1,filename1]);
end
pointer_change(app);
end
This is what pointer_change(app) looks like :
function pointer_change(app)
if strcmp(app.UIFigure.Pointer,'arrow')
set(app.UIFigure, 'pointer','watch');
'a'
else
set(app.UIFigure, 'pointer','arrow');
'z'
end
end
When I run my app, I get a 'a' and a 'z' in my command window. The pointer effectively changes from 'arrow' to 'watch' during the first call of the function, but then it does not return to 'arrow' during the second call of the function (until I move the cursor), despite printing the 'z'.
Geoff Hayes
Geoff Hayes 2022년 8월 15일
@Gwendal Marrec - could you attach a simplified version of your GUI that exhibits this behaviour?

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

답변 (4개)

ryugasen
ryugasen 2022년 8월 25일

2 개 추천

I was having the same issue with only one situation, and upon looking on your example, I think I found the culprit. It's related to opening a file (I have a pointer change at two different callback functions, it works perfectly in one where it does a calculation, while in the one that loads an excel file through readmatrix it doesn't work until I move the cursor).
Interestingly, I found that if the app is maximised, it works perfectly regardless. I suspect it has something to do with the window of the app becoming out of focus when you go and load a file (and only upon the moving the mouse does Windows realise the app is still the window of focus). If the app is maximising, I guess Windows always treats it as the focus.
So yeah, the solution is to keep the app maximised, or if someone with more tech knowledge knows how to keep the app in focus even while Windows browses and opens a different file in the background, then that would be the best solution
Veronica Taurino
Veronica Taurino 2022년 5월 10일

1 개 추천

I have the same problem. The pointer does not change until I move the cursor. I am working in the app designer, each callback has something like:
function callback1(app, event)
set(app.UIFigure, 'Pointer','watch')
% do stuff...
set(app.UIFigure, 'Pointer','arrow')
end

댓글 수: 5

Gwendal Marrec
Gwendal Marrec 2022년 5월 11일
We have the exact same issue. Have you tried to put drawnow ?
Veronica Taurino
Veronica Taurino 2022년 5월 11일
Yes I did, but it didn't work
Geoff Hayes
Geoff Hayes 2022년 5월 11일
Does the same issue occur with the sample code I provided above? Note that I'm using a Macbook...not sure which OS either of you are using.
Gwendal Marrec
Gwendal Marrec 2022년 5월 11일
편집: Gwendal Marrec 2022년 5월 11일
Your sample code works well for me. Really intriguing.
I'm on Windows 10 20H2.
Veronica Taurino
Veronica Taurino 2023년 5월 30일
편집: Veronica Taurino 2023년 5월 30일
after a year, I still have the same issue.
I solved it programatically moving a bit the cursor at the end of the process:
hroot=groot;
pp=get(hroot,'PointerLocation'); % current cursor position
set(hroot,'PointerLocation',[pp(1)+10 ,pp(2)+10 ]); %slightly moving cursor

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

Gwendal Marrec
Gwendal Marrec 2022년 6월 13일

0 개 추천

Up. I've tried a couple of things but none of them worked out. Whenever I call another function to handle the pointer change, it never returns to 'arrow' until I move the mouse.
Veronica Taurino
Veronica Taurino 2023년 5월 30일

0 개 추천

after a year, I still have the same issue.
I solved it programatically, moving a bit the cursor at the end of the process:
hroot=groot;
pp=get(hroot,'PointerLocation'); % current cursor position
set(hroot,'PointerLocation',[pp(1)+10 ,pp(2)+10]); %slightly moving cursor

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2022년 5월 5일

답변:

2023년 5월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by