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.
Layout callback in custom view classes
-
@omz, I know you are busy, but I have sort of mentioned this before, but not as a topic on its own. But the layout callback method when you create a custom class that inherits from ui.View, gets 2 callbacks when a view loads. I normally have to make another class member and store the last screen size to avoid a single redundant call to layout. Maybe there is a good reason it's called twice and a better way to avoid executing the layout code twice.
It's not a big deal, but worth mentioning for 1.6 if it is indeed a redundant call. -
Or the old MadonnaView workaround...
import ui class MadonnaView(ui.View): def __init__(self): self.first_time = True def layout(self): if self.first_time: self.first_time = False return
-
Thanks @ccc. Was really about pointing that it happens so it could be addressed in 1.6 if it has not been already.
I still use the screen size to check, just in case double calls made in different circumstances. -
s/Madona/Madonna @ccc :-)
-
phuket, do you have a simple example that calls layout twice? i tried with the most basic example, and thst doesn't happen...
perhaps you are setting the frame after you instantiate (rather than within the constructor)?
-
Well done @ccc : Now my comment makes no sense. :-)
-
@JonB, you are right. I wasn't setting the h,w in the init method, but inside the layout method. And maybe this was my misunderstanding about presenting a sheet. I thought I had to do that before to be device independent. If I presented a view using sheet, I had no idea what the resulting size would be on different screen sizes. ( I remember a long time ago, I asked about this here).
I can see with 1.6, you can look at the screen size and determine what you want your view size to be before you call your class to present. Of course, this is only an issue with presenting with a sheet. As you can control the exact size of your sheet view with 1.6, no reason why the size of the view can't be set in the init method.I hope what I said is correct. My mind is spinning. I did so many tests. But if the view is sized in the init method, no double layout calls. Makes sense.