Skip to content
Permalink
Browse files

Added a utility function for getting node descendants of a certain type

- Updated functionSignatures.json accordingly.
- TODO: mention in main readme.
  • Loading branch information...
Dev-iL committed Mar 24, 2019
1 parent c3cb07a commit 6068af3b24f35c74813afc39c1b66c04ee9390cf
Showing with 51 additions and 0 deletions.
  1. +31 −0 functionSignatures.json
  2. +20 −0 mlapptools.m
@@ -529,6 +529,37 @@
}
]
},
"mlapptools.getDecendentOfType":
{
"inputs":
[
{
"name":"hWin",
"kind":"required",
"purpose":"webWindow handle",
"type":["matlab.internal.webwindow"]
},
{
"name":"ancestorDataTag",
"kind":"required",
"purpose":"HTML node's data_tag",
"type":["char"]
},
{
"name":"descendentType",
"kind":"required",
"purpose":"Target descendent's HTML tag",
"type":["char"]
}
],
"outputs":
[
{
"name":"widgetID",
"type":["WidgetID"]
}
]
},
"mlapptools.figFromWebwindow":
{
"inputs":
@@ -669,6 +669,26 @@ function unlockUIFig(hUIFig)
warning(warnState);
end % getDataTag

function [widgetID] = getDecendentOfType(hWin, ancestorDataTag, descendentType)
% This method returns a node's first descendent of a specified <type>.
% See also:
% https://dojotoolkit.org/reference-guide/1.10/dojo/query.html#standard-css2-selectors
widgetquerystr = sprintf(...
'dojo.getAttr(dojo.query("[data-tag^=''%s''] %s")[0], "%s")', ...
ancestorDataTag, descendentType, mlapptools.DEF_ID_ATTRIBUTE);
try % should work for most UI objects
ID = hWin.executeJS(widgetquerystr);
if ~strcmpi(ID,'null')
widgetID = WidgetID(mlapptools.DEF_ID_ATTRIBUTE, ID(2:end-1));
return
end
catch
warning(['Error encountered while obtaining a descendent of ', ancestorDataTag]);
end
% If the JS command failed, or no descendent found, return an empty WidgetID object.
widgetID = WidgetID();
end % getDecendentOfType

function hFig = figFromWebwindow(hWin)
% Using this method is discouraged as it's relatively computation-intensive.
% Since the figure handle is not a property of the webwindow or its children

0 comments on commit 6068af3

Please sign in to comment.
You can’t perform that action at this time.