Signaling to show ButtonReaders what is going on

This commit is contained in:
Sebastian Lohff 2013-12-18 01:44:52 +01:00
parent b1c8f7b368
commit 11ef399213
4 changed files with 45 additions and 5 deletions

View File

@ -30,6 +30,24 @@ class BaseInput(QtCore.QThread):
if self._app.activeWindow():
QtCore.QCoreApplication.postEvent(self._app.activeWindow(), ButtonEvent(int(btn)))
@QtCore.Slot(bool)
def buzzersOpen(self, isOpen):
""" Called when buzzers are opened or closed for answering
isOpen - True if question got opened, False if closed
"""
#print("Buzzers are now " + ("open" if isOpen else "closed"))
pass
@QtCore.Slot(int)
def playerGotQuestion(self, playerNo):
""" Called when a player got its turn to answer the question
playerNo - number (int) of player which can answer (starting from 1)
"""
#print("player %d can answer now" % playerNo)
pass
class SerialThread(QtCore.QThread):
dataReady = QtCore.Signal(str)

View File

@ -7,11 +7,12 @@ from windows import QuestionWindow, EditAnswersWindow, PlayerStartWindow, Victor
from gamestate import QuestionAnswers
class SeopardyGame(QtGui.QWidget):
def __init__(self, questions, gamestate, parent=None):
def __init__(self, questions, gamestate, inputs, parent=None):
super(SeopardyGame, self).__init__(parent)
self.questions = questions
self.gamestate = gamestate
self.inputs = inputs
#self.players = [Player.gen_player(i, parent=self) for i in range(1, 4)]
self.players = self.gamestate.get_players()
if len(self.players) == 0:
@ -175,8 +176,14 @@ class SeopardyGame(QtGui.QWidget):
dj = (dwin.get_player(), dwin.get_chosen_points())
qwin = QuestionWindow(self.players, section, number, question, answers, dj, self)
for inp in self.inputs:
qwin.buzzersOpen.connect(inp.buzzersOpen)
qwin.playerGotQuestion.connect(inp.playerGotQuestion)
qwin.showFullScreen()
qwin.exec_()
for inp in self.inputs:
qwin.buzzersOpen.disconnect(inp.buzzersOpen)
qwin.playerGotQuestion.disconnect(inp.playerGotQuestion)
self._inOtherWindow = False

View File

@ -88,7 +88,7 @@ if __name__ == '__main__':
inputs[-1].start()
# create board
board = SeopardyGame(questions, gamestate)
board = SeopardyGame(questions, gamestate, inputs)
board.show()
app.exec_()
sys.exit()

View File

@ -7,6 +7,9 @@ from music import MusicBox
from player import Player, ButtonEvent, nobodyColor
class QuestionWindow(QtGui.QDialog):
buzzersOpen = QtCore.Signal(bool)
playerGotQuestion = QtCore.Signal(int)
def __init__(self, players, section, qnumber, question, answers=None, dj=None, parent=None):
super(QuestionWindow, self).__init__(parent)
@ -15,6 +18,9 @@ class QuestionWindow(QtGui.QDialog):
self.qnumber = qnumber
self.question = question
self.dj = dj
self._windowSetup = False
if answers is not None:
self.answers = answers
else:
@ -43,6 +49,7 @@ class QuestionWindow(QtGui.QDialog):
def closeEvent(self, event):
if not self._inWindow:
self.buzzersOpen.emit(False)
MusicBox.stop_music()
event.accept()
else:
@ -103,6 +110,7 @@ class QuestionWindow(QtGui.QDialog):
self._inWindow = True
player = self.players[e.get_playerno()-1]
qawin = QuestionAnswerWindow(player, self)
self.playerGotQuestion.emit(e.get_playerno())
res = qawin.exec_()
if res == QuestionAnswerWindow.CORRECT:
self.answers.add_try(player, correct=True)
@ -113,12 +121,19 @@ class QuestionWindow(QtGui.QDialog):
self.answers.add_try(player, correct=False)
self._inWindow = False
if self.question["Type"] == "Music" and not done:
# restart music if question was not answered
MusicBox.play_music("%s-%s" % (self.section, self.qnumber))
if not done:
self.buzzersOpen.emit(True)
if self.question["Type"] == "Music":
# restart music if question was not answered
MusicBox.play_music("%s-%s" % (self.section, self.qnumber))
return True
else:
if not self._windowSetup and e.type() == QtCore.QEvent.Show:
if not self.answers.is_answered():
self.buzzersOpen.emit(True)
self._windowSetup = True
return super(QuestionWindow, self).event(e)
def keyPressEvent(self, e):