@omz, sorry to bring this up again. I can image it drives you crazy sometimes :). But anyway.....
I wanted to ask is there any real reason that any ui.View cant have its own update function. I sort of forgot about this thread and started out to make a still dismissing btn today. The crude attempt is below. When I could see it was not working the way I expected, I remembered this thread and found it. I tried to follow @enceladus example, but realised he was adding a update method to a custom class. In the below, I want my created button to look after itself. In this case just thinking about a modal case where if there is no user interaction you want the process to continue after a set timeout.
Why is it important? At first I thought, hmmm so many other ways to do this. But I think is not so clean if you would like to make a reusable ui Item for others. Then I started to think about other use cases. Eg. a textfield updating itself using requests to get a exchange rate. But the beauty would be in if it could be coded in one function using closures. Then the consumer of the "control" only needs to know some pertinent params. The control could be presented without a host container (superview) and still work.
Anyway, I am not trying to be stupid for stupid sake! I can just see some cool possibilities for ppl to create some interesting reusable ui controls that are self contained.
After all that, I have no idea if its a feasible idea or not. I mean the ability to have all your controls to be able to have its own update method (callback). Personally I would say it is feasible after the tests I did with a lot of customviews in a table all having their own update methods.
Anyway, it's just an idea. I can just see the merit in it.
import ui
import types
def auto_button(time_out_secs=1, *args, **kwargs):
'''
Incomplete attempt at getting something other than a Custom View
to have its own update event
'''
btn = None
def myupdate():
'''
here we might change the btns title in x secs. Could then call the
btn's action. eg, might close a view that is blocked by ui.wait_modal.
'''
print('In Update')
btn = ui.Button(**kwargs)
btn.update = types.MethodType(myupdate, btn)
btn.update_interval = 1
return btn
class MyClass(ui.View):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.make_view()
def make_view(self):
btn = auto_button(title='Continue',
width=100,
height=32,
bg_color='white',
corner_radius=6,
)
btn.center = self.center
self.add_subview(btn)
if __name__ == '__main__':
f = (0, 0, 300, 400)
v = MyClass(frame=f, bg_color='teal')
v.present(style='sheet')