Stop Figure from taking Focus!!
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (1)
Image Analyst
il 26 Dic 2018
0 voti
See this link MathWorks answer to stealing focus
3 Commenti
LeChat
il 17 Feb 2020
just read that and it is pretty cool, but I don't know how to use this if instead of plot I am doing viscircle.
Any suggestion? I posted a comment in the question you linked... Thank you!
Walter Roberson
il 17 Feb 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.
LeChat
il 17 Feb 2020
I answered you on the other discussion...
Categorie
Scopri di più su Performance and Memory in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!