Fixed code & image question display
This commit is contained in:
parent
8d2205dd12
commit
f321312a64
16
windows.py
16
windows.py
|
@ -41,10 +41,13 @@ class QuestionWindow(QtGui.QDialog):
|
||||||
else:
|
else:
|
||||||
event.ignore()
|
event.ignore()
|
||||||
|
|
||||||
def _mkQuestionLabel(self, text):
|
def _mkQuestionLabel(self, text, monospaced=False):
|
||||||
question = QtGui.QLabel(text, alignment=QtCore.Qt.AlignCenter)
|
question = QtGui.QLabel(text, alignment=QtCore.Qt.AlignCenter)
|
||||||
question.setWordWrap(True)
|
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
|
return question
|
||||||
|
|
||||||
|
@ -66,6 +69,15 @@ class QuestionWindow(QtGui.QDialog):
|
||||||
pixmap = QtGui.QPixmap()
|
pixmap = QtGui.QPixmap()
|
||||||
pixmap.loadFromData(open(self.question["Question"]).read())
|
pixmap.loadFromData(open(self.question["Question"]).read())
|
||||||
qlabel.setPixmap(pixmap)
|
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:
|
else:
|
||||||
raise ValueError("%s is an unknown type for section %s question name %s" % (self.question["Type"], self.section, self.question["Name"]))
|
raise ValueError("%s is an unknown type for section %s question name %s" % (self.question["Type"], self.section, self.question["Name"]))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue