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

7 views (last 30 days)
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!

Answers (2)

Cameron B
Cameron B on 13 Jan 2020
Edited: Cameron B on 13 Jan 2020
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 on 25 Jan 2020
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!

Categories

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

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!