Yeah, sorry. I know this is a stupid question. I am having a very difficult time getting my head around it though. I have a very simple slide_in func to slide in a view. The view is created but hidden. That's fine. Then with manual activation it slides in (a button press). So far so good. What I have great difficulty doing is sliding out the view, and then closing it. Below I have put test code that does the simple slide in. I didn't include my various attempts to slide it out and close the view. Embarrassing 😱Seems like it should be so simple if you can get the slide in working. Keeping in mind, I don't want the view to slide out automatically, meaning that will triggered at some other time.
Any help appreciated, hate I can't figure it out myself.
'''
Pythonista Forum - @Phuket2
'''
import ui
def quick_button(p):
# p is the parent view
_inset = 60
btn = ui.Button(name='btn')
btn.frame = ui.Rect(0, 0, p.width, p.width ).inset(_inset, _inset)
btn.corner_radius = btn.width / 2
btn.center = p.bounds.center()
btn.title = 'Push Me'
btn.bg_color = 'cornflowerblue'
btn.tint_color = 'white'
btn.font = ('Arial Rounded MT Bold', 48)
p.add_subview(btn)
return btn
def slide_in(p, v, duration = .5, reverse = False, delay = 0 ):
v.x = p.width if not reverse else -p.width
def animation():
v.x = 0
ui.animate(animation, duration = duration , delay=delay)
class MyClassB(ui.View):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.bg_color = 'purple'
self.hidden = True
class MyClass(ui.View):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
f = (0, 0, self.width, 44)
cb = MyClassB(name = 'classb', frame = f)
self.add_subview(cb)
qb = quick_button(self)
qb.action = self.my_action
self.add_subview(qb)
def my_action(self, sender):
v = self['classb']
v.hidden = False
slide_in(self, self['classb'], reverse = False)
if __name__ == '__main__':
w, h = 600, 800
f = (0, 0, w, h)
mc = MyClass(frame=f, bg_color='white')
mc.present('sheet', animated=False)