How to monitor background queue of App Designer `uifigure` (e.g. its initialisation), which can be waited with `drawnow`?

23 views (last 30 days)
Hi,
It appears the background queue of a uifigure finishes much later than its appearance. For example:
profile on
f=uifigure('Visible','on','WindowState',"maximized");
a1=uiaxes(f); % use `uiaxes` to make it much slower
% drawnow
f.Position
delete(f);
profile off
profile viewer
will have different f.Position output as well as profile "total time" with/without the drawnow. This asynchronous behaviour allows some early input from the user before all background tasks finsih, I guess.
I wonder what is the method to get the "queue state" of a uifigure? As it can be walled by drawnow, I assume this is possible?
My ultimate goals are, for example, to have a uilamp to indicate the busy/idle of background queues from operations like "moving a ROI on a uiaxes", as well as knowing the end of the initialisation without using drawnow to wait.
Cheers

Answers (1)

Suraj Kumar
Suraj Kumar on 26 Mar 2024 at 11:33
Hi Tianyu,
MATLAB does not offer a direct built-in function to inquire about the "queue state" of a “uifigure”, but as a workaround you can attach event listeners to specific events “MovingROI”, “ROIMoved” that can serve as markers for the start and end of significant operations.
You can refer the below code snippet which features a “uilamp” function that changes colour from green (idle) to red (busy) based on the ROI's movement, using event listeners to track the start and completion of this interaction:
f = uifigure('Position', [100, 100, 400, 400]);
a1 = uiaxes(f, 'Position', [100, 100, 200, 200]);
roi = drawrectangle(a1);
uil = uilamp(f, 'Position', [20, 20, 20, 20], 'Color', 'green'); % Start as 'idle'
% Listener for starting the move
addlistener(roi, 'MovingROI', @(src, evt) set(uil, 'Color', 'red')); % Busy
% Listener for move completion
addlistener(roi, 'ROIMoved', @(src, evt) set(uil, 'Color', 'green')); % Idle
You can refer the figures shown below:
To know more about “uilamp function and event listeners, please refer to the documentations below:
  1. https://www.mathworks.com/help/matlab/ref/uilamp.html
  2. https://www.mathworks.com/help/matlab/matlab_oop/learning-to-use-events-and-listeners.html#bu6lzcw
Hope this helps!

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!