필터 지우기
필터 지우기

Is it possible to detect when a gui moves to the background?

조회 수: 2 (최근 30일)
Nick
Nick 2013년 7월 25일
Hello all,
I use one main-gui for entering parameters when a sub-gui does calculations in the background.
Is it possible to detect when a gui moves to the background? And if so how do I program my sub-gui to reload variables when this happens?
An user has the ability to click on the minimize button or just click on a different gui.
When the user reopens the sub-gui I need the value’s to reset.
SimpleExample
%InputsMaingui
Ingreadients.Suger =3;
Ingreadients.flour = 1;
Open subgui
%show output:
Ingreadients.Suger =3;
Ingreadients.flour = 1;
*click on main window in the back
%change value's
Ingreadients.Suger =50;
Ingreadients.flour = 4;
*click on subgui *this is when it goes wrong and the gui uses the wrong data.
%show output
Ingreadients.Suger =3;
Ingreadients.flour = 1;
this happens cause the users dont "restart" the sub-gui so I want the sub-gui to restart everytime it has been to the background.
Or a method that forces an user to close the sub-gui before he/she can click anywere else. Like when an error message pops up you have to pres "ok" before you can continue any other operation
Regards, Nick

채택된 답변

Jan
Jan 2013년 7월 25일
편집: Jan 2013년 7월 26일
There is no documented method to achieve this, but an undocumented one:
FigH = gcf; drawnow;
jFrame = get(handle(FigH), 'JavaFrame');
% [EDITED]
try
jProx = jFrame.fFigureClient.getWindow;
catch
jProx = jFrame.fHG1Client.getWindow;
end
% [/EDITED]
set(jProx, 'WindowLostFocusCallback', {@figLostFocus, FigH});
function figLostFocus(jProx, EventData, FigH)
disp(clock) % Dummy for testing
Is is recommended to set this into a TRY/CATCH-Block and simply a useful error message, when it fails. The shown method might fail in future Matlab version as all undocumented features.
  댓글 수: 3
Jan
Jan 2013년 7월 26일
Please post which Matlab version you are using.
Do you mean:
figure('WindowStyle', 'modal')
See [EDITED] for a possibly working fallback. But remember that such errors are typical of undocumented methods.
Nick
Nick 2013년 7월 29일
I am using Matlab R2012b.
And indeed
figure('WindowStyle', 'modal')
is the code im looking for thanks allot!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by