GUI: dialog box delayed closing

5 Ansichten (letzte 30 Tage)
Tiberiu Tesileanu
Tiberiu Tesileanu am 11 Aug. 2016
I'm writing a GUI in which I need a dialog box to show up under certain conditions. The problem is that closing the dialog box briefly freezes the GUI, for anything from a second to 5-6 seconds. The smallest example I've come up with is the following:
function testdlg(varargin)
if nargin >= 1 && isnumeric(varargin{1})
n = varargin{1};
else
n = 9;
end
main = figure;
for i = 1:n
for j = 1:n
uicontrol('style', 'pushbutton', 'string', [int2str(i) ', ' int2str(j)], ...
'units', 'normalized', 'position', [0.101*(i-1) + 0.0 0.06*(j-1) + 0.4 0.1 0.05], ...
'callback', @displayDialog);
end
end
if ~any(strcmpi(varargin, 'noax'))
axes('units', 'normalized', 'position', [0 0.01 0.3 0.3]);
end
uiwait(main);
end
function displayDialog(varargin)
d = dialog('name', 'Dialog');
uiwait(d);
end
To describe this briefly: the function creates a grid (9x9 by default) of push buttons and a set of axes in a figure. A callback function is used so that clicking on any of the push buttons opens an empty dialog box.
What happens is the following. If the callback is never called (i.e., no button is clicked) and the figure is closed, everything is fast and there is no delay. If, however, a button is clicked and the dialog shows up, trying to close the dialog exhibits a long delay (about one second on my machine) before it actually closes. When attempting to close the figure after this, there is a similarly long delay for the figure to close. Any other GUI interaction is also delayed (so pushing a button to open another dialog box exhibits a one second delay as well).
Both the axes and the push buttons are important for this behavior. If you remove the axes (by calling testdlg noax), there is no delay. Reducing the number of buttons to a 5x5 grid or smaller (by calling, e.g., testdlg(5)) also gets rid of the delay. Since there is no noticeable delay in these cases, the delay I'm seeing can't just be due to the sum of the times it takes Matlab to handle one axes and the time it takes to handle >25 buttons: the delay I see is much longer than the sum of the delays I see when only the axes or only the buttons are displayed. So the effect must somehow be due to an interaction between the axes and the buttons.
Here's what I know from the tests I've done:
  • this is not due to the uiwait calls: removing them completely does not affect the delay
  • this is not due to the dialog box being modal (adding 'WindowStyle', 'normal' doesn't change anything)
  • it's also not due to it being a dialog box (using a second figure instead of a dialog exhibits the same behavior)
  • I've also tried setting all the axes options that are set to 'auto' by default to 'manual', with no success
  • this is also not due to giving callbacks to all the push buttons; removing the callbacks and using an extra button for opening the dialog exhibits the same delays
  • changing 'pushbutton' to 'popup' doesn't change the delay, though there is some change in the appearance of the dropdown menus after the dialog box is closed, which slowly reverts back to normal over a second or so
  • using 'text' controls instead of 'pushbutton' or 'popup' does get rid of the delay.
Has anyone else noticed anything like this before? Is Matlab trying to do some layout calculations whose complexity grows quickly when axes are surrounded by many buttons? Is there a way to stop it from doing what it's trying to do?
The profiler shows a lot of time spent in Matlab's default closereq function that's called when the user attempts to close a window. All this does is essentially delete the figure. However, if I set my own CloseRequestFcn and try to time the delete call, it takes very little time.
I'm pretty stumped at this point -- if this is a bug, it's a very confusing one. Any ideas are very welcome. I'm running R2015b (8.6.0.267246) on Mac OS 10.11.6, if that's of any help.
  4 Kommentare
Geoff Hayes
Geoff Hayes am 13 Aug. 2016
Even if I change the pushbutton to a popup, I don't observe any performance issues.
Tiberiu Tesileanu
Tiberiu Tesileanu am 19 Aug. 2016
Thanks for trying, Geoff! I wrote to MathWorks support to see whether this is a general issue with R2015b, or whether it's just my computer. They're still looking into it.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by