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.


    Mixing ui and scene

    Pythonista
    1
    1
    944
    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.
    • ccc
      ccc last edited by

      When you want to use both the ui and scene modules together, SceneViewer can act as a plug-compatible replacement for scene.run(). Of course, scene.gravity() no longer works but more on that in a follow up post.

      In your code, replace:

      scene.run(MyScene())
      #with...
      import ui
      SceneViewer(MyScene())
      
      class SceneViewer(ui.View):
          def __init__(self, in_scene):
              self.present('full_screen', hide_title_bar = True)
              scene_view = scene.SceneView(frame=self.frame)
              scene_view.scene = in_scene
              self.add_subview(scene_view)
              self.add_subview(self.close_button())
          
          def close_action(self, sender):
              self.close()
      
          def close_button(self):
              the_button = ui.Button(title='X')
              the_button.x = self.width - the_button.width
              the_button.y = the_button.height / 2
              the_button.action = self.close_action
              the_button.font=('<system-bold>', 20)
              return the_button
      
      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Powered by NodeBB Forums | Contributors