56 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
| from PySide import QtGui, QtCore
 | |
| 
 | |
| #class QuestionWindow(QtGui.QWidget):
 | |
| class QuestionWindow(QtGui.QDialog):
 | |
| 	def __init__(self, section, question, parent=None):
 | |
| 		super(QuestionWindow, self).__init__(parent)
 | |
| 
 | |
| 		self.section = section
 | |
| 		self.question = question
 | |
| 		self.results = []
 | |
| 
 | |
| 		self._setupGui()
 | |
| 		self.setWindowTitle("Seopardy")
 | |
| 
 | |
| 	def get_results(self):
 | |
| 		return self.results
 | |
| 
 | |
| 	def _mkQuestionLabel(self, text):
 | |
| 		question = QtGui.QLabel(text, alignment=QtCore.Qt.AlignCenter)
 | |
| 		question.setWordWrap(True)
 | |
| 		question.setStyleSheet("QLabel { font-size: 40px; }")
 | |
| 
 | |
| 		return question
 | |
| 
 | |
| 	def _setupGui(self):
 | |
| 		self.layout = QtGui.QVBoxLayout()
 | |
| 
 | |
| 		seclabel = QtGui.QLabel(self.section)
 | |
| 		seclabel.setStyleSheet("QLabel { font-size: 30px; }")
 | |
| 		self.layout.addWidget(seclabel, alignment=QtCore.Qt.AlignCenter)
 | |
| 		self.layout.addStretch()
 | |
| 
 | |
| 		qlabel = None
 | |
| 		if self.question["Type"] == "Text":
 | |
| 			qlabel = self._mkQuestionLabel(self.question["Question"])
 | |
| 			print(self.question["Question"])
 | |
| 		elif self.question["Type"] == "Music":
 | |
| 			qlabel = self._mkQuestionLabel("Listen...")
 | |
| 		elif self.question["Type"] == "Image":
 | |
| 			qlabel = QtGui.QLabel()
 | |
| 			pixmap = QtGui.QPixmap()
 | |
| 			pixmap.loadFromData(open(self.question["Question"]).read())
 | |
| 			qlabel.setPixmap(pixmap)
 | |
| 		else:
 | |
| 			raise ValueError("%s is an unknown type for section %s question name %s" % (self.question["Type"], self.section, self.question["Name"]))
 | |
| 
 | |
| 		self.layout.addWidget(qlabel)
 | |
| 		self.layout.addStretch()
 | |
| 
 | |
| 		self.setLayout(self.layout)
 | |
| 
 | |
| 	def keyPressEvent(self, e):
 | |
| 		print("question", e, e.key())
 | |
| 		if e.key() == QtCore.Qt.Key_Escape:
 | |
| 			self.close()
 |