Hello,
I am trying to generate a scripted module with embed html. Then I use webEngineView and set the webEngineView url to my html file. Since I want html js to interact with slicer, I use websockets to allow the two to interact, but whether I use multi-process or Cli Module to run websockets server, I can’t operate view node in Slicer. So, is there any good solution to implement the interaction between the embedded HTML components and the Slicer scene?
No need for a websocket, you can communicate directly from python to javascript or javascript to python using the qSlicerWebWidget. See the test code linked below for examples. It’s all asynchronous and smooth.
Here’s an example of some demo code that mixes a web graph with the segment editor.
If you communicate via the web widget data is passed in ascii, which is usually fast enough but if it’s not you can communicate asynchronously by integrating the sockets with the Qt event loop using tools like the QSocketNotifier, which is used in the SlicerWeb code.
It works for me. I use qSlicerWebWidget and set html like this:
and in html, import the js to enable window.slicerPython,
then I can use window.slicerPython.evalPython and self.webWidget.evalJS to communicate from python to javascript and javascript to python.