Return from run Scene
I am trying to implement animation to a discrete event simulation package, which I have running already in a CPython environment with tkinter.
The main program looks like:
In these simulate routines, the simulation runs and presents an animation.
Under Pythonista, I could put Run(MyScene()) in the simulate routine, but then I don't know how to return to the calling program, in order to give a second run command.
Is there any possibility to stop the scene and return to the caller?
Okay, this is probably a very brute force way, but
the idea is to run the scene in a sceneview, and have your calling script blocked by a threading.Event. The calling script can "burp" the scene by setting the
tilltime via attribute access in the scene, and waits for the event to be set. Control is returned to the caller via the Event inside update, which checks if the simtime has gone too far.
Exception handling is annoying, mainly because SceneView does not seem to properly call Scene.stop() when the scene actually stops! So you need to handle this via the containing view will_close.
This is ugly, but seems to work. Keep in mind, the scene continues to run even when the caller has control, but just is not advancing the simtime.... so update gets called at 60Hz...