Localhost and Multiple Camera Views

111 views
Skip to first unread message

Kyle James

unread,
Jul 27, 2022, 10:39:36 AM7/27/22
to VPython-users
Hi all,

I'm currently working on a vpython project where I'd like to get a vpython rendering inside of a GUI application. The GUI is currently taking a url, so I'd need to be able to open vpython's localhost server inside the GUI with the localhost url. As of right now, when I run the python file, edge is being opened automatically, and vpython's visualization runs inside of edge in a localhost server, please see the photo attached for a visual of this. Unfortunately, I'm unable to copy the local host url and use it inside of the GUI, because when I do so, nothing renders. I suspect that this is because the local host server is only able to be displayed in one tab. With this being said, I would like to know if there's a way to get vpython to not open edge or any browser and return the local host url so that I could pass it to the GUI and open the visualization's local host server? If not, I was wondering what files inside of the vpython package contain the command(s) that open edge with the localhost url?

My second question is: is there a way to get multiple camera views in one vpython visualization? As in cameras with different positions and different axes in the same visualization?

If I was unclear in any of this or if any other information is required to help me, please let me know as I'd be happy to answer!

Thank you,
Kyle


example.PNG

Bruce Sherwood

unread,
Jul 27, 2022, 12:57:43 PM7/27/22
to VPython-users
Concerning the first question, it may be helpful to understand the architecture of VPython:


It's not obvious to me whether what you want to do could be feasible or not. Another possibility would be to use Web VPython (webvpython.org), where you can export an html version of your VPython program in which the Python code has been transpiled to JavaScript, and this html code can be placed into an iframe. Here's an example of an exported Web VPython program running in an iframe embedded in a Wordpress document:


Concerning the second question, the answer is yes. Create multiple canvases, and clone the objects of one canvas into the others:


However, if you modify an object in one canvas you will need also to modify it in the other canvases.

Bruce

Kyle James

unread,
Jul 27, 2022, 3:27:19 PM7/27/22
to VPython-users
Hi Bruce,

I looked into putting some test vpython code into web vpython and exporting it as an iframe, and I'm happy to say I can now get vpython to render inside of a PyQt5 application! Thank you for your help there. I'd like to put my own code into web vpython so I can render it in my GUI the same way, but I have a couple of questions first:

1) Am I able to use any other libraries inside of web vpython?
2) My script parses data from a csv and then makes a visualization based off of said data. Would this be possible in web vpython?


Thanks again for your help,
Kyle

Bruce Sherwood

unread,
Jul 27, 2022, 4:49:08 PM7/27/22
to VPython-users
Because Web VPython is transpiled to JavaScript in order to be able to run in the browser, you can't import Python modules unless they are converted to JavaScript, which might be possible using the transpiler, namely if the Python module is pure Python. The developer of the RapydScript-NG transpiler used by Web VPython, Kovid Goyal, used his transpiler to produce a nearly complete random module which is available in Web VPython. 

You can import JavaScript libraries using the get_library() function, and you can read a file from the disk using the read_local_file() function, which brings up a file-selection window.

tinyurl.com/SurfaceCharge is a Web VPython program that imports JavaScript code that was generated by a Python program. Take a look at the files imported by get_library() in that program to see an example of such things.

Bruce

Reply all
Reply to author
Forward
0 new messages