Problem with widgets in vpython 7

69 views
Skip to first unread message

Avedis Neehus

unread,
Oct 25, 2017, 1:06:08 PM10/25/17
to VPython-users
Clicking on the button 'add E field' causes the programm to crash without giving an error. The relevant code can be found inside the gui class. https://github.com/Avedis-Neehus/3D-EM-Balls/blob/gui/3DEMtest.py

Bruce Sherwood

unread,
Oct 25, 2017, 9:17:30 PM10/25/17
to VPython-users
The problem is this:

from vpython import *

def make_text():
    print('make_text')
    T = text(text='abc')
    print(T.text)

#make_text() # this works
button(bind=make_text, text='Try') # text creation fails when clicked

I don't know what causes this, though it has to be related to the fact that creating a 3D text object requires a kind of wait state in Python to receive from the browser the final data on the text object (such as its length), before continuing to the next statement.

There is a very simple fix, which is to delete or comment out your large number of 3D text objects, none of which will be seen, because the default height is 1 but your scene is much larger than that.

Thanks for the report. It must be the case that no one up to now has tried to create a 3D text object inside a function that is bound to a mouse event.

Bruce

Bruce Sherwood

unread,
Oct 25, 2017, 9:19:30 PM10/25/17
to VPython-users
For completeness I should add that the bug is not present in GlowScript VPython, where there is no wait state when a 3D text object is created, because everything is in the browser.

Bruce

Bruce Sherwood

unread,
Oct 25, 2017, 9:28:03 PM10/25/17
to VPython-users
The VPython 7 bug is present not only for 3D text but also for compound and extrusion (all of these have to wait for information from the browser).

Bruce

Avedis Neehus

unread,
Oct 26, 2017, 9:34:40 AM10/26/17
to vpytho...@googlegroups.com
I just noticed that what I actually wanted to use is wtext() not text() so the bug doesn't affect my programm . By the way, is it possible to use the space to the right of the animation?

2017-10-26 3:28 GMT+02:00 Bruce Sherwood <bruce.s...@gmail.com>:
The VPython 7 bug is present not only for 3D text but also for compound and extrusion (all of these have to wait for information from the browser).

Bruce

--
You received this message because you are subscribed to a topic in the Google Groups "VPython-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vpython-users/V07QLK3QdHc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bruce Sherwood

unread,
Oct 26, 2017, 11:13:19 AM10/26/17
to VPython-users
Yes, see the "align" attribute at


Bruce

Russell Kramer

unread,
Apr 10, 2018, 11:03:38 PM4/10/18
to VPython-users
Has this issue been fixed for compound or extrusion objects or is there a work around?

I have a program https://github.com/northcoastmountainrat/Sitchensis that plots complex 3d trees.
Documented Issue #14 therein is related to this problem... I think. 

I want to include all the code in the MainBodyScript.py file into a main() function so I can call it from the command line and pass some arguments that control its output. 
When I do this none of the widgets work any longer. They work fine if I leave the MainBodyScript as it is. 

Thank you, 
Russell Kramer

Bruce Sherwood

unread,
Apr 11, 2018, 3:35:58 PM4/11/18
to VPython-users
I tried the following in Spyder and it works correctly:

from vpython import *
box(pos=vec(-1,0,0))

def make_text():
    print('make_text')
    T = text(text='abc')
    s = sphere(pos=vec(1,-1,0), radius=0.2, color=color.red)
    c = cone(pos=vec(1,-1,0), radius=0.1, color=color.cyan)
    cmp = compound([s,c], pos=vec(-1,1,0))
    print(T.text)

button(bind=make_text, text='Try')

Russell Kramer

unread,
Apr 12, 2018, 5:36:38 PM4/12/18
to VPython-users
My structure is actually slightly different, all the code is in the function so it can be called from the command line. In your example it would look like this:

def main():

   
def make_text():
       
print('make_text')
        T
= text(text='abc')
        s
= sphere(pos=vec(1,-1,0), radius=0.2, color=color.red)
        c
= cone(pos=vec(1,-1,0), radius=0.1, color=color.cyan)
        cmp
= compound([s,c], pos=vec(-1,1,0))
       
print(T.text)
    button
(bind=make_text, text='Try')


if __name__ == "__main__":
    main
()


Then in the setup.py file there is an entry point that calls main.

setup( ... entry_points = { 'console_scripts': ['run_tree=folder.script:main'], } ... )

then from the command line:

python main

This outputs the figure but no working widgets. 

Bruce Sherwood

unread,
Apr 13, 2018, 9:05:01 PM4/13/18
to VPython-users
I don't understand your setup stuff, but the following program behaves as expected when running from Spyder:

from vpython import *
Reply all
Reply to author
Forward
0 new messages