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?
-
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.
-
Found a solution. Update will follow soon...
-
Okay, just uploaded the new/working version. I hope it's useful for your next drawing project.
-
-
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...
-
perhaps you have forgotten to set the color?
Also, have you verified you have a path?
-
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.
-
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()
-
self.set_needs_display()
you are not drawing to view2, you are drawing on self.
-
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()).
-
also. ciew2 needs to be an ImageView!
-
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. -
Once again thank you so much. The ImageView() did the trick.
-
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
-
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.
-
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. -
You really saved my day! I will update my code...
Stopped this project. See instead DrawOnImage