in discussion Forum Discussion / Help requests » Problem integrating VPython5 and PyQt4
I'm afraid this forum isn't read by many people. It would be better to post this to the VPython mailing list.
I'm afraid this forum isn't read by many people. It would be better to post this to the VPython mailing list.
The following code should show a PyQt4 form together with a VPython scene.
Using VPython3 it works correctly, while useing VPython5 it crashes.
Does anyone has experience on facing this problem?
I would be very grateful if anyone can help me.
from visual import * from PyQt4 import QtCore, QtGui import sys class MainWindow(QtGui.QMainWindow): def __init__(self): QtGui.QDialog.__init__(self) scene.visible = 1 b = box() app = QtGui.QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_())
replacing
scene.visible = 1
scene.visible = 0
Thanks in advance
Matteo
The SConstruct file has not been maintained is no longer relevant. Start by reading the file INSTALL.txt. It looks to me like maybe you're trying to build against Numeric, which is no longer supported, rather than numpy.
Hi all,
I've been playing around with VPython for a little less than a year now. I installed the package from the Debian packages and had great success. But some sort of update in the last week or so is causing a seg fault when even the examples are run. The bug has already been reported to the package maintainers.
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=539922
So I've tried building from source (5.11) after grabbing the .bz tarball, but I still get a seg fault.
Next I tried grabbing the latest (as of Aug. 14th) CVS files from Sourceforge for the vpython-core2 package to try to build. Does anyone know if this is where I should be starting?
I've got Python 2.5 installed, so I edited the SConstruct file to reflect this. I also added '/usr/include/libglademm-2.4' to the CPPPATH to pick up one of the include files that's buried a bit deeper on my system. However, I'm still getting errors.
In file included from src/python/num_util_impl_numeric.cpp:4:
include/python/num_util_impl.hpp:26: error: ‘array_types’ has not been declared
include/python/num_util_impl.hpp:27: error: ISO C++ forbids declaration of ‘array_types’ with no type
include/python/num_util_impl.hpp:27: warning: ‘array_types’ initialized and declared ‘extern’
include/python/num_util_impl.hpp:27: error: ‘type_impl’ was not declared in this scope
include/python/num_util_impl.hpp:27: error: expected ‘,’ or ‘;’ before ‘(’ token
include/python/num_util_impl.hpp:31: error: ‘array_types’ is not a type
src/python/num_util_impl_numeric.cpp:14: error: ‘NPY_TYPES cvisual::python::type’ redeclared as different kind of symbol
include/python/num_util.hpp:127: error: previous declaration of ‘NPY_TYPES cvisual::python::type(boost::python::numeric::array)’
src/python/num_util_impl_numeric.cpp:15: error: ‘array_types’ does not name a type
src/python/num_util_impl_numeric.cpp:16: error: ‘char cvisual::python::type2char’ redeclared as different kind of symbol
include/python/num_util.hpp:225: error: previous declaration of ‘char cvisual::python::type2char(NPY_TYPES)’
src/python/num_util_impl_numeric.cpp: In function ‘void cvisual::python::init_numeric_impl()’:
src/python/num_util_impl_numeric.cpp:33: error: ‘import_array’ was not declared in this scope
src/python/num_util_impl_numeric.cpp: At global scope:
src/python/num_util_impl_numeric.cpp:42: error: ‘NPY_TYPES cvisual::python::type’ redeclared as different kind of symbol
include/python/num_util.hpp:127: error: previous declaration of ‘NPY_TYPES cvisual::python::type(boost::python::numeric::array)’
src/python/num_util_impl_numeric.cpp:42: error: expected ‘)’ before ‘t’
src/python/num_util_impl_numeric.cpp:205: error: expected ‘}’ at end of input
src/python/num_util_impl_numeric.cpp:205: error: expected ‘}’ at end of input
scons: *** [src/python/num_util_impl_numeric.os] Error 1
scons: building terminated because of errors.
Has anyone see this or have suggestions so as to get VPython back up and running on my system?
Matt
There were several pending new member requests that had not been approved. They have all been approved now. Sorry for the delay.
Collision detection is essential but difficult to implement for mechanics simulations.
I modified the pyODE collision detection example to work with VPython.
You can create robots and artificial life by adding and animating pyODE joints between the blocks.
# pyODE example 3: Collision detection
# Originally by Matthias Baas.
# Modified by Miles Jacobs to make collision detection work with VPython.
# With thanks to http://python.matrix.jp/projects/pyogre/ode_test2.py.
import sys, os, random, time
from math import *
from visual import *
import ode
# geometric utility functions
def scalp (vec, scal):
vec[0] *= scal
vec[1] *= scal
vec[2] *= scal
def length (vec):
return sqrt (vec[0]**2 + vec[1]**2 + vec[2]**2)
# create_box
def create_box(world, space, density, lx, ly, lz):
"""Create a box body and its corresponding geom."""
# Create body
body = ode.Body(world)
M = ode.Mass()
M.setBox(density, lx, ly, lz)
body.setMass(M)
# Set parameters for drawing the body
body.shape = "box"
body.boxsize = (lx, ly, lz)
# Create a box geom for collision detection
geom = ode.GeomBox(space, lengths=body.boxsize)
geom.setBody(body)
return body
# drop_object
def drop_object():
"""Drop an object into the scene."""
global bodies, counter, objcount
body = create_box(world, space, 1000, 1.0,1.0,1.0)
body.setPosition((random.gauss(0,0.1),10.0,random.gauss(0,0.1)))
theta = random.uniform(0,2*pi)
ct = cos (theta)
st = sin (theta)
body.setRotation([ct, 0., -st, 0., 1., 0., st, 0., ct])
icecube = box(pos=body.getPosition(), axis=(ct,0.,st),length=1.0, height=1.0, width=1.0,
color=(random.gauss(0.1,1),random.gauss(0.1,1),random.gauss(0.1,1)))
bodies.append(body)
cubes.append(icecube)
counter=0
objcount+=1
# explosion
def explosion():
"""Simulate an explosion.
Every object is pushed away from the origin.
The force is dependent on the objects distance from the origin.
"""
global bodies
for b in bodies:
l=b.getPosition ()
d = length (l)
a = max(0, 800000*(1.0-0.2*d*d))
l = [l[0] / 4, l[1], l[2] /4]
scalp (l, a / length (l))
b.addForce(l)
# pull
def pull():
"""Pull the objects back to the origin.
Every object will be pulled back to the origin.
Every couple of frames there'll be a thrust upwards so that
the objects won't stick to the ground all the time.
"""
global bodies, counter
for b in bodies:
l=list (b.getPosition ())
scalp (l, -100000 / length (l))
b.addForce(l)
if counter%60==0:
b.addForce((0,100000,0))
# Collision callback
def near_callback(args, geom1, geom2):
"""Callback function for the collide() method.
This function checks if the given geoms do collide and
creates contact joints if they do.
"""
# Check if the objects do collide
contacts = ode.collide(geom1, geom2)
# Create contact joints
world,contactgroup = args
for c in contacts:
c.setBounce(0.2)
c.setMu(5000)
j = ode.ContactJoint(world, contactgroup, c)
j.attach(geom1.getBody(), geom2.getBody())
######################################################################
# Create a world object
world = ode.World()
world.setGravity( (0,-9.81,0) )
world.setERP(0.8)
world.setCFM(1E-5)
# Create a space object
space = ode.Space()
# Create a plane geom which prevent the objects from falling forever
floor = ode.GeomPlane(space, (0,1,0), 0)
ground=box(pos=(0,-0.1,0), width=20, height=0.1, length=20,
color=color.white)
# A list with ODE bodies and Visual objects to see the bodies
bodies = []
cubes = []
# A joint group for the contact joints that are generated whenever
# two bodies collide
contactgroup = ode.JointGroup()
# Some variables used inside the simulation loop
fps = 25
dt = 1.0/fps
running = True
state = 0
counter = 0
objcount = 0
scene.autoscale=0
scene.forward=(-5,-5,-5)
while(1):
global counter, state
counter += 1
if state==0:
if counter==20:
drop_object()
if objcount==10:
state=1
counter=0
# State 1: Explosion and pulling back the objects
elif state==1:
if counter==100:
explosion()
if counter>300:
pull()
if counter==500:
counter=20
for b in range(len(bodies)):
x,y,z = bodies[b].getPosition()
R = bodies[b].getRotation()
cubes[b].pos=(x,y,z)
cubes[b].axis=R[0], R[3], R[6]
cubes[b].up=R[1], R[4], R[7]
print state, counter
# Simulate
n = 2
for i in range(n):
# Detect collisions and create contact joints
space.collide((world,contactgroup), near_callback)
# Simulation step
world.step(dt/n)
# Remove all contact joints
contactgroup.empty()
rate(25)
Certainly looking forward to see what it will do.
Ah. thanks for the answer. I was mildly surprised when 2.6 came out, I didn't realize anything before 3.0 was planned.
I really like VPython, particularly in my intro. to comps. course. If I have to choose between 2.6 and Vpython, the choice is easy.
-Bob Montante
Indeed, the version of Visual has to have been built for a specific version of Python, and a mismatch cannot work. Just this week I worked a bit with Python 2.6 to see what the issues are going to be. There are some problems. The Boost libraries, which enhance C++, have to be built for a specific version of Python, and since there aren't yet available these binaries for 2.6, I built them from source. Similarly for numpy. Turns out that something has changed in these components, because there's now a type mismatch between numpy integers and Python integers (this is a simplified description). Moreover, for the new Visual about to be released, there's a problem with a native-mode version for the Mac because the Mac Python 2.6 has an IDLE that won't run!
Summary: There are various problems in the Python 2.6 world. But we'll be tracking them and looking for solutions. We would prefer to release the new Visual for Python 2.6, because the new Python builds a bridge between Python 2.5 and the coming Python 3.0, a version of Python that will actually break some existing programs. Python 2.6 offers tools to check on possible incompatibilities.
Bruce Sherwood
How can I use VPython w/ Python 2.6, in Windows? I tried the naive approach of running "VPython-Win-Py2.5-3.2.11.exe" —- it doesn't find the C:\Python_26 directory, and if I force it it still fails. Specifically, "bounce.py" fails with a complaint about not finding cvisual.pyd.
It's not a major problem for me (yet) since I still have Python v2.5.2 around, but I thought I'd ask.
Many thanks for setting this up.
Chris@wyleu
Hmm, attaching files doesn't seem to work well. Here's another approach, using the code feature to post it inline. In fact, with Python mode, it looks pretty nice.
from visual import * floor = box (pos=(0,0,0), length=4, height=0.5, width=4, color=color.blue) ball = sphere (pos=(0,4,0), radius=1, color=color.red) ball.velocity = vector(0,-1,0) dt = 0.01 while 1: rate (100) ball.pos = ball.pos + ball.velocity*dt if ball.y < ball.radius: ball.velocity.y = -ball.velocity.y else: ball.velocity.y = ball.velocity.y - 9.8*dt
The attached file is the sample program from www.vpython.org. (I see that the file type contents are incorrectly determined to be Java program text!)
I uploaded a file named sample.py to "this page", but can't seem to get a reference to it.