From 649a714bb38ae2e31cef5d840425c0afc77f595e Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Mon, 2 Dec 2013 02:46:33 +0100 Subject: [PATCH] Music questions are working now --- music.py | 3 ++- windows.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/music.py b/music.py index fc949e1..9892135 100644 --- a/music.py +++ b/music.py @@ -18,7 +18,8 @@ class MusicBox(object): @classmethod def add_music(clazz, name, media_path): - clazz.media[name] = phonon.Phonon.MediaSource(media_path) + if name not in clazz.media.iterkeys(): + clazz.media[name] = phonon.Phonon.MediaSource(media_path) @classmethod def play_music(clazz, name): diff --git a/windows.py b/windows.py index a1829cb..7a08627 100644 --- a/windows.py +++ b/windows.py @@ -21,7 +21,9 @@ class QuestionWindow(QtGui.QDialog): self.answers = QuestionAnswers(self.section, self.qnumber) if not self.answers.is_answered(): - MusicBox.play_music("questionSong") + if self.question["Type"] != "Music": + MusicBox.play_music("questionSong") + if self.dj: self.answers.set_dj_points(self.dj[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._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): return self.answers @@ -89,6 +96,10 @@ class QuestionWindow(QtGui.QDialog): def event(self, e): if e.type() == ButtonEvent.eventType: if e.get_playerno() <= len(self.players) and not self._inWindow: + done = False + if self.question["Type"] == "Music": + MusicBox.stop_music() + self._inWindow = True player = self.players[e.get_playerno()-1] qawin = QuestionAnswerWindow(player, self) @@ -96,10 +107,16 @@ class QuestionWindow(QtGui.QDialog): if res == QuestionAnswerWindow.CORRECT: self.answers.add_try(player, correct=True) self._inWindow = False + done = True self.close() elif res == QuestionAnswerWindow.WRONG: self.answers.add_try(player, correct=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 else: return super(QuestionWindow, self).event(e)