Browse Source

Button events for PlayerStartWindow

Sebastian Lohff 6 years ago
parent
commit
9ea09888aa
2 changed files with 32 additions and 2 deletions
  1. 8
    0
      game.py
  2. 24
    2
      windows.py

+ 8
- 0
game.py View File

@@ -88,7 +88,15 @@ class SeopardyGame(QtGui.QWidget):
88 88
 			if not self._inOtherWindow:
89 89
 				self._inOtherWindow = True
90 90
 				x = PlayerStartWindow(self.players, self)
91
+				for inp in self.inputs:
92
+					inp.buttonEvent.connect(x.playerButtonPress)
93
+					x.buzzersOpen.connect(inp.buzzersOpen)
94
+					x.playerGotQuestion.connect(inp.playerGotQuestion)
91 95
 				x.exec_()
96
+				for inp in self.inputs:
97
+					inp.buttonEvent.disconnect(x.playerButtonPress)
98
+					x.buzzersOpen.disconnect(inp.buzzersOpen)
99
+					x.playerGotQuestion.disconnect(inp.playerGotQuestion)
92 100
 				self._inOtherWindow = False
93 101
 				self.gamestate.set_state("playing")
94 102
 				self.gamestate.save()

+ 24
- 2
windows.py View File

@@ -368,12 +368,16 @@ class KeyGrabber(QtCore.QObject):
368 368
 		return QtCore.QObject.eventFilter(self, obj, e)
369 369
 
370 370
 class PlayerStartWindow(QtGui.QDialog):
371
+	buzzersOpen = QtCore.Signal(bool)
372
+	playerGotQuestion = QtCore.Signal(int)
373
+
371 374
 	def __init__(self, players, parent):
372 375
 		super(PlayerStartWindow, self).__init__(parent)
373 376
 		self._players = players
374 377
 		self._parent = parent
375 378
 
376 379
 		self._playerLineEdits = []
380
+		self._windowSetup = False
377 381
 
378 382
 		self._setupGui()
379 383
 		self.show()
@@ -397,12 +401,22 @@ class PlayerStartWindow(QtGui.QDialog):
397 401
 					widget = layoutItem.widget()
398 402
 					widget.selectAll()
399 403
 					widget.setFocus()
404
+
405
+					self.playerGotQuestion.emit(e.get_playerno())
400 406
 			return True
401 407
 		else:
402
-			return super(PlayerStartWindow, self).event(e)
408
+			ret = super(PlayerStartWindow, self).event(e)
409
+
410
+			if not self._windowSetup and e.type() == QtCore.QEvent.WindowActivate:
411
+				self.buzzersOpen.emit(True)
412
+				self._windowSetup = True
413
+
414
+			return ret
415
+
403 416
 
404 417
 	def closeEvent(self, event):
405 418
 		MusicBox.stop_music()
419
+		self.buzzersOpen.emit(False)
406 420
 		event.accept()
407 421
 
408 422
 	def keyPressEvent(self, e):
@@ -438,9 +452,17 @@ class PlayerStartWindow(QtGui.QDialog):
438 452
 
439 453
 		edit = QtGui.QLineEdit(player.name, self)
440 454
 		edit.setStyleSheet("QLineEdit { font-size: 40px; }")
441
-		edit.editingFinished.connect(lambda widget=edit, player=player: player.change_name(edit.text()))
455
+		edit.editingFinished.connect(lambda widget=edit, player=player: self._playerDoneEditing(widget, player))
442 456
 		self.playerGrid.addWidget(edit, row, 1)
443 457
 
458
+	def _playerDoneEditing(self, widget, player):
459
+		player.change_name(widget.text())
460
+		self.buzzersOpen.emit(True)
461
+
462
+	@QtCore.Slot(int)
463
+	def playerButtonPress(self, no):
464
+		QtCore.QCoreApplication.postEvent(self, ButtonEvent(int(no)))
465
+
444 466
 
445 467
 class VictoryWindow(QtGui.QDialog):
446 468
 	def __init__(self, players, parent):

Loading…
Cancel
Save