Browse Source

Unknown player handling with extra event

Sebastian Lohff 6 years ago
parent
commit
ca7ace68ba
2 changed files with 15 additions and 4 deletions
  1. 3
    2
      Readme.md
  2. 12
    2
      windows.py

+ 3
- 2
Readme.md View File

@@ -80,8 +80,9 @@ An input class has two functions which are called while a question is on
80 80
 display:
81 81
 
82 82
  - `buzzersOpen(isOpen)` is called, when the question is first displayed,
83
-    when the question is reopened after a false answer and when the question is
84
-	closed after either a correct answer or no answer at all.
83
+    when the question is reopened after a false answer, when the question is
84
+	closed after either a correct answer or no answer at all or when a
85
+	button for an unknown player was submitted.
85 86
 
86 87
  - `playerGotQuestion(playerNo)` is called, whenever a player pressed
87 88
     their button *and* got the turn to answer. Note that no extra

+ 12
- 2
windows.py View File

@@ -127,14 +127,24 @@ class QuestionWindow(QtGui.QDialog):
127 127
 						# restart music if question was not answered
128 128
 						MusicBox.play_music("%s-%s" % (self.section, self.qnumber))
129 129
 
130
+			elif e.get_playerno() > len(self.players) and not self._inWindow:
131
+				# unknown player! to not confuse certain devices we send a buttons open event
132
+				self.buzzersOpen.emit(True)
133
+				print("unknown player", e.get_playerno())
134
+
135
+
130 136
 			return True
131 137
 		else:
132
-			if not self._windowSetup and e.type() == QtCore.QEvent.Show:
138
+			ret =  super(QuestionWindow, self).event(e)
139
+
140
+			# we want to do this after the window has focus for the first time
141
+			if not self._windowSetup and e.type() == QtCore.QEvent.FocusIn:
133 142
 				if not self.answers.is_answered():
134 143
 					self.buzzersOpen.emit(True)
135 144
 				self._windowSetup = True
136 145
 
137
-			return super(QuestionWindow, self).event(e)
146
+			return ret
147
+
138 148
 
139 149
 	def keyPressEvent(self, e):
140 150
 		if e.key() == QtCore.Qt.Key_Escape:

Loading…
Cancel
Save