.....
self.keymap=
{Qt.Key_Left: _board.tryLeft,
Qt.Key_Right: _board.tryRight,
Qt.Key_Up: _board.tryRorateCCW,
Qt.Key_Down: _board.tryRorateCCW,
Qt.Key_Space: _board.dropDown,
Qt.Key_D: _board.tryLineDown}
........
def keyPressEvent(self, event):
key = event.key()
if key == Qt.Key_Escape:
self.paused ^= True
elif not self.paused and key in self.keymap:
self.keymap[key]()
else:
super(Tetris, self).keyPressEvent(event)