From 11ef399213e011f5662e0c0b90db1fcfea0c92d3 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Wed, 18 Dec 2013 01:44:52 +0100 Subject: [PATCH] Signaling to show ButtonReaders what is going on --- buttonreader.py | 18 ++++++++++++++++++ game.py | 9 ++++++++- seopardy.py | 2 +- windows.py | 21 ++++++++++++++++++--- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/buttonreader.py b/buttonreader.py index 54f9e20..53dd446 100644 --- a/buttonreader.py +++ b/buttonreader.py @@ -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) diff --git a/game.py b/game.py index e7d0f03..139bd78 100644 --- a/game.py +++ b/game.py @@ -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 diff --git a/seopardy.py b/seopardy.py index bd3bcbe..60e17c7 100755 --- a/seopardy.py +++ b/seopardy.py @@ -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() diff --git a/windows.py b/windows.py index 567ae6a..76f972b 100644 --- a/windows.py +++ b/windows.py @@ -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):