Thanks for the reply @Thaumaturge.
As to getting the code in question to be run, one way is to include it within your “MyApp” class, or within some code that’s executed by that class
That doesn’t really suit my design needs. I should have explained better. I have a reason for wanting to use panda3d as a visualization tool ran in the midst of a script. Similar to how one may want to generate a plot in the middle of a script with matplotlib, look at it via a pop up window, and then exit the window to continue the script.
Here is a more complex example that better illustrates what I’m working on.
In codebase.py
:
#! /usr/bin/env python
from math import pi, sin, cos
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
class Visualizer(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.scene = self.loader.loadModel("models/environment")
self.scene.reparentTo(self.render)
self.scene.setScale(0.25, 0.25, 0.25)
self.scene.setPos(-8, 42, 0)
self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
self.speed = None
def spinCameraTask(self, task):
angleDegrees = task.time * self.speed
angleRadians = angleDegrees * (pi / 180.0)
self.camera.setPos(20 * sin(angleRadians), -20 * cos(angleRadians), 3)
self.camera.setHpr(angleDegrees, 0, 0)
return Task.cont
def configure(self, speed):
self.speed = speed
def start(self):
self.run()
In script.py
:
#! /usr/bin/env python
import random
from codebase import Visualizer
interface = Visualizer()
def big_computation():
return random.randint(0, 50)
for i in range(10):
output = big_computation()
interface.configure(output)
interface.start()
If you run python script.py
, the panda3d window pops up upon the line of code interactive = Visualizer()
. Great. Then, after big_computation()
, the visualization is properly configured and started. In the Python interpreter, every time I press ctrl+c, the loop continues, the visualizer is reconfigured, and its all good. The problem is that I do not want to continue the loop via ctrl+c within the interpreter. Instead, I want to continue the loop via a key press within the panda3d app.