From: Young-Jin L. <yl...@ui...> - 2002-01-18 17:10:49
|
Hi, I found out why I didn't see the VPython simulation window except the first time. I set scene.exit to 0 because I wanted to close only the VPython simulation window rather than the whole application. I expected "scene.exit = 0" to a "REAL" clsoing, but apparently it is not. It seems like it just set scene.visible to "0". When I manually set "scene.visible" to "1" for later simulation, the VPython simulation window appeared. But VPython objects created in the previous simulation were still there. I tried to set all the spheres created in the previous simulation by setting them to None, it didn't work. Is there any way to clear all the objects in the scene when it is closed? Thanks. YJ # Button ID BT_START = 10 from wxPython.wx import * from wxPython.html import wxHtmlWindow from visual import * class CPFreeFall1D_InitialPane( wxHtmlWindow ): def __init__( self, parent, id, **kwargs ): wxHtmlWindow.__init__( self, parent, id, **kwargs ) wxButton( self, BT_START, "Start Simulation", wxPoint( 100, 100 ) ) EVT_BUTTON( self, BT_START, self.OnClickStart ) def OnClickStart( self, event ): # read the configuration file import ConfigParser cfg = ConfigParser.ConfigParser() cfg.read( 'freefall1d.cfg' ) self.startSimulation( cfg ) def startSimulation( self, cfg ): print 'start simulation' scene.width = scene.height = 500. scene.x = scene.y = 0 scene.forward = ( -0.2, -0.5, -1 ) scene.autoscale = 0 scene.userzoom = 0 scene.range = ( 15, 15, 15 ) scene.exit = 0 # only close the simulation window # clean up the previous simulation result, but it didn't work. for obj in scene.objects: if obj.__class__ == 'sphere': print obj obj = None # start an actual simulation scene.select() xmax = 10 dx = xmax / 5 grid = [] gravity = cfg.get( 'Characteristics', 'gravity' ) r = float( cfg.get( 'Characteristics', 'diameter' ) ) / 2 # make the scene visible # it should be done automatically, but it is not the case. # So I call it by myself. scene.visible = 1 for x in arange( -xmax, xmax+dx, dx ): grid.append( curve( pos = [(x, 0, -xmax), (x, 0, xmax)], color = ( .7, .7, .7 ) ) ) for z in arange( -xmax, xmax+dx, dx ): grid.append( curve( pos = [(-xmax, 0, z), (xmax, 0, z)], color = (.7, .7, .7) ) ) ball = sphere(pos=(0,8,0), radius=r, color=color.red) ball.selected = 0 ball.velocity = vector(0,-1,0) dt = 0.1 ballPosition = [] ballVelocity = [] t = [] currentT = 0 while ball.y > ball.radius: rate(10) ball.pos = ball.pos + ball.velocity*dt ball.velocity.y = ball.velocity.y - float(gravity)*dt wake = sphere( pos = ball.pos, radius = 0.1, color = color.blue ) t.append( currentT + dt ) ballPosition.append( ball.pos.y ) ballVelocity.append( ball.velocity.y ) currentT = currentT + dt print 'end simulation' |
From: Bruce S. <ba...@an...> - 2002-01-25 14:25:50
|
I gather from a later note that the issue isn't how to delete all the objects in a window (which would be to make them invisible, looping through scene.objects, not set them to None; see the section in the online documentation on deleting objects), but rather how to detect when the user has clicked the close box, for which I don't know a mechanism. Bruce Sherwood --On Friday, January 18, 2002 11:10 -0600 Young-Jin Lee <yl...@ui...> wrote: > When I manually set "scene.visible" to "1" for later simulation, the > VPython simulation window appeared. But VPython objects created in the > previous simulation were still there. > I tried to set all the spheres created in the previous simulation by > setting them to None, it didn't work. > Is there any way to clear all the objects in the scene when it is closed? |
From: David S. <dsc...@vi...> - 2002-01-25 15:15:45
|
You can simply check scene.visible in your main loop. When it becomes 0, the window has been closed. Then you have a choice of either removing each object as Bruce suggested, or just creating a new display window (with display()) and drawing new objects in that one. Dave > -----Original Message----- > From: vis...@li... > [mailto:vis...@li...] On > Behalf Of Bruce Sherwood > Sent: Friday, January 25, 2002 9:26 AM > To: vis...@li... > Subject: Re: [Visualpython-users] Repeating VPython > simulation multiple times > > > I gather from a later note that the issue isn't how to delete all the > objects in a window (which would be to make them invisible, > looping through > scene.objects, not set them to None; see the section in the online > documentation on deleting objects), but rather how to detect > when the user > has clicked the close box, for which I don't know a mechanism. > > Bruce Sherwood > > --On Friday, January 18, 2002 11:10 -0600 Young-Jin Lee > <yl...@ui...> > wrote: > > > When I manually set "scene.visible" to "1" for later > simulation, the > > VPython simulation window appeared. But VPython objects > created in the > > previous simulation were still there. I tried to set all > the spheres > > created in the previous simulation by setting them to None, > it didn't > > work. Is there any way to clear all the objects in the > scene when it > > is closed? > > > > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users > |