From http://zetcode.com/gui/pysidetutorial/thetetrisgame/