Clean MainWindow code, fix painter not ready bug.