diff --git a/windows.py b/windows.py index bba5f0e..a1829cb 100644 --- a/windows.py +++ b/windows.py @@ -41,10 +41,13 @@ class QuestionWindow(QtGui.QDialog): else: event.ignore() - def _mkQuestionLabel(self, text): + def _mkQuestionLabel(self, text, monospaced=False): question = QtGui.QLabel(text, alignment=QtCore.Qt.AlignCenter) question.setWordWrap(True) - question.setStyleSheet("QLabel { font-size: 40px; }") + extra = "" + if monospaced: + extra += "font-family: monospace;" + question.setStyleSheet("QLabel { font-size: 40px; %s }" % (extra,)) return question @@ -66,6 +69,15 @@ class QuestionWindow(QtGui.QDialog): pixmap = QtGui.QPixmap() pixmap.loadFromData(open(self.question["Question"]).read()) qlabel.setPixmap(pixmap) + qlabel.setAlignment(QtCore.Qt.AlignCenter) + elif self.question["Type"] == "Code": + # to have this a) aligned but b) centered we "cheat" a bit with the spaces... + code = self.question["Question"].split("\n") + code = map(lambda x: x.replace("\t", " "), code) + maxLineLen = max(map(len, code)) + code = map(lambda x: x + ((maxLineLen-len(x))*" "), code) + + qlabel = self._mkQuestionLabel("
"+"\n".join(code)+"
", monospaced=True) else: raise ValueError("%s is an unknown type for section %s question name %s" % (self.question["Type"], self.section, self.question["Name"]))