Music questions are working now

This commit is contained in:
Sebastian Lohff 2013-12-02 02:46:33 +01:00
parent f321312a64
commit 649a714bb3
2 changed files with 20 additions and 2 deletions

View File

@ -18,6 +18,7 @@ class MusicBox(object):
@classmethod @classmethod
def add_music(clazz, name, media_path): def add_music(clazz, name, media_path):
if name not in clazz.media.iterkeys():
clazz.media[name] = phonon.Phonon.MediaSource(media_path) clazz.media[name] = phonon.Phonon.MediaSource(media_path)
@classmethod @classmethod

View File

@ -21,7 +21,9 @@ class QuestionWindow(QtGui.QDialog):
self.answers = QuestionAnswers(self.section, self.qnumber) self.answers = QuestionAnswers(self.section, self.qnumber)
if not self.answers.is_answered(): if not self.answers.is_answered():
if self.question["Type"] != "Music":
MusicBox.play_music("questionSong") MusicBox.play_music("questionSong")
if self.dj: if self.dj:
self.answers.set_dj_points(self.dj[1]) self.answers.set_dj_points(self.dj[1])
playerNo = self.players.index(self.dj[0])+1 playerNo = self.players.index(self.dj[0])+1
@ -31,6 +33,11 @@ class QuestionWindow(QtGui.QDialog):
self.setWindowTitle("Seopardy - %s - %d" % (section, qnumber*100)) self.setWindowTitle("Seopardy - %s - %d" % (section, qnumber*100))
self._inWindow = False self._inWindow = False
if self.question["Type"] == "Music":
tag = "%s-%s" % (self.section, self.qnumber)
MusicBox.add_music(tag, self.question["Question"])
MusicBox.play_music(tag)
def get_answers(self): def get_answers(self):
return self.answers return self.answers
@ -89,6 +96,10 @@ class QuestionWindow(QtGui.QDialog):
def event(self, e): def event(self, e):
if e.type() == ButtonEvent.eventType: if e.type() == ButtonEvent.eventType:
if e.get_playerno() <= len(self.players) and not self._inWindow: if e.get_playerno() <= len(self.players) and not self._inWindow:
done = False
if self.question["Type"] == "Music":
MusicBox.stop_music()
self._inWindow = True self._inWindow = True
player = self.players[e.get_playerno()-1] player = self.players[e.get_playerno()-1]
qawin = QuestionAnswerWindow(player, self) qawin = QuestionAnswerWindow(player, self)
@ -96,10 +107,16 @@ class QuestionWindow(QtGui.QDialog):
if res == QuestionAnswerWindow.CORRECT: if res == QuestionAnswerWindow.CORRECT:
self.answers.add_try(player, correct=True) self.answers.add_try(player, correct=True)
self._inWindow = False self._inWindow = False
done = True
self.close() self.close()
elif res == QuestionAnswerWindow.WRONG: elif res == QuestionAnswerWindow.WRONG:
self.answers.add_try(player, correct=False) self.answers.add_try(player, correct=False)
self._inWindow = False self._inWindow = False
if self.question["Type"] == "Music" and not done:
# restart music if question was not answered
MusicBox.play_music("%s-%s" % (self.section, self.qnumber))
return True return True
else: else:
return super(QuestionWindow, self).event(e) return super(QuestionWindow, self).event(e)