Signaling to show ButtonReaders what is going on
This commit is contained in:
parent
b1c8f7b368
commit
11ef399213
|
@ -30,6 +30,24 @@ class BaseInput(QtCore.QThread):
|
||||||
if self._app.activeWindow():
|
if self._app.activeWindow():
|
||||||
QtCore.QCoreApplication.postEvent(self._app.activeWindow(), ButtonEvent(int(btn)))
|
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):
|
class SerialThread(QtCore.QThread):
|
||||||
dataReady = QtCore.Signal(str)
|
dataReady = QtCore.Signal(str)
|
||||||
|
|
||||||
|
|
9
game.py
9
game.py
|
@ -7,11 +7,12 @@ from windows import QuestionWindow, EditAnswersWindow, PlayerStartWindow, Victor
|
||||||
from gamestate import QuestionAnswers
|
from gamestate import QuestionAnswers
|
||||||
|
|
||||||
class SeopardyGame(QtGui.QWidget):
|
class SeopardyGame(QtGui.QWidget):
|
||||||
def __init__(self, questions, gamestate, parent=None):
|
def __init__(self, questions, gamestate, inputs, parent=None):
|
||||||
super(SeopardyGame, self).__init__(parent)
|
super(SeopardyGame, self).__init__(parent)
|
||||||
|
|
||||||
self.questions = questions
|
self.questions = questions
|
||||||
self.gamestate = gamestate
|
self.gamestate = gamestate
|
||||||
|
self.inputs = inputs
|
||||||
#self.players = [Player.gen_player(i, parent=self) for i in range(1, 4)]
|
#self.players = [Player.gen_player(i, parent=self) for i in range(1, 4)]
|
||||||
self.players = self.gamestate.get_players()
|
self.players = self.gamestate.get_players()
|
||||||
if len(self.players) == 0:
|
if len(self.players) == 0:
|
||||||
|
@ -175,8 +176,14 @@ class SeopardyGame(QtGui.QWidget):
|
||||||
dj = (dwin.get_player(), dwin.get_chosen_points())
|
dj = (dwin.get_player(), dwin.get_chosen_points())
|
||||||
|
|
||||||
qwin = QuestionWindow(self.players, section, number, question, answers, dj, self)
|
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.showFullScreen()
|
||||||
qwin.exec_()
|
qwin.exec_()
|
||||||
|
for inp in self.inputs:
|
||||||
|
qwin.buzzersOpen.disconnect(inp.buzzersOpen)
|
||||||
|
qwin.playerGotQuestion.disconnect(inp.playerGotQuestion)
|
||||||
|
|
||||||
self._inOtherWindow = False
|
self._inOtherWindow = False
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ if __name__ == '__main__':
|
||||||
inputs[-1].start()
|
inputs[-1].start()
|
||||||
|
|
||||||
# create board
|
# create board
|
||||||
board = SeopardyGame(questions, gamestate)
|
board = SeopardyGame(questions, gamestate, inputs)
|
||||||
board.show()
|
board.show()
|
||||||
app.exec_()
|
app.exec_()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
17
windows.py
17
windows.py
|
@ -7,6 +7,9 @@ from music import MusicBox
|
||||||
from player import Player, ButtonEvent, nobodyColor
|
from player import Player, ButtonEvent, nobodyColor
|
||||||
|
|
||||||
class QuestionWindow(QtGui.QDialog):
|
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):
|
def __init__(self, players, section, qnumber, question, answers=None, dj=None, parent=None):
|
||||||
super(QuestionWindow, self).__init__(parent)
|
super(QuestionWindow, self).__init__(parent)
|
||||||
|
|
||||||
|
@ -15,6 +18,9 @@ class QuestionWindow(QtGui.QDialog):
|
||||||
self.qnumber = qnumber
|
self.qnumber = qnumber
|
||||||
self.question = question
|
self.question = question
|
||||||
self.dj = dj
|
self.dj = dj
|
||||||
|
|
||||||
|
self._windowSetup = False
|
||||||
|
|
||||||
if answers is not None:
|
if answers is not None:
|
||||||
self.answers = answers
|
self.answers = answers
|
||||||
else:
|
else:
|
||||||
|
@ -43,6 +49,7 @@ class QuestionWindow(QtGui.QDialog):
|
||||||
|
|
||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
if not self._inWindow:
|
if not self._inWindow:
|
||||||
|
self.buzzersOpen.emit(False)
|
||||||
MusicBox.stop_music()
|
MusicBox.stop_music()
|
||||||
event.accept()
|
event.accept()
|
||||||
else:
|
else:
|
||||||
|
@ -103,6 +110,7 @@ class QuestionWindow(QtGui.QDialog):
|
||||||
self._inWindow = True
|
self._inWindow = True
|
||||||
player = self.players[e.get_playerno()-1]
|
player = self.players[e.get_playerno()-1]
|
||||||
qawin = QuestionAnswerWindow(player, self)
|
qawin = QuestionAnswerWindow(player, self)
|
||||||
|
self.playerGotQuestion.emit(e.get_playerno())
|
||||||
res = qawin.exec_()
|
res = qawin.exec_()
|
||||||
if res == QuestionAnswerWindow.CORRECT:
|
if res == QuestionAnswerWindow.CORRECT:
|
||||||
self.answers.add_try(player, correct=True)
|
self.answers.add_try(player, correct=True)
|
||||||
|
@ -113,12 +121,19 @@ class QuestionWindow(QtGui.QDialog):
|
||||||
self.answers.add_try(player, correct=False)
|
self.answers.add_try(player, correct=False)
|
||||||
self._inWindow = False
|
self._inWindow = False
|
||||||
|
|
||||||
if self.question["Type"] == "Music" and not done:
|
if not done:
|
||||||
|
self.buzzersOpen.emit(True)
|
||||||
|
if self.question["Type"] == "Music":
|
||||||
# restart music if question was not answered
|
# restart music if question was not answered
|
||||||
MusicBox.play_music("%s-%s" % (self.section, self.qnumber))
|
MusicBox.play_music("%s-%s" % (self.section, self.qnumber))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
else:
|
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)
|
return super(QuestionWindow, self).event(e)
|
||||||
|
|
||||||
def keyPressEvent(self, e):
|
def keyPressEvent(self, e):
|
||||||
|
|
Loading…
Reference in New Issue