Stop Figure from taking Focus!!
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Matthew Cribb
le 25 Déc 2018
Commenté : LeChat
le 17 Fév 2020
I have created a function that repeatedly display a uitable (in a figure) that is looped every 10 seconds using a timer object. TheI global TASK variable in the function is continually being changed by a main function (not shown). The function displays information about tasks being performed and who (in a group) is performing what tasks. TASK is a global structure variable in the main program's data, that continually changes (what this function is built to display).
My question: How do I keep figure(2) from taking focus every time it loops??? I just want it to update in the background, and not pop up evey time or make my computer switch window to the figure! Seems simple. I'v tried two examples, listed below my function. The first is closest to what i want to happen, but havnt figured out how to adapt it to mine. Please help! Thank you!
%DISPLAY FUNCTION for main program:
function displayCurrent()
global a; global TASK;
if a==0
return; %If program has ended, stop updating the Display
end
%Create and Display Table (OUTPUT):
memberNames = {TASK(1).name,TASK(2).name,TASK(3).name}
tasktime = {TASK(1).hh_mm_ss,TASK(2).hh_mm_ss,TASK(3).hh_mm_ss};
memberIDs = {num2str(TASK(1).grpTsk_members), num2str(TASK(2).grpTsk_members), num2str(TASK(3).grpTsk_members)};
tasks = {TASK(1).title, TASK(2).title, TASK(3).title};
T = table(memberNames', tasktime', memberIDs', 'RowNames', tasks');
T.Properties.Description = 'DAILY TASK LIST';
T.Properties.VariableNames = {'AllMembers' 'TaskTime' 'CurrentIDs'};
%sfigure(figure(2)) %Does not work, or not using correctly
%h1 = figure(2);set(gcf,'Visible', 'off'); %Just makes figure go away compeltely...
figure(2) %STEALS FOCUS! HOW TO STOP????
UIT = uitable('Data',T{:,:},'ColumnName',T.Properties.VariableNames,...
'RowName',T.Properties.RowNames,'Units', 'Normalized', 'Position',[0, 0, 1, 1],'ColumnWidth', {150,100,70},'FontSize', 15);
%Looping timer-
t=timer; t.StartDelay = 10; t.TimerFcn = @(~,~) displayCurrent(); start(t)%Loops DISPLAY function
disp('');
end
I have tried many MATLAB resources. Here are a few I tried to implement with no luck:
1) The closest in effect to what want:
function example_focusin
T = timer('timerfcn',@updatePlot,'period',5,'executionmode','fixedrate','taskstoexecute',10);
figure; h = plot(rand(1,10));start(T);
function updatePlot(src,evt)
set(h,'ydata',rand(1,10));
end
end
AND
2) Couldnt get to work:
function h = sfigure(h)
% SFIGURE Create figure window (minus annoying focus-theft)... Usage is identical to figure. Daniel Eaton, 2005
if nargin>=1
if ishandle(h)
set(0, 'CurrentFigure', h);
else h = figure(h); end
else h = figure; end
end
0 commentaires
Réponse acceptée
Walter Roberson
le 26 Déc 2018
Do not keep calling figure and making new uicontrol . create the objects ahead of time and update the appropriate properties .
1 commentaire
Plus de réponses (1)
Image Analyst
le 26 Déc 2018
See this link MathWorks answer to stealing focus
3 commentaires
Walter Roberson
le 17 Fév 2020
You can record the handle returned by viscircles. It wil be an hggroup object, which has a Children property, and there will be one Chart Line object for each circle that is drawn. You can access those children and update their XData and YData properties.
Voir également
Catégories
En savoir plus sur Graphics Object Properties dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!