StackOverflowMATLABchat / mlapptools

MATLAB class containing methods for programmatic uifigure modification
http://undocumentedmatlab.com/blog/customizing-uifigures-part-2
MIT License
25 stars 11 forks source link

Error executing JavaScript command #7

Closed sco1 closed 6 years ago

sco1 commented 6 years ago

I'm receiving a JS error every time I attempt to modify a UI element.

For example, the demos from the readme:

myGUI = DOMdemoGUI;
mlapptools.fontColor(myGUI.TextArea, 'aqua');

Throws the following:

Error using matlab.internal.webwindow/executeJS (line 701)
Error executing JavaScript command:

    JavaScript error: Uncaught TypeError: dojo.query is not a function at line 1 column 18 in undefined

Error in mlapptools/getWidgetID (line 345)
                    widgetID = win.executeJS(widgetquerystr);

Error in mlapptools.getWebElements (line 104)
            widgetID = mlapptools.getWidgetID(win, mlapptools.getDataTag(uiElement));

Error in mlapptools.fontColor (line 54)
            [win, widgetID] = mlapptools.getWebElements(uiElement);

Error in trialcode (line 2)
mlapptools.fontColor(myGUI.TextArea, 'aqua');

On both Windows & Mac

sco1 commented 6 years ago

Mac ver:

-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.3.0.713579 (R2017b)
MATLAB License Number:
Operating System: Mac OS X  Version: 10.13.2 Build: 17C88 
Java Version: Java 1.8.0_121-b13 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB                                                Version 9.3         (R2017b)

Windows ver:

-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.3.0.713579 (R2017b)
MATLAB License Number:
Operating System: Microsoft Windows 10 Enterprise Version 10.0 (Build 14393)
Java Version: Java 1.8.0_121-b13 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB                                                Version 9.3         (R2017b)
Dev-iL commented 6 years ago

I tried running the code now - it resulted in an error on my 1st attempt, then it was ok. This sort of Heisenbug makes me think it is related to the logic that determines whether the figure finished loading (asynchronously...).

Please try to run the 1st line separately, make sure that the figure is loaded, then run the 2nd line.

sco1 commented 6 years ago

Confirming that executing the figure generating code first does resolve the issue on both OSes

sco1 commented 6 years ago

Is this related to the issues we've run into previously with #1?

Dev-iL commented 6 years ago

@sco1 Yes, I believe these issues are related.

I think I came up with a better testing method based on the ideas in the other issue. Please test the solution I uploaded to my fork: https://github.com/Dev-iL/mlapptools/commit/697f6c9d5fe74d73667440e284d92520dadd397a

If it works for you, I'll merge it and we can close the issues (at least until a new MATLAB version comes out).

sco1 commented 6 years ago

I still need a bit of time to check some things out but it looks good for the most part.

It does regress the issue identified & fixed in #5. 2bd87fc asserts that getWebWindow will get the ancestor automatically but it does not in the uipanel case:

Reference to non-existent field 'PlatformHost'.

Error in mlapptools.getWebWindow (line 121)
                win = struct(hController.PlatformHost).CEF;

Error in mlapptools.getWebElements (line 103)
            win = mlapptools.getWebWindow(uiElement);

Error in mlapptools.fontWeight (line 67)
            [win, widgetID] = mlapptools.getWebElements(uiElement);

Error in trialcode (line 6)
mlapptools.fontWeight(txa, 'bold');

Adding the ancestor check to getWebWindow quickly fixes this issue.

This could also affect waitTillFigureLoaded since it assumes it's being passed a figure input, which might not necessarily be the case because the type enforcement happens elsewhere. That being said, it doesn't look like it will cause an overt error since it's checking for existence of struct(hFig).Controller, which is still present with a uipanel input.

It would probably be best to go through and check on all of the input assumptions and make sure they're correct and type enforced as early as appropriate.

Dev-iL commented 6 years ago

It doesn't regress, I just didn't add this change on my branch so as to avoid merge issues later on :)

sco1 commented 6 years ago

Should be fixed with #8 (947c54e)