WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   quit an embedded viz-simulation (https://forum.worldviz.com/showthread.php?t=1906)

levisii 03-13-2009 11:10 AM

quit an embedded viz-simulation
 
hi there,

i was creating a frame with wxPython. from this frame i started an embedded viz-simulation. so far it works quite well. (i found everything i need here. thanks for that ;) )

but if i try to close this simulation and start it again form the mainFrame, the new simulation is just gray. the problem is that i am not able to call the viz.quit() function to clean up. as you can see in the code i was testing the function calls by printouts.
the viz.EXIT_EVENT is not executed before i close the wxPython mainFrame.
my onKeyDown() function does the test print as it should be done, but it ignores the viz.quit() without an error.
i hope you can help me.

here is my code:

#wxFrame class
import viz
import wx
import ducks #this is my testsimulation

class MainFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)

#Menubar
menubar = wx.MenuBar()
worldViz = wx.Menu()
...
worldViz.Append(104, '&Simulation', 'Start a 3D-simulation')
self.SetMenuBar(menubar)
wx.EVT_MENU(self, 104, self.onStart3D)
...

def onStart3D(self, event):
self.timer = wx.Timer(self, 5000) #timer to refresh the simulation
self.timer.Start(10)
wx.EVT_TIMER(self, 5000, self.onTimer)

self.sim = viz.go(viz.EMBEDDED)
test = ducks.simulation()

def onTimer(self, event):
viz.updateframe()



#my testsimulation class
import viz

def simulation():
viz.clearcolor(0.5, 0.5, 1.0)

#Set ViewPoint
view = viz.MainView
view.setPosition(0, 1, -20)

#Turn on the physics engine
viz.phys.enable()

#Add ground
ground = viz.add('tut_ground.wrl')
ground.collidePlane()

...

#Exit-function
def onkeydown(key): #exit the simulation if you press 1
if key == '1':
print 'test'
viz.quit()

viz.callback(viz.KEYDOWN_EVENT, onkeydown)

def onexit():
print 'onexit executed'
viz.quit()

viz.callback(viz.EXIT_EVENT, onexit)



#this is the starting class
import wx
from MainFrame import *

class MainApp(wx.App):
def OnInit(self):
frame = MainFrame(None,-1, 'Phantom')
frame.Show(True)
return True

app = MainApp(0)
app.MainLoop()
del app

farshizzo 03-13-2009 11:40 AM

Please repost the code using the [code][/code] tags. This will preserve the indentation which is need to run Python code.

levisii 03-14-2009 04:17 AM

oh, i'm sorry. first time i'm posting here :rolleyes:
i've splitted my code to one files per class, but if you run this, it is showing my problem:

Code:

import viz, wx

#This class implements the GUI-Frame
class MainFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)

        #Menubar
        menubar        = wx.MenuBar()
        worldViz        = wx.Menu()
        worldViz.Append(104, '&Simulation', 'Start a 3D-simulation')
        menubar.Append(worldViz, '&WorldViz')
        self.SetMenuBar(menubar)
        self.CreateStatusBar()

        wx.EVT_MENU(self, 104, self.onStart3D)

    #calls the embedded simulation
    def onStart3D(self, event):
        self.timer = wx.Timer(self, 5000)  #Timer for updating the frames
        self.timer.Start(10)
        wx.EVT_TIMER(self, 5000, self.onTimer)

        viz.go(viz.EMBEDDED)
        simulation()

    #Manuel FrameUpdate
    def onTimer(self, event):
        viz.updateframe()
       
#this is my test simulation
def simulation():
    viz.clearcolor(0.5, 0.5, 1.0)

    #Set ViewPoint
    view = viz.MainView
    view.setPosition(0, 1, -20)

    #Turn on the physics engine
    viz.phys.enable()

    #Add ground
    ground = viz.add('tut_ground.wrl')
    ground.collidePlane()

#Exit-function
def onkeydown(key):
    if key == '1':
        print 'onKeyDown() executed'
        viz.quit()

viz.callback(viz.KEYDOWN_EVENT, onkeydown)

def onexit():
    print'onExit() executed'
    viz.quit()

viz.callback(viz.EXIT_EVENT, onexit)


#this is the starting class
class MainApp(wx.App):
        def OnInit(self):
                frame = MainFrame(None,-1, 'Phantom')
                frame.Show(True)
                return True

app = MainApp(0)
app.MainLoop()
del app


levisii 03-20-2009 08:34 AM

Hello? Can anybody help me?

farshizzo 03-24-2009 11:21 AM

Are you trying to exit your entire application when the key is pressed, or just close the Vizard window?

If you are trying to exit the entire app, then you need to call the Close() method of your MainFrame class.

If you want to just close the Vizard window, then this is not possible. You can only call viz.go() once, so you can only create a single Vizard window for the duration of your script. To deal with this limitation you can create the Vizard window during startup and make the window visible/hidden to simulate creating/destroying the window.

levisii 04-01-2009 03:39 AM

Thank you very mutch for this information. It helps me a lot. I try to exit the Vizard window and create another one while the main frame is running. But I will handle this by antoher way.


All times are GMT -7. The time now is 05:01 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC