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.


    UI launching a scene

    Pythonista
    3
    4
    3006
    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.
    • chriswilson
      chriswilson last edited by

      Hi all,

      I have made a game (which I have posted about before) using the scene module.

      I am trying to get a pyui file to launch the scene. After some trial and error I managed it like this:

      import ui
      from black_white import *
      from time import sleep
      from scene import run
      
      @ui.in_background
      def start(sender):
      	run(Game(), show_fps=False)
      	
      v = ui.load_view()
      v.present('sheet', hide_title_bar = True)
      

      black_white is the name of the script running my scene Game.

      I could only get it to work by running the scene 'inside' the UI. I had to import time.sleep and scene.runas my script needs them, which seems quite messy. When I try to close the UI view v at the end of the start function, everything closes!

      Does anyone know of a better way to do this?

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

        You might be able to use a SceneView. Maybe it's just me, but I couldn't understand your question clearly. So this might not be the answer. But oh well.

        You can create a SceneView:

        sv = ui.SceneView()
        

        Add your scene as a parameter of "sv", then use

        main_view.add_subview(sv)
        

        in your function.
        Your button calls the function, the just clear the main_view and call the line above.

        1 Reply Last reply Reply Quote 1
        • brumm
          brumm last edited by brumm

          Here you can find an example PhotoTextV2.
          It's a ui.View with two scrollviews. One for buttons and another one for the scene.SceneView.

          edit: Have you tried ui.delay instead of time.sleep?

          1 Reply Last reply Reply Quote 1
          • chriswilson
            chriswilson last edited by

            @jbap @brumm
            Thanks for your replies. I'm going to try to implement that.

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