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.


    Scene within ui

    Pythonista
    4
    9
    1934
    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.
    • red_shift
      red_shift last edited by

      I'm a Pythonista 3 and Python newcomer, so simpler answers are preferred...I'm wanting to display an n x n grid of cells within a ui which has some other fields and buttons. When any of the cells in the grid are touched, I'd like that cell to go from empty to filled or vice versa. I want to have an array that captures the content of each cell once the user is finished touching cells. Can someone provide some guidance on the best approach? I was assuming I'd have to define a scene within the ui view, but not clear on how these work since I don't want it to be full screen.

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

        Look at SceneView, which lets you define a scene within a View.

        Though in this case you could also just use an array of Button, or use a custom View class with custom touch_began and maybe touch_moved.

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

          Thanks for pointing me to SceneView. I'm now looking into using an array of SpriteNodes.

          1 Reply Last reply Reply Quote 0
          • mikael
            mikael @red_shift last edited by

            @red_shift, nothing in what you describe requires mixing scene and ui, and although mixing them is definitely possible, it seems borrowing trouble for your first project, as they have different coordinate systems and different operating logics.

            So I would pick one and concentrate on learning the subtleties of that one first.

            My take is that scene holds your hand a bit more, has better out-of-the-box animation capabilities and might be easier to start with, while ui is much more versatile and will serve you in more projects.

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

              Since he wanted text fields, ui is needed since scene does not offer text entry.. I would probably tend towards a custom ui.View in this case, because ui is more touch event based, whereas scene feels more heavy, with the built in runloop.

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

                @JonB I agree, I don't see any request of animation in his initial post, only touching buttons

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

                  Thanks to all for the comments and guidance. I had written a couple of scripts using the ui module already and felt pretty comfortable with it. Although an array of buttons would meet my needs, I did want to try combining ui and SceneView, mostly for learning purposes. So far I've managed to place a Custom view into my ui, and populate it with a scene that contains an array of cells, which are SpriteNodes textured as circles. Next it's figuring out how to capture the location of touches and process them to change the texture of the sprite at that location. I need to figure out the best way to translate from a view location to which is sprite located there.

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

                    Touch_began provides the touch object, and touch.location provides coordinates within the scene.

                    (I assume you are implementing touch handling within the scene object, using a custom scene, not a custom View).

                    Then, assuming you have your SpriteNodes stored in some attribute of your scene, you can use something like:

                    for b in self.grid:
                        if touch.location in b.bbox:
                             # do something....
                    
                    JonB 1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB @JonB last edited by

                      Rereading your last post make sure you implement your touch handling within the scene class, not the custom view. Getting coordinates converted from UI to scene can be a little tricky.

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