Transfer buttons from readers via signal/slot
This commit is contained in:
parent
8313b81529
commit
ccd22fc3c3
|
@ -7,8 +7,6 @@ import os
|
||||||
import serial
|
import serial
|
||||||
from PySide import QtCore
|
from PySide import QtCore
|
||||||
|
|
||||||
from player import ButtonEvent
|
|
||||||
|
|
||||||
_inputs = {}
|
_inputs = {}
|
||||||
|
|
||||||
def _add_input(inputType, inputClass):
|
def _add_input(inputType, inputClass):
|
||||||
|
@ -22,13 +20,14 @@ def get_input(inputType, args, app):
|
||||||
return _inputs[inputType](app, *args)
|
return _inputs[inputType](app, *args)
|
||||||
|
|
||||||
class BaseInput(QtCore.QThread):
|
class BaseInput(QtCore.QThread):
|
||||||
|
buttonEvent = QtCore.Signal(int)
|
||||||
|
|
||||||
def __init__(self, app, parent=None):
|
def __init__(self, app, parent=None):
|
||||||
super(BaseInput, self).__init__(parent)
|
super(BaseInput, self).__init__(parent)
|
||||||
self._app = app
|
self._app = app
|
||||||
|
|
||||||
def _sendButtonEvent(self, btn):
|
def _sendButtonEvent(self, btn):
|
||||||
if self._app.activeWindow():
|
self.buttonEvent.emit(int(btn))
|
||||||
QtCore.QCoreApplication.postEvent(self._app.activeWindow(), ButtonEvent(int(btn)))
|
|
||||||
|
|
||||||
@QtCore.Slot(bool)
|
@QtCore.Slot(bool)
|
||||||
def buzzersOpen(self, isOpen):
|
def buzzersOpen(self, isOpen):
|
||||||
|
|
2
game.py
2
game.py
|
@ -177,11 +177,13 @@ class SeopardyGame(QtGui.QWidget):
|
||||||
|
|
||||||
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:
|
for inp in self.inputs:
|
||||||
|
inp.buttonEvent.connect(qwin.playerButtonPress)
|
||||||
qwin.buzzersOpen.connect(inp.buzzersOpen)
|
qwin.buzzersOpen.connect(inp.buzzersOpen)
|
||||||
qwin.playerGotQuestion.connect(inp.playerGotQuestion)
|
qwin.playerGotQuestion.connect(inp.playerGotQuestion)
|
||||||
qwin.showFullScreen()
|
qwin.showFullScreen()
|
||||||
qwin.exec_()
|
qwin.exec_()
|
||||||
for inp in self.inputs:
|
for inp in self.inputs:
|
||||||
|
inp.buttonEvent.disconnect(qwin.playerButtonPress)
|
||||||
qwin.buzzersOpen.disconnect(inp.buzzersOpen)
|
qwin.buzzersOpen.disconnect(inp.buzzersOpen)
|
||||||
qwin.playerGotQuestion.disconnect(inp.playerGotQuestion)
|
qwin.playerGotQuestion.disconnect(inp.playerGotQuestion)
|
||||||
|
|
||||||
|
|
|
@ -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))):
|
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.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):
|
class QuestionAnswerWindow(QtGui.QDialog):
|
||||||
CORRECT = 1
|
CORRECT = 1
|
||||||
WRONG = 2
|
WRONG = 2
|
||||||
|
|
Loading…
Reference in New Issue