lock first app if second is running

14 ビュー (過去 30 日間)
Tomas Girasek
Tomas Girasek 2019 年 4 月 26 日
回答済み: Itshak 2024 年 1 月 30 日
Hello,
how can i lock first app if secod is running.
I have the main app and one app which ask some input data from oprator. And i would like to lock main app during time when operator write some data to second one app. It should be locked, visibility is not solutions....
Thanks.
Tomas
  3 件のコメント
Jan
Jan 2019 年 4 月 29 日
編集済み: Jan 2019 年 5 月 3 日
[MOVED from section for answers] Tomas Girasek wrote:
Hello,
The app is aplication created in appdesigner. By first aplication (main app) is opened second one aplication where "operator" (somebody wo will works wit this aplication) will write some neccesary data. During this time i would like to lock the main app. Lock - in my case meaning disable whole main aplication until second one is running.
Tomas
Oliver Schön
Oliver Schön 2019 年 8 月 14 日
Hi,
same problem here but found an alternative solution:
  • add an image component to overlay the complete main app window, e.g. app.BlankWindow, set ScaleMethod to 'strech'
  • set its properties Visible and Enable to 'off' on creation
  • in the main app StartupFcn initialise app.BlankWindow.ImageSource = ones(1,1,3)*0.5 (i.e. single pixel grey image)
  • when starting a dialog box set the image Visible and Enable to 'on', now no clicks go through to the main app (unless you add an ImageClickedFcn callback)
  • when the dialog exits set the image properties back to 'off'
This mimics the uiconfirm dialog function except that it does not restrict the dialog window to the frame of the main app.
Cheers,
Oliver.

サインインしてコメントする。

採用された回答

Jan
Jan 2019 年 4 月 29 日
編集済み: Jan 2019 年 8 月 15 日
You can use waitfor in the main function and provide the handle of the uifigure.
[EDITED] I assume, that https://www.mathworks.com/matlabcentral/fileexchange/15895-enable-disable-entire-figure-window works with figures only, not with uifigures. I did not test https://www.mathworks.com/matlabcentral/fileexchange/31437-windowapi with uifigures also, and it would run under Windows only:
% [EDITED: works with uifigure also, tested in R2018b]
H = uifigure;
WindowAPI(H, 'enable', 0);
pause(10)
WindowAPI(H, 'enable', 1);
You can disable all elements of the uifigure manually: Store a collection of all handles you want to disable in aa variable. Then set the 'Enable' property to 'off' and add a message, that the window is locked until the other is finished.
Actually using uiwait should work suffciently, if the other window is 'modal'. Unfortunately I do not see a way to create a modal uifigure. But if the 2nd GUI is opened through a callback of the 1st GUI, setting teh 'Interruptible' property of the 1st GUI to 'off' and the 'BusyAction' to 'cancel' should ignore all interactions with the 1st GUI, when it waits to waitfor inside the callback.
Another idea is to set a flag in the GUI's UserData, which is checked in each callback, as long as the 2nd GUI is open:
function CallbackOf1StGUI(H, EventData)
GUI1 = ancestor(H, 'uifigure'); % Does this work?
if GUI1.UserData.Locked
return;
end
GUI2 = OpenGUI2();
GUI1.UserData.Locked = true;
waitfor(GUI2);
GUI1.UserData.Locked = false;
end
Add the test of the locked GUI in each callback.

その他の回答 (1 件)

Itshak
Itshak 2024 年 1 月 30 日
For anyone still looking for a solution in 2024. The component browser panel has an option to set the UIFigure Window Style to modal. Upon setting this value if a secondary app is launched from a primary modal app, the primary modal app will be uninteractable as long as the second one is open.

カテゴリ

Help Center および File ExchangeDevelop uifigure-Based Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by