Button events for PlayerStartWindow
This commit is contained in:
parent
8baf7f05aa
commit
9ea09888aa
8
game.py
8
game.py
|
@ -88,7 +88,15 @@ class SeopardyGame(QtGui.QWidget):
|
||||||
if not self._inOtherWindow:
|
if not self._inOtherWindow:
|
||||||
self._inOtherWindow = True
|
self._inOtherWindow = True
|
||||||
x = PlayerStartWindow(self.players, self)
|
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_()
|
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._inOtherWindow = False
|
||||||
self.gamestate.set_state("playing")
|
self.gamestate.set_state("playing")
|
||||||
self.gamestate.save()
|
self.gamestate.save()
|
||||||
|
|
26
windows.py
26
windows.py
|
@ -368,12 +368,16 @@ class KeyGrabber(QtCore.QObject):
|
||||||
return QtCore.QObject.eventFilter(self, obj, e)
|
return QtCore.QObject.eventFilter(self, obj, e)
|
||||||
|
|
||||||
class PlayerStartWindow(QtGui.QDialog):
|
class PlayerStartWindow(QtGui.QDialog):
|
||||||
|
buzzersOpen = QtCore.Signal(bool)
|
||||||
|
playerGotQuestion = QtCore.Signal(int)
|
||||||
|
|
||||||
def __init__(self, players, parent):
|
def __init__(self, players, parent):
|
||||||
super(PlayerStartWindow, self).__init__(parent)
|
super(PlayerStartWindow, self).__init__(parent)
|
||||||
self._players = players
|
self._players = players
|
||||||
self._parent = parent
|
self._parent = parent
|
||||||
|
|
||||||
self._playerLineEdits = []
|
self._playerLineEdits = []
|
||||||
|
self._windowSetup = False
|
||||||
|
|
||||||
self._setupGui()
|
self._setupGui()
|
||||||
self.show()
|
self.show()
|
||||||
|
@ -397,12 +401,22 @@ class PlayerStartWindow(QtGui.QDialog):
|
||||||
widget = layoutItem.widget()
|
widget = layoutItem.widget()
|
||||||
widget.selectAll()
|
widget.selectAll()
|
||||||
widget.setFocus()
|
widget.setFocus()
|
||||||
|
|
||||||
|
self.playerGotQuestion.emit(e.get_playerno())
|
||||||
return True
|
return True
|
||||||
else:
|
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):
|
def closeEvent(self, event):
|
||||||
MusicBox.stop_music()
|
MusicBox.stop_music()
|
||||||
|
self.buzzersOpen.emit(False)
|
||||||
event.accept()
|
event.accept()
|
||||||
|
|
||||||
def keyPressEvent(self, e):
|
def keyPressEvent(self, e):
|
||||||
|
@ -438,9 +452,17 @@ class PlayerStartWindow(QtGui.QDialog):
|
||||||
|
|
||||||
edit = QtGui.QLineEdit(player.name, self)
|
edit = QtGui.QLineEdit(player.name, self)
|
||||||
edit.setStyleSheet("QLineEdit { font-size: 40px; }")
|
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)
|
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):
|
class VictoryWindow(QtGui.QDialog):
|
||||||
def __init__(self, players, parent):
|
def __init__(self, players, parent):
|
||||||
|
|
Loading…
Reference in New Issue