|
33 | 33 | end |
34 | 34 | end % aboutDojo |
35 | 35 |
|
36 | | - function fontColor(uielement, newcolor) |
| 36 | + function fontColor(uiElement, newcolor) |
37 | 37 | % A method for manipulating text color. |
38 | 38 | newcolor = mlapptools.validateCSScolor(newcolor); |
39 | 39 |
|
40 | | - [win, widgetID] = mlapptools.getWebElements(uielement); |
| 40 | + [win, widgetID] = mlapptools.getWebElements(uiElement); |
41 | 41 |
|
42 | 42 | fontColorSetStr = sprintf('dojo.style(dojo.query("#%s")[0], "color", "%s")', widgetID, newcolor); |
43 | 43 | win.executeJS(fontColorSetStr); |
44 | 44 | end % fontColor |
45 | 45 |
|
46 | | - function fontWeight(uielement, weight) |
| 46 | + function fontWeight(uiElement, weight) |
47 | 47 | % A method for manipulating font weight, which controls how thick or |
48 | 48 | % thin characters in text should be displayed. |
49 | | - weight = mlapptools.validatefontweight(weight); |
| 49 | + weight = mlapptools.validateFontWeight(weight); |
50 | 50 |
|
51 | | - [win, widgetID] = mlapptools.getWebElements(uielement); |
| 51 | + [win, widgetID] = mlapptools.getWebElements(uiElement); |
52 | 52 |
|
53 | 53 | fontWeightSetStr = sprintf('dojo.style(dojo.query("#%s")[0], "font-weight", "%s")', widgetID, weight); |
54 | 54 | win.executeJS(fontWeightSetStr); |
@@ -80,6 +80,54 @@ function fontWeight(uielement, weight) |
80 | 80 | %} |
81 | 81 | end % getHTML |
82 | 82 |
|
| 83 | + function [win, widgetID] = getWebElements(uiElement) |
| 84 | + % A method for obtaining the webwindow handle and the widgetID corresponding |
| 85 | + % to the provided uifigure control. |
| 86 | + % Get a handle to the webwindow |
| 87 | + win = mlapptools.getWebWindow(uiElement.Parent); |
| 88 | + |
| 89 | + % Find which element of the DOM we want to edit |
| 90 | + widgetID = mlapptools.getWidgetID(win, mlapptools.getDataTag(uiElement)); |
| 91 | + end % getWebElements |
| 92 | + |
| 93 | + function [win] = getWebWindow(hUIFig) |
| 94 | + mlapptools.toggleWarnings('off') |
| 95 | + % Make sure we got a valid handle |
| 96 | + assert(mlapptools.isUIFigure(hUIFig),... |
| 97 | + 'mlapptools:getWebWindow:NotUIFigure',... |
| 98 | + 'The provided window handle is not of a UIFigure.'); |
| 99 | + |
| 100 | + tic |
| 101 | + while true && (toc < mlapptools.QUERY_TIMEOUT) |
| 102 | + try |
| 103 | + hController = struct(struct(hUIFig).Controller); |
| 104 | + % Check for Controller version: |
| 105 | + switch subsref(ver('matlab'), substruct('.','Version')) |
| 106 | + case {'9.0','9.1'} % R2016a or R2016b |
| 107 | + win = hController.Container.CEF; |
| 108 | + otherwise % R2017a onward |
| 109 | + win = struct(hController.PlatformHost).CEF; |
| 110 | + end |
| 111 | + break |
| 112 | + catch err |
| 113 | + if strcmp(err.identifier, 'MATLAB:nonExistentField') |
| 114 | + pause(0.01) |
| 115 | + else |
| 116 | + mlapptools.toggleWarnings('on') |
| 117 | + rethrow(err) |
| 118 | + end |
| 119 | + end |
| 120 | + end |
| 121 | + mlapptools.toggleWarnings('on') |
| 122 | + |
| 123 | + if toc >= mlapptools.QUERY_TIMEOUT |
| 124 | + msgID = 'mlapptools:getWidgetID:QueryTimeout'; |
| 125 | + error(msgID, ... |
| 126 | + 'WidgetID query timed out after %u seconds, UI needs more time to load', ... |
| 127 | + mlapptools.QUERY_TIMEOUT); |
| 128 | + end |
| 129 | + end % getWebWindow |
| 130 | + |
83 | 131 | function varargout = getWidgetInfo(hUIFig,verbose) |
84 | 132 | % A method for gathering information about dijit widgets. |
85 | 133 |
|
@@ -176,12 +224,12 @@ function fontWeight(uielement, weight) |
176 | 224 |
|
177 | 225 | end % setStyle |
178 | 226 |
|
179 | | - function textAlign(uielement, alignment) |
| 227 | + function textAlign(uiElement, alignment) |
180 | 228 | % A method for manipulating text alignment. |
181 | 229 | alignment = lower(alignment); |
182 | 230 | mlapptools.validateAlignmentStr(alignment) |
183 | 231 |
|
184 | | - [win, widgetID] = mlapptools.getWebElements(uielement); |
| 232 | + [win, widgetID] = mlapptools.getWebElements(uiElement); |
185 | 233 |
|
186 | 234 | alignSetStr = sprintf('dojo.style(dojo.query("#%s")[0], "textAlign", "%s")', widgetID, alignment); |
187 | 235 | win.executeJS(alignSetStr); |
@@ -214,63 +262,12 @@ function textAlign(uielement, alignment) |
214 | 262 |
|
215 | 263 | end % emptyStructWithFields |
216 | 264 |
|
217 | | - function [data_tag] = getDataTag(uielement) |
| 265 | + function [data_tag] = getDataTag(uiElement) |
218 | 266 | mlapptools.toggleWarnings('off') |
219 | | - data_tag = char(struct(uielement).Controller.ProxyView.PeerNode.getId); |
| 267 | + data_tag = char(struct(uiElement).Controller.ProxyView.PeerNode.getId); |
220 | 268 | mlapptools.toggleWarnings('on') |
221 | 269 | end % getDataTag |
222 | | - |
223 | | - function [win, widgetID] = getWebElements(uielement) |
224 | | - % Get a handle to the webwindow |
225 | | - win = mlapptools.getWebWindow(uielement.Parent); |
226 | | - |
227 | | - % Find which element of the DOM we want to edit |
228 | | - data_tag = mlapptools.getDataTag(uielement); |
229 | | - |
230 | | - % Manipulate the DOM via a JS command |
231 | | - widgetID = mlapptools.getWidgetID(win, data_tag); |
232 | | - end % getWebElements |
233 | | - |
234 | | - function [win] = getWebWindow(uifigurewindow) |
235 | | - mlapptools.toggleWarnings('off') |
236 | | - % Test if uifigurewindow is a valid handle |
237 | | - if ~isa(uifigurewindow,'matlab.ui.Figure') || ... |
238 | | - isempty(struct(uifigurewindow).ControllerInfo) |
239 | | - msgID = 'mlapptools:getWebWindow:NotUIFigure'; |
240 | | - error(msgID, 'The provided window handle is not of a UIFigure.'); |
241 | | - end |
242 | | - |
243 | | - tic |
244 | | - while true && (toc < mlapptools.QUERY_TIMEOUT) |
245 | | - try |
246 | | - hController = struct(struct(uifigurewindow).Controller); |
247 | | - % Check for Controller version: |
248 | | - switch subsref(ver('matlab'), substruct('.','Version')) |
249 | | - case {'9.0','9.1'} % R2016a or R2016b |
250 | | - win = hController.Container.CEF; |
251 | | - otherwise % R2017a onward |
252 | | - win = struct(hController.PlatformHost).CEF; |
253 | | - end |
254 | | - break |
255 | | - catch err |
256 | | - if strcmp(err.identifier, 'MATLAB:nonExistentField') |
257 | | - pause(0.01) |
258 | | - else |
259 | | - mlapptools.toggleWarnings('on') |
260 | | - rethrow(err) |
261 | | - end |
262 | | - end |
263 | | - end |
264 | | - mlapptools.toggleWarnings('on') |
265 | | - |
266 | | - if toc >= mlapptools.QUERY_TIMEOUT |
267 | | - msgID = 'mlapptools:getWidgetID:QueryTimeout'; |
268 | | - error(msgID, ... |
269 | | - 'WidgetID query timed out after %u seconds, UI needs more time to load', ... |
270 | | - mlapptools.QUERY_TIMEOUT); |
271 | | - end |
272 | | - end % getWebWindow |
273 | | - |
| 270 | + |
274 | 271 | function [widgetID] = getWidgetID(win, data_tag) |
275 | 272 | widgetquerystr = sprintf('dojo.getAttr(dojo.query("[data-tag^=''%s''] > div")[0], "widgetid")', data_tag); |
276 | 273 |
|
@@ -299,7 +296,12 @@ function textAlign(uielement, alignment) |
299 | 296 | mlapptools.QUERY_TIMEOUT); |
300 | 297 | end |
301 | 298 | end % getWidgetID |
302 | | - |
| 299 | + |
| 300 | + function tf = isUIFigure(hList) |
| 301 | + tf = arrayfun(@(x)isa(x,'matlab.ui.Figure') && ... |
| 302 | + isstruct(struct(x).ControllerInfo), hList); |
| 303 | + end |
| 304 | + |
303 | 305 | function toggleWarnings(togglestr) |
304 | 306 | switch lower(togglestr) |
305 | 307 | case 'on' |
|
0 commit comments