Tutorials using the command sendToWebEngine are missing a vital detail

Tutorials using the command sendToWebEngine are missing a vital detail

Anonymous
Not applicable
642 Views
3 Replies
Message 1 of 4

Tutorials using the command sendToWebEngine are missing a vital detail

Anonymous
Not applicable

There are a lot of great samples how to use HTML5 with VRED.

 

Unfortunately none of them shows how to access the data parameter of the following python code in JavaScript

sendToWebEngine( name, event, data )

VRED uses a so called CustomEvent to talk to the WebEngine. I was successfully accessing the data parameter from python as the .detail member of the JavaScript event like this:

  document.addEventListener("SET_TEXT1", function(evt) {
    document.getElementById("hudText1").innerText = evt.detail;
  });
0 Likes
643 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Hello, I'm trying to display the data parameter on my browser.

I tried this but it did not work.

	sendToWebEngine("SizeValue", "ValueX", str(XValue))
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <h1>SIZE</h1>
    <script>
    document.addEventListener("ValueX", function(evt) {
            ValueX= document.getElementById("XValue").innerText = evt.detail;
            });
            
         document.write(ValueX);
    </script> 

</body>
</html>
0 Likes
Message 3 of 4

Anonymous
Not applicable

Dear Ayoub, 

 

your attempt is wrong in many levels. Let me try to both give you running code for your use case and also explain how it works.

 

Python side needs to look like this:

 

 

 

sendToWebEngine(nameOfEngine, "SET_SIZE", "x="+str(xSize)+", y="+str(ySize))

 

 

 

 

HTML side should look like this:

 

 

 

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <h1>SIZE</h1>
    <span id="sizeValue">to be replaced by event listener</span>
    <script>
    document.addEventListener("SET_SIZE", function(evt) {
       document.getElementById("sizeValue").innerText = evt.detail;
    });
    </script> 
</body>
</html>

 

 

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

Hello, thank you for the answer.

 

 

0 Likes