forbid the switch of tab group in app designer while running a calculation

1 次查看(过去 30 天)
How can I forbid user to switch to another tab in a tab group in app designer?
I have an implementation with multiple tabs dedicated to different calculations. When running a calculation in one specific tab, which takes a couple of minutes, the user is still capable of switching to a different tab, which sometimes can screw up the calculation. How can I forbid the user to do such operation?
thanks!

回答(2 个)

Cameron B
Cameron B 2020-1-13
编辑:Cameron B 2020-1-13
It doesn't look as if I can attach my mlapp file so I'll paste the relevant code here and let you put it together. When you hit the button marked "Count to 10" it will begin counting and will not allow the user to change tabs until the callback function is complete.Once complete, it will assign a value of 1 to IsFinished which allows the tabs to be changed.
%i don't know why properties and methods aren't shown as blue, but they should be. not a big deal
properties (Access = private)
IsFinished = 1; %allows tabs to be changed at beginning
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: Countto10Button
function Countto10ButtonPushed(app, event)
app.IsFinished = 0; %stops tabs from being changed
app.Countto10Button.BackgroundColor = 'r';
for bb = 1:10
app.EditField.Value = bb;
pause(1)
end
app.IsFinished = 1; %allows tab to be changed
app.Countto10Button.BackgroundColor = 'g';
end
% Selection change function: TabGroup
function TabGroupSelectionChanged(app, event)
app.TabGroup.BusyAction = 'Cancel';
if app.IsFinished == 1 %don't run this if the Count button isn't pressed.
return
end
%if the selected tab is anything other than 'Stay', then run this
if ~strcmpi(app.TabGroup.SelectedTab.Title,'Stay')
app.TabGroup.SelectedTab = app.TabGroup.Children(1);
end
end
end

Yang Yang
Yang Yang 2020-1-25
thank you very much Cameron B!
I ended up not having to using this feature by removing some of the functionality.
But your solution is great and will be useful in future!

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by