From f321312a64315bf533d6600213fe2ed70d8658f1 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Mon, 2 Dec 2013 02:40:21 +0100 Subject: [PATCH] Fixed code & image question display --- windows.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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"]))