Preventing focus theft while running matlab from the command line and creating figures

조회 수: 3 (최근 30일)
There have been several posts on this subject such as this thread , and proposed solutions such as the program sfigure, but nothing works for me. I'm running R2016b from linux, and opening matlab with the flags
-nosplash -nodesktop
When I run the following code, using @Walter Roberson's fix proposed in the first link
close all;
figure(1);
set(0,'CurrentFigure',1);
plot(1:10);
or using the program `sfigure` suggested in the second link
close all;
sfigure(1);
plot(1:10);
the focus thief remains as active as ever. I would so love to put this thief away for life.
Thanks for any suggestions

답변 (1개)

Walter Roberson
Walter Roberson 2016년 12월 27일
Creating a figure always gives it focus. The discussion in the other thread is about how to reduce the other circumstances under which the focus might get stolen.
If you set the new figure Visible off and drawnow() almost immediately after you create the figure then you reduce the time during which the focus is at risk. The focus will mostly go back to where it was when you make the new figure visible off, but not necessarily completely reliably. You can reduce the window even more by creating it with visible off: the documentation implies that it would still be temporarily made the current figure in that case, but it can be difficult to tell the cases apart.
  댓글 수: 1
Leo Simon
Leo Simon 2016년 12월 27일
Thanks Walter, I'm afraid I don't understand the suggestion. I tried the following command, which I thought might be what you were suggesting:
h = figure('Visible','off');drawnow(); plot(1:10); h.Visible='on';
but the focus was still lost. Is there some reason why matlab doesn't provide us with some way to prevent loss of focus? It's very hard for me to come up with some reason why this protocol should be hard-wired?

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

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by