GithubHelp home page GithubHelp logo

vpython / vpython-jupyter Goto Github PK

View Code? Open in Web Editor NEW
138.0 138.0 65.0 8.87 MB

3D visualization made easy

License: MIT License

Python 74.43% Jupyter Notebook 0.88% JavaScript 13.23% TypeScript 0.42% CSS 2.68% HTML 6.03% Cython 2.34%

vpython-jupyter's People

Contributors

0dminnimda avatar aherrera1721 avatar axe319 avatar bauen1 avatar brianbbsu avatar brucesherwood avatar dalthviz avatar danx0r avatar dependabot[bot] avatar elias-a avatar eye0inc avatar genevievebuckley avatar gwtaylor avatar higucheese avatar jcoady avatar kdunn926 avatar mgorny avatar mwcraig avatar odidev avatar pmelanson avatar ruthchabay avatar sspickle avatar uz9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vpython-jupyter's Issues

Websocket hang on JupyterLab + JupyterHub while classic Notebook + JupyterHub is OK

Hello,

For a third year undergraduate course we are running JupyterHub 1.3.0 which is configured to serve up JupyterLab 3.0.9 by default. The Python version is 3.8.8 and VPython is at 7.6.1. Everything has been installed via conda.

Starting a new notebook in JupyterLab and running the MWE of:

from vpython import *
scene = canvas()
sphere()

results in the first cell executing fine and the second cell hung on [*] with no output. When I interrupt the kernel I see

/opt/conda/lib/python3.8/site-packages/vpython/with_notebook.py in <module>
    151 baseObj.glow = GlowWidget(wsport=__SOCKET_PORT, wsuri='/ws')
    152 while (not wsConnected):
--> 153     time.sleep(0.1)          # wait for websocket to connect
    154 
    155 baseObj.trigger()  # start the trigger ping-pong process

which is similar to what is described in this thread: https://groups.google.com/g/vpython-users/c/yd1aO79mdV0?pli=1
We tried the fix in the last post of that thread to no avail.

I understand that this issue was supposed to be resolved for non-localhost type setups (like JupyterHub or Binder) as per #28.

Interestingly, if we start in Classic notebook by replacing /lab in the URL with /tree, or using the “Launch Classic Notebook” item in JupyterLab’s Help menu, the MWE works perfectly fine.

So it seems to be the combination of JupyterLab and JupyterHub that's preventing the opening of the websocket.

Compound origin bug

Omitting an origin attribute from the constructor for a compound object leads to "AttributeError: 'compound' object has no attribute '_origin'"

How to use it in Google colab?

Screenshot from 2020-04-11 21-10-22
hangs without render anything.
I do the following steps to install the environment:

!apt install curl
!curl -sL https://deb.nodesource.com/setup_10.x | bash -
!apt-get install -y nodejs
!node -v
!pip install vpython
!jupyter labextension install vpython

Adding options to the menu widget

Hi,
I am relatively new to vpython and am working on a project where I would benefit from being able to add options to an existing menu widget. I see that in the documentation it says that the menu choices could be updated by specifying a new list of strings. I was able to get my new choices to appear on the menu in my browser, but it appears like this breaks the indexing system on the menu. This is demonstrated by the example program below.

from vpython import *

scene = canvas()
scene.append_to_title("<h1>Bug Demonstration</h1>")
scene.append_to_title("\n")

def menuFunc(menu):
    print("Selected: " + menu.selected)
    print("Index: " + str(menu.index))
    
options = 3
menuChoices = ["Choice 1", "Choice 2", "Choice 3"]
m = menu(pos = scene.title_anchor, choices = menuChoices, bind = menuFunc)
scene.append_to_title("  ")

def addChoice():
    global options, menuChouces, m
    options += 1
    menuChoices.append("Choice " + str(options))
    m.choices = menuChoices

b = button(pos = scene.title_anchor, bind = addChoice, text = "Add Menu Choice")

box(pos = vector(0,0,0))

I have the menu binded to a function that will print the menu selection and index. This works properly before I add more choices, but after the choices are added, the function will only print the index and selection of the last index when any choice in the menu is selected besides the first one. I have tried to fix this problem in my main project, but all solutions that I have come up with have caused the same issue.

I am using vpython version 7.6.2, python version 3.8.3, running the program in spyder, and using chrome to view the canvas.

Unable to quit program when using PowerShell

I know this isn't specifically related to vpython jupyter, but I'm not sure where else to put it. If there is a better place for this query let me know.

As per the documentation at https://vpython.org/presentation2018/install.html
I include from vpython.no_notebook import stop_server and stop_server() at the end of my program, however when it finishes the browser window stays active and I am unable to do anything within PowerShell. Exiting the browser window does not stop the program either. The only way I've found to stop the program from running and regain control is to press ctrl+break, but I'd like for there to be a clean way to do this.

Thanks.

Import error

python3
Ubuntu 18.04
pip3 install vpython

  Building wheel for vpnotebook (setup.py) ... error
  ERROR: Complete output from command /usr/bin/python3 -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-psmc2uo_/vpnotebook/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-6p65ughb --python-tag cp36:
  ERROR: ImportError install_kernel_spec
  /usr/lib/python3/dist-packages/setuptools/dist.py:397: UserWarning: Normalizing '0.1.03' to '0.1.3'
    normalized_version,
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib
  creating build/lib/vpnotebook
  copying vpnotebook/__init__.py -> build/lib/vpnotebook
  creating build/lib/vpnotebook/data
  copying vpnotebook/data/kernel.json -> build/lib/vpnotebook/data
  installing to build/bdist.linux-x86_64/wheel
  running install
  Installing Python module...
  running install_lib
  creating build/bdist.linux-x86_64
  creating build/bdist.linux-x86_64/wheel
  creating build/bdist.linux-x86_64/wheel/vpnotebook
  creating build/bdist.linux-x86_64/wheel/vpnotebook/data
  copying build/lib/vpnotebook/data/kernel.json -> build/bdist.linux-x86_64/wheel/vpnotebook/data
  copying build/lib/vpnotebook/__init__.py -> build/bdist.linux-x86_64/wheel/vpnotebook
  running install_egg_info
  running egg_info
  writing vpnotebook.egg-info/PKG-INFO
  writing dependency_links to vpnotebook.egg-info/dependency_links.txt
  writing top-level names to vpnotebook.egg-info/top_level.txt
  reading manifest file 'vpnotebook.egg-info/SOURCES.txt'
  writing manifest file 'vpnotebook.egg-info/SOURCES.txt'
  Copying vpnotebook.egg-info to build/bdist.linux-x86_64/wheel/vpnotebook-0.1.3.egg-info
  running install_scripts
  Installing custom kernel ...
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-psmc2uo_/vpnotebook/setup.py", line 30, in <module>
      package_data={'vpnotebook': ['data/kernel.json']},
    File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
      self.run_command(cmd)
    File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/usr/lib/python3/dist-packages/wheel/bdist_wheel.py", line 240, in run
      self.run_command('install')
    File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/tmp/pip-install-psmc2uo_/vpnotebook/vpnotebook/__init__.py", line 72, in run
      run_kernel_install(False)
    File "/tmp/pip-install-psmc2uo_/vpnotebook/vpnotebook/__init__.py", line 63, in run_kernel_install
      install_kernel_spec(source_dir, kernel_name='vpython', user=user)
  NameError: free variable 'install_kernel_spec' referenced before assignment in enclosing scope
  ----------------------------------------
  ERROR: Failed building wheel for vpnotebook

Perhaps the same import error as vpython/visual#10

"Task exception was never retrieved" and "TypeError" while zooming

Steps to reproduce:
(use Chrome/Firefox as the default browser)
(in Win10 cmdline)

D:\code\py>python
Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 13:35:33) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import vpython
>>> vpython.__version__
'7.5.1'
>>> vpython.sphere()
<vpython.vpython.sphere object at 0x000001FB85AD1A90>
>>>

Now a browser is opened and the sphere is shown correctly. Zoom in the object sufficiently (probably with other operations, with touch screen), the following will then repeatedly shown:

Task exception was never retrieved
future: <Task finished coro=<WSserver.onMessage() done, defined at C:\Users\xyy82\AppData\Roaming\Python\Python36\site-packages\vpython\no_notebook.py:154> exception=TypeError('must be real number, not NoneType',)>
Traceback (most recent call last):
  File "C:\Users\xyy82\AppData\Roaming\Python\Python36\site-packages\vpython\no_notebook.py", line 187, in onMessage
	await loop.run_in_executor(None, GW.handle_msg, msg)
  File "C:\Program Files\Python36\lib\concurrent\futures\thread.py", line 56, in run
	result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\xyy82\AppData\Roaming\Python\Python36\site-packages\vpython\vpython.py", line 393, in handle_msg
	cvs.handle_event(evt)
  File "C:\Users\xyy82\AppData\Roaming\Python\Python36\site-packages\vpython\vpython.py", line 3159, in handle_event
	evt['pos'] = list_to_vec(pos)
  File "C:\Users\xyy82\AppData\Roaming\Python\Python36\site-packages\vpython\vpython.py", line 177, in list_to_vec
	return vector(L[0], L[1], L[2])
  File "vpython/cyvector.pyx", line 29, in vpython.cyvector.vector.__init__
TypeError: must be real number, not NoneType

Import fails in (some) spyder versions

From the vpython email list (https://groups.google.com/forum/?hl=en#!topic/vpython-users/jFiOpafJnkI):

 from vpython import*
  box()

there is an error showed in console:

  KeyError: 'default/interpreter/dedicated'

but it is fine when I use Jupyter Notebook to run it.

How can I fix this?

The console message:

runfile('D:/user/Desktop/WPy64-3740/settings/.spyder-py3/temp.py', wdir='D:/user/Desktop/WPy64-3740/settings/.spyder-py3')
Traceback (most recent call last):

  File "<ipython-input-1-e68d4507caad>", line 1, in <module>
    runfile('D:/user/Desktop/WPy64-3740/settings/.spyder-py3/temp.py', wdir='D:/user/Desktop/WPy64-3740/settings/.spyder-py3')

  File "D:\user\Desktop\WPy64-3740\python-3.7.4.amd64\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "D:\user\Desktop\WPy64-3740\python-3.7.4.amd64\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "D:/user/Desktop/WPy64-3740/settings/.spyder-py3/temp.py", line 8, in <module>
    from vpython import*

  File "D:\user\Desktop\WPy64-3740\python-3.7.4.amd64\lib\site-packages\vpython\__init__.py", line 57, in <module>
    _warn_if_spyder_settings_wrong()

  File "D:\user\Desktop\WPy64-3740\python-3.7.4.amd64\lib\site-packages\vpython\_notebook_helpers.py", line 15, in _warn_if_spyder_settings_wrong
    if not _spyder_run_setting_is_correct():

  File "D:\user\Desktop\WPy64-3740\python-3.7.4.amd64\lib\site-packages\vpython\_notebook_helpers.py", line 11, in _spyder_run_setting_is_correct
    return CONF['run']['default/interpreter/dedicated']

  File "D:\user\Desktop\WPy64-3740\python-3.7.4.amd64\lib\configparser.py", line 1251, in __getitem__
    raise KeyError(key)

KeyError: 'default/interpreter/dedicated'

How to use old code with display()?

Here is a webpage

Here is code:

from vpython import *
display(title=u"坐标轴".encode("gb2312"), width=300, height=300)
arrow(pos=(1,0,0), axis=(1,0,0), color=(1,0,0))
arrow(pos=(0,1,0), axis=(0,1,0), color=(0,1,0))
arrow(pos=(0,0,1), axis=(0,0,1), color=(0,0,1))

I tried to run it , but I don't see anything.

It returns that

NameError: name 'display' is not defined

So how to solve it?

I tried to delete display(title=u"坐标轴".encode("gb2312"), width=300, height=300) ,and get nothing.

image

will frames be added?

I am trying to program a serial link mechanism like this

However, I don't seem to able to control rotation frames easily. I assume if you implement frames eventually it will make my life easier. The old vision code had it, any idea if you will add frames?

qt browser does not work on python 3.8

When I try the program below on python 3.8 I get the error traceback that is below the program.

to reproduce, run this

from vpython import *
set_browser(type='pyqt')
b = box()

Error traceback

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/multiprocessing/spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/multiprocessing/spawn.py", line 125, in _main
    prepare(preparation_data)
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/multiprocessing/spawn.py", line 236, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/runpy.py", line 263, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/mattcraig/development/vpython-jupyter/Demos_no_notebook/qt.py", line 3, in <module>
    b = box()
  File "/Users/mattcraig/development/vpython-jupyter/vpython/vpython.py", line 1099, in __init__
    super(box, self).setup(args)
  File "/Users/mattcraig/development/vpython-jupyter/vpython/vpython.py", line 579, in setup
    super(standardAttributes, self).__init__()
  File "/Users/mattcraig/development/vpython-jupyter/vpython/vpython.py", line 236, in __init__
    from .no_notebook import _
  File "/Users/mattcraig/development/vpython-jupyter/vpython/no_notebook.py", line 265, in <module>
    __m.start()
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/multiprocessing/context.py", line 283, in _Popen
    return Popen(process_obj)
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 42, in _launch
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/multiprocessing/spawn.py", line 154, in get_preparation_data
    _check_not_importing_main()
  File "/Users/mattcraig/miniconda3/envs/vptest/lib/python3.8/multiprocessing/spawn.py", line 134, in _check_not_importing_main
    raise RuntimeError('''
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.
Exception ignored in: <function standardAttributes.__del__ at 0x7f8a780971f0>
Traceback (most recent call last):
  File "/Users/mattcraig/development/vpython-jupyter/vpython/vpython.py", line 1092, in __del__
    super(standardAttributes, self).__del__()
  File "/Users/mattcraig/development/vpython-jupyter/vpython/vpython.py", line 317, in __del__
    cmd = {"cmd": "delete", "idx": self.idx}
AttributeError: 'box' object has no attribute 'idx'

winput does not get re-enabled after being disabled

Hi maintainers,

In my program, I disable and re-enable a couple winput fields during runtime. It starts out enabled (and the user can properly enter text), then I set winput.disabled = True and then winput.disabled = False, but the winput field cannot be made to enter text again. This is unexpected, as re-enabling the winput field should allow text to be entered again.

Also, re-enabling the field does change the element's styling, but does not remove disabled="disabled" on the HTML element. So it seems like the intent is for the field to be re-enabled, but it does not properly get re-enabled.

I was able to reproduce this with the following program:

from vpython import *
w = winput(bind=lambda box: print(box.text))  # At this point, the user can enter text
w.disabled = True  # At this point, the user cannot enter text
w.disabled = False  # At this point, the user cannot (but I think _should_ be able to) enter text

Is this a bug? If it is, and we agree on a fix (having w.disabled = False re-enable the HTML input field), I can investigate and make a pull request.

Thank you maintainers!

winput: onChange updates would be nice

I've seen many students forget to hit "enter" when they're using a winput text box. This is mostly a reminder to myself to look into calling the bound function on every change, rather than just when the user hits "enter". Submitting this as an issue will help me remember to look into it sometime soon.

Jupyter in VS Code - Wait for websocket to connect

Hi, I am running a notebook in VS code with the tutorial commands:

from vpython import *
sphere()

The first command finishes but the second hangs on this line from the stack trace:

KeyboardInterrupt
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-2-b919c6b7ad5b> in <module>
----> 1 sphere()

~/opt/anaconda3/lib/python3.7/site-packages/vpython/vpython.py in __init__(self, **args)
   1148         args['_default_size'] = vector(2,2,2)
   1149         args['_objName'] = "sphere"
-> 1150         super(sphere, self).setup(args)
   1151         self._sizing = False # no axis/size connection
   1152 

~/opt/anaconda3/lib/python3.7/site-packages/vpython/vpython.py in setup(self, args)
    582 
    583     def setup(self, args):
--> 584         super(standardAttributes, self).__init__()
    585         self._constructing = True  ## calls to setters are from constructor
    586 

~/opt/anaconda3/lib/python3.7/site-packages/vpython/vpython.py in __init__(self, **kwargs)
    236                 baseObj._canvas_constructing):
    237             if _isnotebook:
--> 238                 from .with_notebook import _
    239             else:
    240                 from .no_notebook import _

~/opt/anaconda3/lib/python3.7/site-packages/vpython/with_notebook.py in <module>
    151 baseObj.glow = GlowWidget(wsport=__SOCKET_PORT, wsuri='/ws')
    152 while (not wsConnected):
--> 153     time.sleep(0.1)          # wait for websocket to connect
    154 
    155 baseObj.trigger()  # start the trigger ping-pong process

KeyboardInterrupt: 

Update Readme.md of labextension with proper install instructions

I am delighted to see that we can now use vpython in jupyterlab 3. However, I spend a few hours understanding why the given instruction "jupyter labextension install vpython" did not work and trying to debug a nonexsting issue. It is only when I found a closed issue where @jcoady explained how to install for jlab > 3 that I understood that I was installing the wrong thing.

Maybe the Readme.md can be updated to include the information from that issue that for different jlab versions the following commands need to be executed?

The vpython extension for JuptyerLab 3 and vpython version 7.6.1 can be installed with the command.
pip install jupyterlab-vpython==3.0.4
The vpython extension for JupyterLab 2 and vpython version 7.6.1 can be installed with the command.
jupyter labextension install [email protected]

Thanks in advance and also for this great visualization package
Cheers

WebSocket drops the connection

I use vpython as a visualization tool in a larger program.

When working with larger models, during model generation I sometimes get a dropped connection:

dropping connection to peer tcp4:127.0.0.1:56067 with abort=True: WebSocket opening handshake timeout (peer did not finish the opening handshake in time)

The model then gets built, but the program run stops.

Is there a way to change the timeout (or any other means to prevent this happening)?

Breakage with spyder 4

There may be more issues, but at a minimum this error needs to be fixed:

Traceback (most recent call last):

  File "/Users/mattcraig/.spyder-py3/temp.py", line 8, in <module>
    from vpython import box

  File "/Users/mattcraig/development/vpython-jupyter/vpython/__init__.py", line 57, in <module>
    _warn_if_spyder_settings_wrong()

  File "/Users/mattcraig/development/vpython-jupyter/vpython/_notebook_helpers.py", line 17, in _warn_if_spyder_settings_wrong
    if not _spyder_run_setting_is_correct():

  File "/Users/mattcraig/development/vpython-jupyter/vpython/_notebook_helpers.py", line 10, in _spyder_run_setting_is_correct
    from spyder.config.main import CONF

ImportError: cannot import name 'CONF' from 'spyder.config.main' (/Users/mattcraig/miniconda3/envs/vp37/lib/python3.7/site-packages/spyder/config/main.py)

websocket ip in jupyter notebook

As we know ,we might be able to make jupyter notebook listen on different ip. However, vpython always try to connect to ws://localhost.

I think that It might be well to make vpython connect to what jupyter notebook is listening on.

capture doesn't work

I tried to capture a scene to a file:

scene = canvas()
# created some stuff here ...
scene.capture("test.jpg")

On linux, nothing happened.

scaling an extrusion

In the classic vpython a linear scaling of a extrusion was possible by defining a ratio between the start and the end face. In the new version this is not possible; calling extrusion() with a scale argument does not raise a NotImplementedError or similar, but the resulting object is generated as if scale=1 was defined.
Is it planned to incluse this feature?

Problems with Carnets PLus on iPad

I use python on my iPad, using the (very good!!) app Carmets PLus, which is a Jupiter Notebook.
I started to play around with vpython.
When I open a new notebook, it seems to work fine, but when I close the notebook, reopen it and try to run it again, it seems to enter some 'infinite loop': it seems to calculate something, but the result never comes.

Any help would be GREATLY appreciated!!

Spontaneous scene error

The equivalent of the following code did not initially produce an error, but the next day it did:

from vpython import canvas,box
scene = None
def reset(scene=scene):
    if scene: scene.delete()
    scene = canvas()
reset(scene)
scene.camera.follow(box())

AttributeError: 'NoneType' object has no attribute 'camera'

I fixed it with:

from vpython import canvas,box
scene = None
def reset():
    global scene
    if scene: scene.delete()
    scene = canvas()
reset()
scene.camera.follow(box())

camera.rotation strange behavior.

Using the code:

scene.camera.rotate(angle=-5.0 * PI / 180.0,
                                axis=scene.up,
                                origin=scene.center)

where:

  • scene.up is <0, 1, 0>
  • scene.center is <0, 0, 0>

From this top view:
before

I obtain this:
after

That doesn't seems what I was expecting, there is some error or I misunderstood the doc ?

Missing scene/camera sync with browser view after web page-mouse interaction.

If you change the point of view dragging with mouse in the browser window the camera and scene data are not updated.
It could be CPU intensive/inefficient so could be possible to add at least an explicit sync method to be able to retrieve correct parameters just before perform some action like camera movement after key pressure detection or just before an action is made on scene or camera ?

For Jupyter Lab 3, Every cell output raises "Javascript Error"

Environment A

Jupyter Lab 3.2.5
jupyterlab-vpthon 3.0.7(development version from https://github.com/jcoady/jupyterlab_vpython)

Environment B

Jupyter Lab 3.2.5
jupyterlab-vpython 3.1.1(installed via pip install jupyterlab-vpython)

Steps to Reproduce

In env A and B, executing following two cell raises "Javascript Error"

from vpython import *
box()
print("Hello, VPython!")

image

Additionally, exceptions are silently ignored and raise the "Javascript Error"
image

Expected Behavior

texts and exceptions are expected to be printed like this :
image

My Investigation

Even if I restart the kernel, the bug still exists. I guess something break my brower's javascript runtime. I must reload the brower tab to fix this.

glow.min.js is supected of causing this bug. Because right after import 'script-loader!../vpython_libraries/glow.min.js'; executed, the bug was occured.

Add support to release linux aarch64 wheels

Problem

On aarch64, ‘pip install vpython’ builds the wheels from source code and then installs it. It requires the user to have a development environment installed on his system. Also, it takes some time to build the wheels than downloading and extracting the wheels from pypi.

Resolution

On aarch64, ‘pip install vpython’ should download the wheels from pypi

@BruceSherwood and Team Please let me know your interest in releasing aarch64 wheels. I can help in this.

version7.6.3: error when executing scene.camera.follow(None)

using Ubuntu Linux 21.10, python 3.9.7, vpython version 7.3.6 jupyter:
after upgrading to vpython version 7.6.3, i got this error when my program tries to execute the scene.follow(None)"command:

The error is reproducable using idle or a python shell:

>>> import vpython as vp
>>> vp.scene
<vpython.vpython.canvas object at 0x7f059eaabbb0>
>>> vp.scene.camera.follow(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/horst/.local/lib/python3.9/site-packages/vpython/vpython.py", line 2937, in follow
    self.addmethod('follow', obj.idx)
AttributeError: 'NoneType' object has no attribute 'idx'
>>> 

Is this a re-introduced error from version <7.6.1 ?
If i run a bigger vpython program, i got those error messages below. The program still continues to work, but the camera is still following the object from the last camera.follow command, it is ignoring the "scene.camera.follow(None)" command.

my current workaround is to let the camera follow an non-moving object


Task exception was never retrieved
future: <Task finished name='Task-189' coro=<WSserver.onMessage() done, defined at /home/horst/.local/lib/python3.9/site-packages/vpython/no_notebook.py:181> exception=AttributeError("'NoneType' object has no attribute 'idx'")>
Traceback (most recent call last):
  File "/home/horst/.local/lib/python3.9/site-packages/vpython/no_notebook.py", line 214, in onMessage
    await loop.run_in_executor(None, GW.handle_msg, msg)
  File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/horst/.local/lib/python3.9/site-packages/vpython/vpython.py", line 392, in handle_msg
    obj._bind()
  File "/home/horst/code/vpython/flugzeug2.py", line 34, in follow_plane_no
    Game.scene1.camera.follow(None)
  File "/home/horst/.local/lib/python3.9/site-packages/vpython/vpython.py", line 2937, in follow
    self.addmethod('follow', obj.idx)
AttributeError: 'NoneType' object has no attribute 'idx'

JupyterLab 1.04 not supported?

I was creating a fresh environment today, which installed JupyterLab 1.04. When I tried installed the VPython extension I get the following:

An error occured.
ValueError: This extension does not yet support the current version of JupyterLab.
Conflicting Dependencies:
JupyterLab              Extension      Package
>=1.0.2 <2.0.0          >=0.19.1 <0.20.0@jupyterlab/application
>=1.0.2 <2.0.0          >=0.19.1 <0.20.0@jupyterlab/apputils
>=1.0.2 <2.0.0          >=0.19.1 <0.20.0@jupyterlab/notebook

This isn't a big deal for me since I've got other environments installed that work but I thought I'd mention it in case this causes problems for others in the future.

Binder error

@jcoady -- I tried the latest on binder and get this error in the javascript console:

main.min.js?v=617dbb6b838f3495e90f667d4b1f2fa9:24955 Could not open comm  --  Error: Class glow not found in registry 
    at main.min.js?v=617dbb6b838f3495e90f667d4b1f2fa9:24919
    at new Promise (<anonymous>)
    at Object.load_class (main.min.js?v=617dbb6b838f3495e90f667d4b1f2fa9:24904)
    at CommManager.comm_open (main.min.js?v=617dbb6b838f3495e90f667d4b1f2fa9:36618)
    at i (main.min.js?v=617dbb6b838f3495e90f667d4b1f2fa9:2)
    at Kernel._handle_iopub_message (main.min.js?v=617dbb6b838f3495e90f667d4b1f2fa9:38098)
    at Kernel._finish_ws_message (main.min.js?v=617dbb6b838f3495e90f667d4b1f2fa9:37890)
    at main.min.js?v=617dbb6b838f3495e90f667d4b1f2fa9:37881
(anonymous) @ main.min.js?v=617dbb6b838f3495e90f667d4b1f2fa9:24955
main.min.js?v=617dbb6b838f3495e90f667d4b1f2fa9:37882 Couldn't process kernel message WrappedError

The binder URL I used is https://mybinder.org/v2/gh/vpython/vpython-jupyter/master?filepath=index.ipynb

Shape roundness bug

Using shape roundness argument results in extrusion missing front and end faces.

from vpython import *

print(version)
print(GSversion)

### works as expected
# rt = shapes.rectangle(width=3, height=3)

### start and end faces missing
rt = shapes.rectangle(width=3, height=3, roundness=0.1)

extrusion(
    path=[vec(0,0,0), vec(0,0,-0.1)],
    shape=rt
    )

bug

['7.6.1', 'jupyter']
['2.9', 'glowscript']

request: Python-3.9

if it's simple via CI systems, it would be nice to generate a wheel for Python-3.9 Windows 64 bit

"Task exception was never retrieved" upon moving mouse in browser canvas

When running a program that uses vpython from an IDE like PyCharm, the program output spits errors when moving the mouse around the browser canvas where the vpython output is located.

I am simply using this program:

from vpython import *
a = arrow(pos=vector(1, 1, 5), color=vector(255, 52, 32))

When I run the program, a browser window opens with the arrow at the specified position. When I move my mouse around, I am spammed with errors like these (all the same error):

Task exception was never retrieved
future: <Task finished name='Task-17' coro=<WSserver.onMessage() done, defined at /home/simple/.local/lib/python3.9/site-packages/vpython/no_notebook.py:156> exception=RuntimeError("can't register atexit after shutdown")>
Traceback (most recent call last):
  File "/home/simple/.local/lib/python3.9/site-packages/vpython/no_notebook.py", line 189, in onMessage
    await loop.run_in_executor(None, GW.handle_msg, msg)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 809, in run_in_executor
    executor = concurrent.futures.ThreadPoolExecutor(
  File "/usr/lib/python3.9/concurrent/futures/__init__.py", line 49, in __getattr__
    from .thread import ThreadPoolExecutor as te
  File "/usr/lib/python3.9/concurrent/futures/thread.py", line 37, in <module>
    threading._register_atexit(_python_exit)
  File "/usr/lib/python3.9/threading.py", line 1370, in _register_atexit
    raise RuntimeError("can't register atexit after shutdown")
RuntimeError: can't register atexit after shutdown

I saw another issue (#14) about this being related to zooming, but I figured this was a novel issue as it happens when simply moving my cursor around.

I'm running on Arch Linux, Python 3.9, PyCharm 2020.3, and Firefox 83.0.

Is this fixable?

Triangle not rendered.

Using this snippet from linux console and vpython 7.6.0 from pypi :

#!/usr/bin/env python3
from vpython import vector as vec
from vpython import *

a = vertex( pos=vec(0,0,0) )
b = vertex( pos=vec(1,0,0) )
c = vertex( pos=vec(1,1,0) )
T = triangle( v0=a, v1=b, v2=c)

and interfacing with chrome Version 79.0.3945.130 (Official Build) unknown (64-bit) I obtain this error in the development console:

Uncaught Error: A triangle does not have a canvas; its vertex objects do.
    at new triangle (glow.min.js:1)
    at triangle (glow.min.js:1)
    at handle_cmds ((index):645)
    at handler ((index):530)
    at WebSocket.ws.onmessage ((index):74)

Is it a sort of misalignment between components or I' m doing something wrong in the snippet ?

extrusion seems doesn't support smooth.

Creating these skittles using extrusion I cannot obtain smoothing setting ''smooth'' attrib to any value between 0 and 1.
Using paths.circle(radius=0.0001, np=16), with paths.circle(radius=0.0001, np=32) works fine also without smooth param.
skittle_wrong

installed python 3.10 raises an exception

import vpython

File "C:\Users\justi\AppData\Roaming\Python\Python310\site-packages\vpython_init_.py", line 25, in
raise Exception(s)
Exception: The non-notebook version of vpython requires Python 3.5 or later.
vpython does work on Python 2.7 and 3.4 in the Jupyter notebook environment.

vpython app stopping takes a few minutes

Steps to reproduce

  • Create script.py:
from vpython import *
b = box()
  • Run python script.py on cmd / Powershell on Windows. New tab appears in browser.
  • Close the browser tab
  • Try to terminate the application with Ctrl-C, Ctrl-D, .. Nothing seems to happen. After few minutes (1? 5? 10?) the script returns to the console.

What would be expected

  • Hitting Ctrl-C exits the process immediately.

Versions

  • vpython 7.6.1
  • Python 3.7.9 64-bit on Windows

scene.capture() does not include labels

The function scene.capture(filename) does not consider labels.

Execute the following code in a jupyter notebook:

from vpython import *
sphere()
label(text='TEXT')
scene.capture('image.png')
Expected output Actually saved
image.png image.png

I noticed that there are two canvas elements in the HTML, one containing the labels, and the other being a placeholder for the 3D objects:

<div class="glowscript-canvas-wrapper ui-resizable" style="display: inline-block; position: relative; float: none;">
    <canvas style="position: absolute;" width="640" height="400"></canvas>
    <canvas style="position: relative; background-color: transparent;" width="640" height="400"></canvas>
    <div class="ui-resizable-handle ui-resizable-e" style="z-index: 90;"></div>
    <div class="ui-resizable-handle ui-resizable-s" style="z-index: 90;"></div>
    <div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 90;"></div>
</div>

It seems that the capturing function here only considers one of them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.