Skip to content

Commit d021c62

Browse files
committed
Added unlockUIFig(), for bringing back access via external browsers!
See example in the updated README.md.
1 parent 88171df commit d021c62

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ published Wednesday, September 7th, 2016.
3232
[`setStyle`](#setStyle) - Modify a specified style property.
3333
[`setTimeout`](#setTimeout) - Override the default timeout for dojo commands, for a specific `uifigure`.
3434
[`textAlign`](#textAlign) - Modify text alignment.
35+
[`unlockUIFig`](#unlockUIFig) - Modify this UIFigure to allow viewing it in an external browser, on release R2017b and newer.
3536
[`waitForFigureReady`](#waitForFigureReady) - A blocking method that only returns after the uifigure is fully loaded.
3637

3738
-----------------
@@ -335,6 +336,35 @@ myGUI = DOMdemoGUI;
335336
mlapptools.textAlign(myGUI.TextArea, 'right');
336337
```
337338

339+
-----------------
340+
<a name="unlockUIFig"></a>
341+
342+
#### *mlapptools*.**unlockUIFig**(*hUIFig*)
343+
344+
##### Description
345+
346+
This method modifies the properties of the UIFigure controller such that opening the UIFigure in a browser (using the webwindow URL) becomes possible. This method has no effect on MATLAB releases before R2017b (where no such restriction exists in the first place).
347+
348+
##### Examples
349+
350+
Using the demo GUI generated by `./Demo/DOMdemoGUI.m`
351+
352+
```MATLAB
353+
% Create a uifigure:
354+
myGUI = DOMdemoGUI;
355+
356+
% Attempt to open it using an external browser:
357+
hWW = mlapptools.getWebWindow(myGUI.UIFigure);
358+
web(hWW.URL,'-browser'); pause(3);
359+
360+
% "Unlock" the uifigure:
361+
mlapptools.unlockUIFig(myGUI.UIFigure);
362+
363+
% Attempt to open again:
364+
web(hWW.URL,'-browser');
365+
```
366+
The 1<sup>st</sup> browser window should be empty, whereas the 2<sup>nd</sup> should correctly show the contents of the UIFigure.
367+
338368
-----------------
339369
<a name="waitForFigureReady"></a>
340370

mlapptools.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
% setStyle - Modify a specified style property.
1717
% setTimeout - Override the default timeout for dojo commands, for a specific uifigure.
1818
% textAlign - Modify text alignment.
19+
% unlockUIFig - Allow the uifigure to be opened using an external browser.
1920
% waitForFigureReady - A blocking method that only returns after the uifigure is fully loaded.
2021
%
2122
% See README.md for detailed documentation and examples.
@@ -106,6 +107,8 @@ function fontWeight(uiElement, weight)
106107
% A method for dumping the HTML code of a uifigure.
107108
% Intended for R2017b (and onward?) where the CEF url cannot be simply opened in
108109
% an external browser.
110+
% Mostly irrelevant for UIFigures as of the introduction of mlapptools.unlockUIFig(...),
111+
% but can be useful for other non-uifigure webwindows.
109112
%% Obtain webwindow handle:
110113
if isa(hFigOrWin,'matlab.ui.Figure')
111114
win = mlapptools.getWebWindow(hFigOrWin);
@@ -341,6 +344,16 @@ function textAlign(uiElement, alignment)
341344

342345
mlapptools.setStyle(win, 'textAlign', alignment, ID_struct);
343346
end % textAlign
347+
348+
function unlockUIFig(hUIFig)
349+
% This method allows the uifigure to be opened in an external browser,
350+
% as was possible before R2017b.
351+
if verLessThan('matlab','9.3')
352+
% Do nothing, since this is not required pre-R2017b.
353+
else
354+
struct(hUIFig).Controller.ProxyView.PeerNode.setProperty('hostType','""');
355+
end
356+
end % unlockUIFig
344357

345358
function win = waitForFigureReady(hUIFig)
346359
% This blocking method waits until a UIFigure and its widgets have fully loaded.

0 commit comments

Comments
 (0)