From 9ea09888aab428d6533d274541a2b760e7e38e7a Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Thu, 19 Dec 2013 18:42:08 +0100 Subject: [PATCH] Button events for PlayerStartWindow --- game.py | 8 ++++++++ windows.py | 26 ++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/game.py b/game.py index 1a04241..be40389 100644 --- a/game.py +++ b/game.py @@ -88,7 +88,15 @@ class SeopardyGame(QtGui.QWidget): if not self._inOtherWindow: self._inOtherWindow = True x = PlayerStartWindow(self.players, self) + for inp in self.inputs: + inp.buttonEvent.connect(x.playerButtonPress) + x.buzzersOpen.connect(inp.buzzersOpen) + x.playerGotQuestion.connect(inp.playerGotQuestion) x.exec_() + for inp in self.inputs: + inp.buttonEvent.disconnect(x.playerButtonPress) + x.buzzersOpen.disconnect(inp.buzzersOpen) + x.playerGotQuestion.disconnect(inp.playerGotQuestion) self._inOtherWindow = False self.gamestate.set_state("playing") self.gamestate.save() diff --git a/windows.py b/windows.py index e4e747e..e1d1fe4 100644 --- a/windows.py +++ b/windows.py @@ -368,12 +368,16 @@ class KeyGrabber(QtCore.QObject): return QtCore.QObject.eventFilter(self, obj, e) class PlayerStartWindow(QtGui.QDialog): + buzzersOpen = QtCore.Signal(bool) + playerGotQuestion = QtCore.Signal(int) + def __init__(self, players, parent): super(PlayerStartWindow, self).__init__(parent) self._players = players self._parent = parent self._playerLineEdits = [] + self._windowSetup = False self._setupGui() self.show() @@ -397,12 +401,22 @@ class PlayerStartWindow(QtGui.QDialog): widget = layoutItem.widget() widget.selectAll() widget.setFocus() + + self.playerGotQuestion.emit(e.get_playerno()) return True else: - return super(PlayerStartWindow, self).event(e) + ret = super(PlayerStartWindow, self).event(e) + + if not self._windowSetup and e.type() == QtCore.QEvent.WindowActivate: + self.buzzersOpen.emit(True) + self._windowSetup = True + + return ret + def closeEvent(self, event): MusicBox.stop_music() + self.buzzersOpen.emit(False) event.accept() def keyPressEvent(self, e): @@ -438,9 +452,17 @@ class PlayerStartWindow(QtGui.QDialog): edit = QtGui.QLineEdit(player.name, self) edit.setStyleSheet("QLineEdit { font-size: 40px; }") - edit.editingFinished.connect(lambda widget=edit, player=player: player.change_name(edit.text())) + edit.editingFinished.connect(lambda widget=edit, player=player: self._playerDoneEditing(widget, player)) self.playerGrid.addWidget(edit, row, 1) + def _playerDoneEditing(self, widget, player): + player.change_name(widget.text()) + self.buzzersOpen.emit(True) + + @QtCore.Slot(int) + def playerButtonPress(self, no): + QtCore.QCoreApplication.postEvent(self, ButtonEvent(int(no))) + class VictoryWindow(QtGui.QDialog): def __init__(self, players, parent):