Browse Source

Music questions are working now

Sebastian Lohff 6 years ago
parent
commit
649a714bb3
2 changed files with 20 additions and 2 deletions
  1. 2
    1
      music.py
  2. 18
    1
      windows.py

+ 2
- 1
music.py View File

@@ -18,7 +18,8 @@ class MusicBox(object):
18 18
 
19 19
 	@classmethod
20 20
 	def add_music(clazz, name, media_path):
21
-		clazz.media[name] = phonon.Phonon.MediaSource(media_path)
21
+		if name not in clazz.media.iterkeys():
22
+			clazz.media[name] = phonon.Phonon.MediaSource(media_path)
22 23
 
23 24
 	@classmethod
24 25
 	def play_music(clazz, name):

+ 18
- 1
windows.py View File

@@ -21,7 +21,9 @@ class QuestionWindow(QtGui.QDialog):
21 21
 			self.answers = QuestionAnswers(self.section, self.qnumber)
22 22
 
23 23
 		if not self.answers.is_answered():
24
-			MusicBox.play_music("questionSong")
24
+			if self.question["Type"] != "Music":
25
+				MusicBox.play_music("questionSong")
26
+
25 27
 			if self.dj:
26 28
 				self.answers.set_dj_points(self.dj[1])
27 29
 				playerNo = self.players.index(self.dj[0])+1
@@ -31,6 +33,11 @@ class QuestionWindow(QtGui.QDialog):
31 33
 		self.setWindowTitle("Seopardy - %s - %d" % (section, qnumber*100))
32 34
 		self._inWindow = False
33 35
 
36
+		if self.question["Type"] == "Music":
37
+			tag = "%s-%s" % (self.section, self.qnumber)
38
+			MusicBox.add_music(tag, self.question["Question"])
39
+			MusicBox.play_music(tag)
40
+
34 41
 	def get_answers(self):
35 42
 		return self.answers
36 43
 
@@ -89,6 +96,10 @@ class QuestionWindow(QtGui.QDialog):
89 96
 	def event(self, e):
90 97
 		if e.type() == ButtonEvent.eventType:
91 98
 			if e.get_playerno() <= len(self.players) and not self._inWindow:
99
+				done = False
100
+				if self.question["Type"] == "Music":
101
+					MusicBox.stop_music()
102
+
92 103
 				self._inWindow = True
93 104
 				player = self.players[e.get_playerno()-1]
94 105
 				qawin = QuestionAnswerWindow(player, self)
@@ -96,10 +107,16 @@ class QuestionWindow(QtGui.QDialog):
96 107
 				if res == QuestionAnswerWindow.CORRECT:
97 108
 					self.answers.add_try(player, correct=True)
98 109
 					self._inWindow = False
110
+					done = True
99 111
 					self.close()
100 112
 				elif res == QuestionAnswerWindow.WRONG:
101 113
 					self.answers.add_try(player, correct=False)
102 114
 				self._inWindow = False
115
+
116
+				if self.question["Type"] == "Music" and not done:
117
+					# restart music if question was not answered
118
+					MusicBox.play_music("%s-%s" % (self.section, self.qnumber))
119
+
103 120
 			return True
104 121
 		else:
105 122
 			return super(QuestionWindow, self).event(e)

Loading…
Cancel
Save