Forum Archive

ui.animate for nested class functions is really awkward

Webmaster4o

Say I have a class, in which I have the function animate(self) which does a bunch of actions and then animates something. It looks somehing like this:

def animate(self):
    def anim(self):
        self.subviews[0].frame=(10, 10, 100, 120)
    #Do stuff here
    ui.animate(anim(self), 1)

This doesn't work, because then it's not callable. Additionally, using self.anim doesn't work, because anim isn't in the main namespace of the class. I actually have to call

ui.animate(lambda: anim(self), 1)

This seems awkward... Am I missing something?

Webmaster4o

Wait... Answered my own question. anim doesn't need self as an argument, because it inherits this from the parent's namespace. I can use

def animate(self):
    def anim():
        self.subviews[0].frame=(10, 10, 100, 120)
    #Do stuff here
    ui.animate(anim, 1)