1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
| function f = CreateDoubleProgressBar(maintitle, title1, title2, WindowStyle)
%% Help
% Function Calling syntax:
% Type 1: With Window style normal (default)
% handle = CreateDoubleProgressBar(maintitle, title1, title2)
% where maintitle is the title of the waitbar (string)
% title1 is the title of progress bar 1 (string)
% title2 is the title of progress bar 2 (string)
%
% Type 2: With Window style imposed
% handle = CreateDoubleProgressBar(maintitle, title1, title2, WindowStyle)
% where maintitle is the title of the waitbar (string)
% title1 is the title of progress bar 1 (string)
% title2 is the title of progress bar 2 (string)
% WindowStyle is either 'normal' or 'modal' (string)
%
%
% Created
% Date
if nargin < 3 || nargin > 4
error('Error in input arguments. Contact EMC Innovation Team for help');
end
if nargout ~= 1
error('Error in output arguments. Contact EMC Innovation Team for help');
end
if ~ischar(maintitle)
error('First argument (title of the waitbar) must be a string');
end
if ~ischar(title1)
error('Second argument (title of the progress bar 1) must be a string');
end
if ~ischar(title2)
error('Third argument (title of the progress bar 2) must be a string');
end
if nargin == 4 && ~ischar(WindowStyle)
error('Fourth argument (Window style) must be a string');
end
if nargin == 3
winstyle = 'normal';
elseif nargin == 4
winstyle = WindowStyle;
end
% Check if winstyle is in correct format
if strncmp(winstyle, 'modal', 5)
winstyle = 'modal';
elseif strncmp(winstyle, 'normal', 6)
winstyle = 'normal';
else
error('Fourth argument (Window style) must be either normal or modal');
end
% Create figure
oldRootUnits = get(0,'Units');
% Restore the Units safely
c = onCleanup(@()set(0, 'Units', oldRootUnits));
set(0, 'Units', 'points');
screenSize = get(0,'ScreenSize');
delete(c);
axFontSize=get(0,'FactoryAxesFontSize');
pointsPerPixel = 72/get(0,'ScreenPixelsPerInch');
width = 360 * pointsPerPixel;
height = 75 * pointsPerPixel * 2;
pos = [screenSize(3)/2-width/2 screenSize(4)/2-height/(2) width height];
f = figure(...
'Units', 'points', ...
'BusyAction', 'queue', ...
'Position', pos, ...
'Resize','off', ...
'CreateFcn','', ...
'NumberTitle','off', ...
'IntegerHandle','off', ...
'MenuBar', 'none', ...
'Tag','DoubleWaitbar',...
'Interruptible', 'off', ...
'Name', maintitle, ...
'WindowStyle', winstyle, ...
'DockControls', 'off', ...
'Visible','on');
% Create cancel button by default
vertMargin = 0;
cancelBtnHeight = 23 * pointsPerPixel;
cancelBtnWidth = 60 * pointsPerPixel;
newPos = pos;
vertMargin = vertMargin + cancelBtnHeight;
newPos(4) = newPos(4)+vertMargin;
callbackFcn = 'setappdata(gcbf,''canceling'',1)';
set( f, 'Position', newPos, 'CloseRequestFcn', callbackFcn );
cancelButt = uicontrol('Parent',f, ...
'Units','points', ...
'Callback', callbackFcn, ...
'ButtonDownFcn', callbackFcn', ...
'Enable','on', ...
'Interruptible','off', ...
'Position', [pos(3)-cancelBtnWidth*1.4, 7, ...
cancelBtnWidth, cancelBtnHeight], ...
'String','Cancel', ...
'Tag','TMWWaitbarCancelButton');
cancelBtnCreated = 1;
% Create axes
colormap([]);
axNorm=[.05 .3 .8 .15];
axPos1=axNorm.*[pos(3:4),pos(3:4)] + [0 vertMargin+30 0 0];
axPos2=axNorm.*[pos(3:4),pos(3:4)] + [0 vertMargin-15 0 0];
h1 = axes('Parent', f, ...
'XLim',[0 100],...
'YLim',[0 1],...
'Box','on', ...
'Units','Points',...
'FontSize', axFontSize,...
'Position',axPos1,...
'XTickMode','manual',...
'YTickMode','manual',...
'XTick',[],...
'YTick',[],...
'XTickLabelMode','manual',...
'XTickLabel',[],...
'YTickLabelMode','manual',...
'YTickLabel',[],...
'Visible', 'on', ...
'NextPlot', 'replace');
tHandle=get(h1,'title');
oldTitleUnits=get(tHandle,'Units');
set(tHandle,...
'Units', 'points',...
'String', title1,...
'Visible', 'on');
tExtent=get(tHandle,'Extent');
set(tHandle,'Units',oldTitleUnits);
titleHeight=tExtent(4)+axPos1(2)+axPos1(4)+5;
if titleHeight>pos(4)
pos(4)=titleHeight;
pos(2)=screenSize(4)/2-pos(4)/2;
figPosDirty=true;
else
figPosDirty=false;
end
if tExtent(3)>pos(3)*1.10;
pos(3)=min(tExtent(3)*1.10,screenSize(3));
pos(1)=screenSize(3)/2-pos(3)/2;
axPos1([1,3])=axNorm([1,3])*pos(3);
set(h1,'Position',axPos1);
figPosDirty=true;
end
h2 = axes('Parent', f, ...
'XLim',[0 100],...
'YLim',[0 1],...
'Box','on', ...
'Units','Points',...
'FontSize', axFontSize,...
'Position',axPos2,...
'XTickMode','manual',...
'YTickMode','manual',...
'XTick',[],...
'YTick',[],...
'XTickLabelMode','manual',...
'XTickLabel',[],...
'YTickLabelMode','manual',...
'YTickLabel',[],...
'Visible', 'on');
tHandle=get(h2,'title');
oldTitleUnits=get(tHandle,'Units');
set(tHandle,...
'Units', 'points',...
'String', title2,...
'Visible', 'on');
tExtent=get(tHandle,'Extent');
set(tHandle,'Units',oldTitleUnits);
titleHeight=tExtent(4)+axPos1(2)+axPos1(4)+5;
if titleHeight>pos(4)
pos(4)=titleHeight;
pos(2)=screenSize(4)/2-pos(4)/2;
figPosDirty=true;
else
figPosDirty=false;
end
if tExtent(3)>pos(3)*1.10;
pos(3)=min(tExtent(3)*1.10,screenSize(3));
pos(1)=screenSize(3)/2-pos(3)/2;
axPos2([1,3])=axNorm([1,3])*pos(3);
set(h2,'Position',axPos2);
figPosDirty=true;
end
if figPosDirty
set(f,'Position',pos);
end
% Create a patch in each axis with 0 value
xpatch = [0 0 0 0];
ypatch = [0 0 1 1];
p1 = patch(xpatch,ypatch,'r', 'Parent', h1,...
'EdgeColor','r','EraseMode','none');
drawnow;
setappdata(p1,'waitbar__data__',0)
p2 = patch(xpatch,ypatch,'r', 'Parent', h2,...
'EdgeColor','r','EraseMode','none');
drawnow;
setappdata(p2,'waitbar__data__',0)
% Create a text box to display the progress value
color1 = 'k'; % Black
color2 = 'w'; % white
backgroundcolor = get(f, 'color');
textPos1 = [axPos1(1)+ axPos1(3) + 80, axPos1(2)+26, 50, 20];
h3 = uicontrol('Parent', f, ...
'style','text',...
'string','0 %', ...
'FontSize', axFontSize,...
'Position', textPos1, ...
'Visible', 'on', ...
'Tag', 'ProgText1', ...
'BackgroundColor', backgroundcolor);
textPos2 = [axPos2(1)+ axPos2(3) + 80, axPos2(2)+10, 50, 20];
h4 = uicontrol('Parent', f, ...
'style','text',...
'string','0 %', ...
'FontSize', axFontSize,...
'Position', textPos2, ...
'Visible', 'on', ...
'Tag', 'ProgText2', ...
'BackgroundColor', backgroundcolor);
end |
Partager