omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Return from run Scene

    Pythonista
    2
    2
    1592
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • upwart
      upwart last edited by

      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:
      ...
      simulate(till=200)
      ...
      simulate(till=300)
      print('the end')

      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?

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        Okay, this is probably a very brute force way, but
        https://gist.github.com/4ea25e2c88579efd030319e920466a0b

        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 till time 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...

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Powered by NodeBB Forums | Contributors