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.


    Two overlaying Views with two different layout methods is this doable?

    Pythonista
    2
    17
    9385
    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.
    • brumm
      brumm last edited by brumm

      I wanted to write a framework (or sth. like that) for drawing projects, but I got stucked. In this framework I have a background view for showing scaled pictures in the original ratio and also a overlay view for touch events. The layout method in overlay view is only called three times at the start. The image in the background view works the whole time. The red frame (view2.frame) should be the area where touch events are accepted (but it doesn't resizes because of the none working overlay method).

      Here you can find the code.

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

        Found a solution. Update will follow soon...

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

          Okay, just uploaded the new/working version. I hope it's useful for your next drawing project.

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

            Looks like there's another issue with the two draw methods in BGView and OLView :(.
            Only BGView.image.draw() works, while OLView.view2.path.stroke() doesn't work.
            picture
            pathtest
            Any ideas?

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

              Could it be that two custom views with different draw methods aren't supported? If I send the path to the (working) background view I can "draw" the path via path.stroke(). I thought/hoped that I can use the overlay view not only for touch events...

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

                perhaps you have forgotten to set the color?

                Also, have you verified you have a path?

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

                  actually, looks like you forgot to turn off touch_enabled for BGView and view2. The way you have it, OLView is nit the overlay, view2 is, since it is added as a subview.

                  also, i think view2 needs to be an imageview for the way you are trying to do this.

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

                    I checked both, but no path is visible. To see if there is a path I used self.view2.image.show() and it looked good.

                        def draw(self):
                            if self.view2.path:
                                ui.set_color('black')
                                self.view2.path.stroke()
                                self.view2.set_needs_display()
                    
                    1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB last edited by

                      self.set_needs_display()

                      you are not drawing to view2, you are drawing on self.

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

                        I'm very astonished as I set touch_enabled = False, because even if I set two or all three views to False, I still get a path (but I can't see it in view2 only via image.show()).

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

                          also. ciew2 needs to be an ImageView!

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

                            self.set_needs_display()
                            doesn't make a change. Need some time to rewrite the code (your suggestion with the imageview). Btw. is it also transparent? And thank you so much for your help.

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

                              Once again thank you so much. The ImageView() did the trick.

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

                                I would think that that image stays transparent, but have not tried it. you should simply be able to change View to ImageView, but I have not downloaded the code to try.

                                A different refactoring would have an overlay on top of an imageview on top of a bgview. It is strange that your drawing layer is essentially the back, thus is covered up by the bgview

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

                                  I only use the bgview for scaling the loaded picture (camera_roll) in a custom view to the max. view size and allow the layout change. The imageview is used for the touch event and I also want to store the overlay image (the path) for further processing.

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

                                    seems to me that the OLView is being used for the touch event and drawing the current path,while the ImageView just to keep the path from growing infinitely long.

                                    If you eventually implement different colors for example, your approach will notice that you are drawing behind the existing lines, because the draw happens on the root view rather than in an overlay, at least until touch_ended

                                    See
                                    https://github.com/jsbain/RoomAreaFinder/blob/master/floorplanarea.py
                                    for something similar to what you are doing, except that there is an explicit Overlay view which handles the touch and drawing and is presented on top.

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

                                      You really saved my day! I will update my code...
                                      Stopped this project. See instead DrawOnImage

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