From ccd22fc3c3355f541e126ea5ae13d546c17f5fa6 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Thu, 19 Dec 2013 18:07:06 +0100 Subject: [PATCH] Transfer buttons from readers via signal/slot --- buttonreader.py | 7 +++---- game.py | 2 ++ windows.py | 5 +++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/buttonreader.py b/buttonreader.py index 53dd446..436a697 100644 --- a/buttonreader.py +++ b/buttonreader.py @@ -7,8 +7,6 @@ import os import serial from PySide import QtCore -from player import ButtonEvent - _inputs = {} def _add_input(inputType, inputClass): @@ -22,13 +20,14 @@ def get_input(inputType, args, app): return _inputs[inputType](app, *args) class BaseInput(QtCore.QThread): + buttonEvent = QtCore.Signal(int) + def __init__(self, app, parent=None): super(BaseInput, self).__init__(parent) self._app = app def _sendButtonEvent(self, btn): - if self._app.activeWindow(): - QtCore.QCoreApplication.postEvent(self._app.activeWindow(), ButtonEvent(int(btn))) + self.buttonEvent.emit(int(btn)) @QtCore.Slot(bool) def buzzersOpen(self, isOpen): diff --git a/game.py b/game.py index 139bd78..1a04241 100644 --- a/game.py +++ b/game.py @@ -177,11 +177,13 @@ class SeopardyGame(QtGui.QWidget): qwin = QuestionWindow(self.players, section, number, question, answers, dj, self) for inp in self.inputs: + inp.buttonEvent.connect(qwin.playerButtonPress) qwin.buzzersOpen.connect(inp.buzzersOpen) qwin.playerGotQuestion.connect(inp.playerGotQuestion) qwin.showFullScreen() qwin.exec_() for inp in self.inputs: + inp.buttonEvent.disconnect(qwin.playerButtonPress) qwin.buzzersOpen.disconnect(inp.buzzersOpen) qwin.playerGotQuestion.disconnect(inp.playerGotQuestion) diff --git a/windows.py b/windows.py index 76f972b..c9a6283 100644 --- a/windows.py +++ b/windows.py @@ -144,6 +144,11 @@ class QuestionWindow(QtGui.QDialog): elif not self.answers.is_answered() and e.key() >= ord('1') and e.key() <= ord(str(len(self.players))): QtCore.QCoreApplication.postEvent(self, ButtonEvent(int(chr(e.key())))) + @QtCore.Slot(int) + def playerButtonPress(self, no): + QtCore.QCoreApplication.postEvent(self, ButtonEvent(int(no))) + + class QuestionAnswerWindow(QtGui.QDialog): CORRECT = 1 WRONG = 2