Animated Grid Layout

Require PyMT 0.4

import random
from pymt import *

class MTAnimatedGridLayout(MTGridLayout):
    def reposition_child(self, child, pos=None, size=None):
        if pos:
            child.do(Animation(f='ease_out_cubic', pos=pos))
        if size:
            child.size = size


class TestWidget(MTWidget):
    _id = 0
    def __init__(self, **kwargs):
        super(TestWidget, self).__init__(**kwargs)
        TestWidget._id += 1
        self.label = str(TestWidget._id)
        self.color = map(lambda x: random.random(), xrange(3))
        self.size = map(lambda x: random.randint(50, 100), xrange(2))
    def draw(self):
        set_color(*self.color)
        drawRectangle(pos=self.pos, size=self.size)
        drawLabel(pos=self.pos, center=False, label=self.label)

if __name__ == '__main__':

    # create a grid + 50 children
    grid = MTAnimatedGridLayout(cols=8)
    for i in xrange(50):
        grid.add_widget(TestWidget())

    # Every second, bring the first children to front
    def bring(*largs):
        grid.children[0].bring_to_front()
    getClock().schedule_interval(bring, 1)

    # Run !
    runTouchApp(grid)