Fixed code & image question display

master
Sebastian Lohff 11 years ago
parent 8d2205dd12
commit f321312a64

@ -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("<pre>"+"\n".join(code)+"</pre>", monospaced=True)
else:
raise ValueError("%s is an unknown type for section %s question name %s" % (self.question["Type"], self.section, self.question["Name"]))

Loading…
Cancel
Save