Question-Answer dialog
This commit is contained in:
parent
0692dc897d
commit
17b8ba4047
2
game.py
2
game.py
|
@ -62,7 +62,7 @@ class SeopardyGame(QtGui.QWidget):
|
|||
def tfunc(self, section, number):
|
||||
print("question window", section, number)
|
||||
|
||||
qwin = QuestionWindow(section, self.questions.get_question(section, number), self)
|
||||
qwin = QuestionWindow(self.players, section, number, self.questions.get_question(section, number), self)
|
||||
qwin.showFullScreen()
|
||||
qwin.exec_()
|
||||
|
||||
|
|
|
@ -3,3 +3,11 @@ from __future__ import print_function
|
|||
class GameState(object):
|
||||
def __init__(self, statefile=None):
|
||||
pass
|
||||
|
||||
class QuestionAnswer(object):
|
||||
def __init__(self, section, question, player, answerno, correct):
|
||||
self.section = section
|
||||
self.question = question
|
||||
self.player = player
|
||||
self.answerno = answerno
|
||||
self.correct = correct
|
||||
|
|
59
windows.py
59
windows.py
|
@ -1,11 +1,15 @@
|
|||
from PySide import QtGui, QtCore
|
||||
|
||||
from gamestate import QuestionAnswer
|
||||
|
||||
#class QuestionWindow(QtGui.QWidget):
|
||||
class QuestionWindow(QtGui.QDialog):
|
||||
def __init__(self, section, question, parent=None):
|
||||
def __init__(self, players, section, qnumber, question, parent=None):
|
||||
super(QuestionWindow, self).__init__(parent)
|
||||
|
||||
self.players = players
|
||||
self.section = section
|
||||
self.qnumber = qnumber
|
||||
self.question = question
|
||||
self.results = []
|
||||
|
||||
|
@ -53,3 +57,56 @@ class QuestionWindow(QtGui.QDialog):
|
|||
print("question", e, e.key())
|
||||
if e.key() == QtCore.Qt.Key_Escape:
|
||||
self.close()
|
||||
elif e.key() >= ord('1') and e.key() <= ord(str(len(self.players))):
|
||||
player = self.players[e.key() - ord('1')]
|
||||
qawin = QuestionAnswerWindow(player, self)
|
||||
res = qawin.exec_()
|
||||
if res == QuestionAnswerWindow.CORRECT:
|
||||
print("Done!")
|
||||
q = QuestionAnswer(self.section, self.qnumber, player, len(self.results)+1, True)
|
||||
self.results.append(q)
|
||||
self.accept()
|
||||
elif res == QuestionAnswerWindow.WRONG:
|
||||
q = QuestionAnswer(self.section, self.qnumber, player, len(self.results)+1, False)
|
||||
self.results.append(q)
|
||||
|
||||
class QuestionAnswerWindow(QtGui.QDialog):
|
||||
CORRECT = 1
|
||||
WRONG = 2
|
||||
OOPS = 3
|
||||
|
||||
def __init__(self, player, parent=None):
|
||||
super(QuestionAnswerWindow, self).__init__(parent)
|
||||
self.player = player
|
||||
|
||||
self._setupGui()
|
||||
|
||||
# move window to bottom right of screen
|
||||
g = QtGui.QApplication.desktop().screenGeometry()
|
||||
self.show()
|
||||
cPos = self.rect()
|
||||
self.move(g.width() - cPos.width(), g.height() - cPos.height())
|
||||
|
||||
|
||||
def _setupGui(self):
|
||||
self.layout = QtGui.QVBoxLayout()
|
||||
|
||||
self.plabel = QtGui.QLabel(self.player.name)
|
||||
self.plabel.setStyleSheet("QLabel { font-size: 60px; }")
|
||||
self.layout.addWidget(self.plabel, alignment=QtCore.Qt.AlignCenter)
|
||||
|
||||
btnbox = QtGui.QHBoxLayout()
|
||||
right = QtGui.QPushButton("Correct")
|
||||
right.clicked.connect(lambda: self.done(self.CORRECT))
|
||||
btnbox.addWidget(right)
|
||||
wrong = QtGui.QPushButton("Wrong")
|
||||
wrong.clicked.connect(lambda: self.done(self.WRONG))
|
||||
btnbox.addWidget(wrong)
|
||||
btnbox.addStretch()
|
||||
oops = QtGui.QPushButton("Oops")
|
||||
oops.clicked.connect(lambda: self.done(self.OOPS))
|
||||
btnbox.addWidget(oops)
|
||||
self.layout.addLayout(btnbox)
|
||||
|
||||
self.setLayout(self.layout)
|
||||
|
||||
|
|
Loading…
Reference in New Issue