-
Notifications
You must be signed in to change notification settings - Fork 63
tSupport for displaying a VPython program (canvas) in a PyQT #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
oh my, this looks interesting! I'd like to do a bit of testing before this gets merged (shouldn't take more than 24 hours) |
Hi Matt,
Indeed, this morning I completed a pull request that incorporates PyQt with VPython so a VPython program can be displayed in a PyQt window without requiring the use of an external browser.
My fork is at:
https://github.com/atitus/vpython-jupyter
for anyone interested in testing it.
I added a new file qtbrowser.py that creates a PyQT application and web browser window. I modified vpython.py to create a function set_browser() by which the browser can be changed from the default to pyqt. I modified _no_notebook.py to take advantage of the browser option.
In a VPython program, use the code below to pop up a Python looking window with the VPython canvas and scene(s).
```
# use type='pyqt' to open the program in a pyqt5 browser windows
set_browser(type='pyqt')
```
Here is a simple example that creates a sphere in a PyQT window:
```
from vpython import *
set_browser(type='pyqt')
ball=sphere()
```
If one does not call set_browser() then the default behavior is to simply open the user’s default browser, as it does in the current version.
In the source code, there is a special accommodation for users of pypy. I did not modify this section, so presumably, pypy users will still use the default browser. However, there could be a problem if a pypy user sets the browser to pyqt. Now that I think about it, this would cause an error. _notebook.py will have to be modified to avoid an error in this case.
AT
From: Matt Craig <notifications@github.com>
Reply-To: vpython/vpython-jupyter <reply@reply.github.com>
Date: Wednesday, June 19, 2019 at 11:22 AM
To: vpython/vpython-jupyter <vpython-jupyter@noreply.github.com>
Cc: "Titus, Aaron" <atitus@highpoint.edu>, Author <author@noreply.github.com>
Subject: Re: [vpython/vpython-jupyter] tSupport for displaying a VPython program (canvas) in a PyQT (#9)
oh my, this looks interesting!
I'd like to do a bit of testing before this gets merged (shouldn't take more than 24 hours)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#9?email_source=notifications&email_token=AANV55UVMN5JHC6HQONAAMDP3JMLVA5CNFSM4HZKJNA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYCM4YY#issuecomment-503631459>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AANV55TSKFAFCAAGLSEBUGTP3JMLVANCNFSM4HZKJNAQ>.
|
@atitus -- I think this is going to be of interest to a lot of users. I'm hoping to have a chance to take a look at it later this week (finally). |
@atitus -- I finally played around with this tonight! It seemed to work pretty well (I was trying it from within ipython) though I didn't try every demo program. I have a few minor code formatting suggestions/request. Do you want me to:
|
@mwcraig Great! Please make the fixes and push them to my branch. I'm guessing you noticed that I did not sufficiently check for whether one is using pypy. At the time, I noted that a pypy user who sets the browser to pyqt might have a problem that I did not test nor check for. There is one other potential issue that I did not check--the GPL license of PyQt. According to the web site, "PyQt5 is dual licensed on all platforms under the Riverbank Commercial License and the GPL v3." It seems that GPL v3 is consistent with the VPython license at: https://www.glowscript.org/docs/VPythonDocs/license.txt but perhaps our license will need to include a statement about PyQT. |
except: | ||
pass | ||
|
||
|
||
if platform.python_implementation() == 'PyPy' and _browsertype == 'pyqt': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atitus -- does this look OK to you for PyPy error handling? It doesn't avoid an error but it does give a fairly explicit error message. I'm a little reluctant to have PyPy automagically ignore the pyqt browser setting because I imagine it will lead to confusion about why the regular browser is opening, but it would be straightforward to make that happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's fine with me. I don't know for sure that using PyPy and the pyqt browser are incompatible. I just know that the way I originally implemented pyqt in no_notebook.py was solely for non-PyPy cases. It's possible that you or someone else might implement pyqt in a way that is compatible with PyPy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK; I'll merge tomorrow morning to give folks a bit of time to make comments.
I think we are fine regarding the license since we aren't incorporating any pyqt code into vpython; the user has to obtain pyqt and install it themselves, so we aren't redistributing the GPLed code. (Though I am not a lawyer, of course) |
Thank you both for getting this merged, it's going to be really useful! |
Merging, thanks again for this new year's gift! |
@mwcraig Thanks! This was my first official contribution to vpython. There's more in the hopper. |
I added a new file qtbrowser.py that creates a PyQt application and web browser window that looks more like VPython classic. I modified vpython.py to create a function set_browser() by which the browser can be changed from the default to pyqt. I modified _no_notebook.py to take advantage of the browser option. Because a PyQt application must run in the main thread, I had to use the multiprocessing package and launch the PyQt application in its own process from a separate .py file. (I could not launch the application from a function in _no_notebook.py.)
In a VPython program, use the code below to pop up a PyQt window with the VPython canvas and scene(s).
Here is a simple example that creates a sphere in a PyQt window: