@@ -97,8 +97,9 @@ function fontWeight(uiElement, weight)
9797 ' mlapptools:getWebWindow:NotUIFigure' ,...
9898 ' The provided window handle is not of a UIFigure.' );
9999
100+ to = mlapptools .getTimeout(hUIFig );
100101 tic
101- while true && (toc < mlapptools . QUERY_TIMEOUT )
102+ while true && (toc < to )
102103 try
103104 hController = struct(struct(hUIFig ).Controller);
104105 % Check for Controller version:
@@ -120,24 +121,24 @@ function fontWeight(uiElement, weight)
120121 end
121122 mlapptools .toggleWarnings(' on' )
122123
123- if toc >= mlapptools . QUERY_TIMEOUT
124+ if toc >= to
124125 msgID = ' mlapptools:getWidgetID:QueryTimeout' ;
125126 error(msgID , ...
126127 ' WidgetID query timed out after %u seconds, UI needs more time to load' , ...
127- mlapptools . QUERY_TIMEOUT );
128+ to );
128129 end
129130 end % getWebWindow
130131
131- function varargout = getWidgetInfo(hUIFig ,verbose )
132+ function varargout = getWidgetInfo(hUIFig , verboseFlag )
132133 % A method for gathering information about dijit widgets.
133134
134135 %% Handle missing inputs:
135136 if nargin < 1 || isempty(hUIFig )
136137 throw(MException(' getWidgetInfo:noHandleProvided' ,...
137138 ' Please provide a valid UIFigure handle as a first input.' ));
138139 end
139- if nargin < 2 || isempty(verbose )
140- verbose = false ;
140+ if nargin < 2 || isempty(verboseFlag )
141+ verboseFlag = false ;
141142 end
142143 %%
143144 win = mlapptools .getWebWindow(hUIFig );
@@ -149,7 +150,7 @@ function fontWeight(uiElement, weight)
149150 try
150151 widgets{ind1 } = jsondecode(win .executeJS(sprintf(' W[%d ]' , ind1 )));
151152 catch % handle circular references:
152- if verbose
153+ if verboseFlag
153154 disp([' Node #' num2str(ind1 - 1 ) ' with id ' win .executeJS(sprintf(' W[%d ].id' , ind1 - 1 ))...
154155 ' could not be fully converted. Attempting fallback...' ]);
155156 end
@@ -223,6 +224,11 @@ function fontWeight(uiElement, weight)
223224 end
224225
225226 end % setStyle
227+
228+ function setTimeout(hUIFig , newTimeoutInSec )
229+ % Sets a custom timeout for dojo queries, specified in [s].
230+ setappdata(hUIFig , ' QUERY_TIMEOUT' , newTimeoutInSec );
231+ end
226232
227233 function textAlign(uiElement , alignment )
228234 % A method for manipulating text alignment.
@@ -271,8 +277,9 @@ function textAlign(uiElement, alignment)
271277 function [widgetID ] = getWidgetID(win , data_tag )
272278 widgetquerystr = sprintf(' dojo.getAttr(dojo.query("[data-tag^=''%s'' ] > div")[0], "widgetid")' , data_tag );
273279
280+ to = mlapptools .getTimeout(mlapptools .figFromWebwindow(win ));
274281 tic
275- while true && (toc < mlapptools . QUERY_TIMEOUT )
282+ while true && (toc < to )
276283 try
277284 widgetID = win .executeJS(widgetquerystr );
278285 widgetID = widgetID(2 : end - 1 );
@@ -289,14 +296,19 @@ function textAlign(uiElement, alignment)
289296 end
290297 mlapptools .toggleWarnings(' on' )
291298
292- if toc >= mlapptools . QUERY_TIMEOUT
299+ if toc >= to
293300 msgID = ' mlapptools:getWidgetID:QueryTimeout' ;
294301 error(msgID , ...
295302 ' widgetID query timed out after %u seconds, UI needs more time to load' , ...
296- mlapptools . QUERY_TIMEOUT );
303+ to );
297304 end
298305 end % getWidgetID
299306
307+ function to = getTimeout(hFig )
308+ to = getappdata(hFig ,' QUERY_TIMEOUT' );
309+ if isempty(to ), to = mlapptools .QUERY_TIMEOUT ; end
310+ end
311+
300312 function tf = isUIFigure(hList )
301313 tf = arrayfun(@(x )isa(x ,' matlab.ui.Figure' ) && ...
302314 isstruct(struct(x ).ControllerInfo), hList );
@@ -371,6 +383,15 @@ function validateAlignmentStr(alignment)
371383 error(msgID , ' Invalid font weight specified: ''%s'' ' , weight );
372384 end
373385 end % validateFontWeight
386+
387+ function hFig = figFromWebwindow(hWebwindow )
388+ hFigs = findall(groot , ' Type' , ' figure' );
389+ mlapptools .toggleWarnings(' off' );
390+ hUIFigs = hFigs(arrayfun(@(x )isstruct(struct(x ).ControllerInfo), hFigs ));
391+ ww = arrayfun(@mlapptools .getWebWindow , hUIFigs );
392+ mlapptools .toggleWarnings(' on' );
393+ hFig = hFigs(hWebwindow == ww );
394+ end
374395
375396 end % Private Static Methods
376397
0 commit comments