Music playback backend now present
This commit is contained in:
parent
d26c7a3a88
commit
645745ed7c
|
@ -0,0 +1,35 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
from PySide import phonon
|
||||
|
||||
class MusicBox(object):
|
||||
# default media
|
||||
media = {}
|
||||
|
||||
# state
|
||||
_media_obj = None
|
||||
|
||||
@classmethod
|
||||
def init(clazz):
|
||||
clazz._output = phonon.Phonon.AudioOutput(phonon.Phonon.MusicCategory)
|
||||
clazz._media_obj = phonon.Phonon.MediaObject()
|
||||
phonon.Phonon.createPath(clazz._media_obj, clazz._output)
|
||||
|
||||
@classmethod
|
||||
def add_music(clazz, name, media_path):
|
||||
clazz.media[name] = phonon.Phonon.MediaSource(media_path)
|
||||
|
||||
@classmethod
|
||||
def play_music(clazz, name):
|
||||
try:
|
||||
clazz._media_obj.setCurrentSource(clazz.media[name])
|
||||
clazz._media_obj.play()
|
||||
except KeyError:
|
||||
print("Warning: Song '%s' is missing, not found in media base" % (name,), file=sys.stderr)
|
||||
|
||||
@classmethod
|
||||
def stop_music(clazz):
|
||||
# use pause so we don't stop having the device open
|
||||
clazz._media_obj.pause()
|
||||
|
|
@ -7,6 +7,7 @@ import sys
|
|||
#from PySide import QtCore, QtGui
|
||||
from PySide import QtGui
|
||||
|
||||
from music import MusicBox
|
||||
from question import Questions
|
||||
from gamestate import GameState
|
||||
from game import SeopardyGame
|
||||
|
@ -51,6 +52,9 @@ if __name__ == '__main__':
|
|||
else:
|
||||
gamestate = GameState(args.savedir)
|
||||
|
||||
# init music box
|
||||
MusicBox.init()
|
||||
|
||||
# create board
|
||||
board = SeopardyGame(questions, gamestate)
|
||||
board.show()
|
||||
|
|
17
windows.py
17
windows.py
|
@ -3,6 +3,7 @@ from PySide import QtGui, QtCore
|
|||
import copy
|
||||
|
||||
from gamestate import QuestionAnswers
|
||||
from music import MusicBox
|
||||
from player import Player, ButtonEvent, nobodyColor
|
||||
|
||||
class QuestionWindow(QtGui.QDialog):
|
||||
|
@ -13,13 +14,15 @@ class QuestionWindow(QtGui.QDialog):
|
|||
self.section = section
|
||||
self.qnumber = qnumber
|
||||
self.question = question
|
||||
self.dj = dj
|
||||
if answers is not None:
|
||||
self.answers = answers
|
||||
else:
|
||||
self.answers = QuestionAnswers(self.section, self.qnumber)
|
||||
|
||||
self.dj = dj
|
||||
if self.dj and not self.answers.is_answered():
|
||||
if not self.answers.is_answered():
|
||||
MusicBox.play_music("questionSong")
|
||||
if self.dj:
|
||||
self.answers.set_dj_points(self.dj[1])
|
||||
playerNo = self.players.index(self.dj[0])+1
|
||||
QtCore.QCoreApplication.postEvent(self, ButtonEvent(playerNo))
|
||||
|
@ -31,6 +34,13 @@ class QuestionWindow(QtGui.QDialog):
|
|||
def get_answers(self):
|
||||
return self.answers
|
||||
|
||||
def closeEvent(self, event):
|
||||
if not self._inWindow:
|
||||
MusicBox.stop_music()
|
||||
event.accept()
|
||||
else:
|
||||
event.ignore()
|
||||
|
||||
def _mkQuestionLabel(self, text):
|
||||
question = QtGui.QLabel(text, alignment=QtCore.Qt.AlignCenter)
|
||||
question.setWordWrap(True)
|
||||
|
@ -73,7 +83,8 @@ class QuestionWindow(QtGui.QDialog):
|
|||
res = qawin.exec_()
|
||||
if res == QuestionAnswerWindow.CORRECT:
|
||||
self.answers.add_try(player, correct=True)
|
||||
self.accept()
|
||||
self._inWindow = False
|
||||
self.close()
|
||||
elif res == QuestionAnswerWindow.WRONG:
|
||||
self.answers.add_try(player, correct=False)
|
||||
self._inWindow = False
|
||||
|
|
Loading…
Reference in New Issue