Transfer buttons from readers via signal/slot

This commit is contained in:
Sebastian Lohff 2013-12-19 18:07:06 +01:00
parent 8313b81529
commit ccd22fc3c3
3 changed files with 10 additions and 4 deletions

View File

@ -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):

View File

@ -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)

View File

@ -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