uigetfile breaks modality in uifigures

I have an app with a main uifigure that does a lot of things. Let's call it the workbench. The workbench calls another uifigure which has its WindowStyle set to 'modal'. This is for input that is required by one of workbench's many steps. Let's call this 2nd uifigure the Filelist.
Normally when Filelist is up, the user cannot access workbench at all. This is good and normal behavior. However, Filelist calls uigetfile(). After the uigetfile dialog goes away, there are two MatLab bugs that occur. The first is minor - some other window gets brought forward - and is easily fixed by calling figure() to bring the Filelist uifigure to the forefront. (See discussion in https://www.mathworks.com/matlabcentral/answers/296305-appdesigner-window-ends-up-in-background-after-uigetfile )
The 2nd bug is not minor. Modality has been broken. The user can now click on workbench while Filelist is open. Filelist is still in control (there's a waitfor() blocking execution) but the user can now interact with workbench's entire UI. The callback in workbench which called Filelist is STILL in operation - it has not been returned to yet from Filelist.
Before the call to uigetfile access to the workbench was blocked. It needs to continue being blocked because the 2nd uifigure is still prompting the user for input. However it's now also possible for the supposedly modal Filelist uifigure to get lost in the background and for the user to continue working with workbench as if the waitfor() had ended and execution had returned. Except that it hasn't returned.
How do I stop this from happening?
Note that I've tried using uiwait() instead of waitfor() with the same result. I've also inspected the Filelist's uifigure object and it still has WindowStyle = 'modal'. I've also tried changing and resetting WindowStyle to re-engage modality. No dice.

Answers (1)

What's Matlab version are you using?! I just test it in R2022b and it's working fine. See app attached.
% app2 button callback
[fileName, filePath] = uigetfile;
figure(app.CallingApp.UIFigure)
figure(app.UIFigure)
(a) app1 normal, app2 modal and an open uigetfiles window:
(b) app1 normal and app2 still a modal:

5 Comments

I am on R2020b.
In your test, once the uigetfile window closes, what happens when you click on app1 while app2 is still open?
Nothing. App1 is behind app2, a modal window. In fact the windows makes a sound.
It must be a bug from this R2020b release…
Excellent! Thank you for checking. It does sound like a bug in 2020b.
I wonder which version it got fixed in and whether Mathworks will roll that fix back? My client requires I support 2020b.
Check if you are using R2020b Update 8 released on Aug 22, 2022.
https://www.mathworks.com/content/dam/mathworks/mathworks-dot-com/support/updates/r2020b/r2020b-updates-release-notes.pdf
Yup. Already up to date. Oh well.

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2020b

Asked:

on 29 Nov 2022

Commented:

on 8 Dec 2022

Community Treasure Hunt

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

Start Hunting!