Button events for PlayerStartWindow

This commit is contained in:
Sebastian Lohff 2013-12-19 18:42:08 +01:00
parent 8baf7f05aa
commit 9ea09888aa
2 changed files with 32 additions and 2 deletions

View File

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

View File

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