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.
I hope someone can shed some light on this issue for me. So if I have a valid reference to an ui element such as (ui.Button). So btn = ui.button(title='button1'). If I do btn.send_to_back() , it works as expected. But it seems when I have added btn as a sub_view() to another .View in a class, the send_to_back() method is ignored. I would have thought given I have the object reference, regardless where it lives in the z order, or View.sub_views(), it would work the same. The syntax does not fail, just no effect when btn added to a view using add_subview() . It's driving me crazy!
Btw, other attributes /methods working ok when accessed by obj.method/attribute
Those functions works to order components within a view. I.e, if you have a hierarchy like
Root +........viewA | +---------button1 |. +---------button2 | +-------viewB +--------button3
Then calling send to back on button1 changes z order within ViewA, but if you want to move ViewA behind ViewB, you'd have to call it on viewA
Thanks @JonB. I will look at it. Your diagram/explanation is the behaviour I expected. However, I am creating a lot of objects from dicts , **kwargs etc... Possible I went wrong. I was sure I was within the same subview. Maybe I wasn't. Thanks
I'll also point out that when you call
add_subview, the added view gets added on top of everything else. So add things from back to front, and only use
send_to_backwhen you need to change z order dynamically .
Yeah, @JonB, maybe I am missing something here. Just trying to create an enclosing class/View and then add the ui elements to the enclosing class. So all my subsequent attribute settings for ui GUI elements are relative to the enclosing class (view) for most part is working as expected, but the send_to_back() method does not seem to behave correctly. I am trying to rework my code in a simpler fashion, to be sure I am not doing the wrong thing. When I simplify my code I will post it. Again thanks
If your vie is not doing anything special, a regular old View works fine as a panel type class.
@JonB, yeah, I jumped the gun again. I can see now with a simple implementation it works (.send_to_back()) . Where it all went wrong for me I think is the mis-understanding of the coordinate system. (frame, bounds, left, right, x,y etc...) but my so called panel, is just a ui.View. Again thanks for your help.
import ui class panel(ui.View): def __init__(self, parent_view): parent_view.add_subview(self) self.frame = parent_view.frame self.height = 100 self.background_color = 'navy' self.panel_objects =  def add_button(self, title): btn = ui.Button(title=title) btn.x ,btn.y = 5,5 btn.height , btn.width = 32,100 btn.background_color = 'white' btn.action = self.send_to_back self.add_subview(btn) self.panel_objects.append(btn) def send_to_back(self, sender): sender.send_to_back() if __name__ == '__main__': v = ui.View(name ='main', frame=(0,0,540,576)) p = panel(v) p.add_button('ok') p.add_button('cancel') v.present('sheet')