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 QtCore, QtGui
|
||||||
from PySide import QtGui
|
from PySide import QtGui
|
||||||
|
|
||||||
|
from music import MusicBox
|
||||||
from question import Questions
|
from question import Questions
|
||||||
from gamestate import GameState
|
from gamestate import GameState
|
||||||
from game import SeopardyGame
|
from game import SeopardyGame
|
||||||
|
@ -51,6 +52,9 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
gamestate = GameState(args.savedir)
|
gamestate = GameState(args.savedir)
|
||||||
|
|
||||||
|
# init music box
|
||||||
|
MusicBox.init()
|
||||||
|
|
||||||
# create board
|
# create board
|
||||||
board = SeopardyGame(questions, gamestate)
|
board = SeopardyGame(questions, gamestate)
|
||||||
board.show()
|
board.show()
|
||||||
|
|
17
windows.py
17
windows.py
|
@ -3,6 +3,7 @@ from PySide import QtGui, QtCore
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from gamestate import QuestionAnswers
|
from gamestate import QuestionAnswers
|
||||||
|
from music import MusicBox
|
||||||
from player import Player, ButtonEvent, nobodyColor
|
from player import Player, ButtonEvent, nobodyColor
|
||||||
|
|
||||||
class QuestionWindow(QtGui.QDialog):
|
class QuestionWindow(QtGui.QDialog):
|
||||||
|
@ -13,13 +14,15 @@ class QuestionWindow(QtGui.QDialog):
|
||||||
self.section = section
|
self.section = section
|
||||||
self.qnumber = qnumber
|
self.qnumber = qnumber
|
||||||
self.question = question
|
self.question = question
|
||||||
|
self.dj = dj
|
||||||
if answers is not None:
|
if answers is not None:
|
||||||
self.answers = answers
|
self.answers = answers
|
||||||
else:
|
else:
|
||||||
self.answers = QuestionAnswers(self.section, self.qnumber)
|
self.answers = QuestionAnswers(self.section, self.qnumber)
|
||||||
|
|
||||||
self.dj = dj
|
if not self.answers.is_answered():
|
||||||
if self.dj and not self.answers.is_answered():
|
MusicBox.play_music("questionSong")
|
||||||
|
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
|
||||||
QtCore.QCoreApplication.postEvent(self, ButtonEvent(playerNo))
|
QtCore.QCoreApplication.postEvent(self, ButtonEvent(playerNo))
|
||||||
|
@ -31,6 +34,13 @@ class QuestionWindow(QtGui.QDialog):
|
||||||
def get_answers(self):
|
def get_answers(self):
|
||||||
return self.answers
|
return self.answers
|
||||||
|
|
||||||
|
def closeEvent(self, event):
|
||||||
|
if not self._inWindow:
|
||||||
|
MusicBox.stop_music()
|
||||||
|
event.accept()
|
||||||
|
else:
|
||||||
|
event.ignore()
|
||||||
|
|
||||||
def _mkQuestionLabel(self, text):
|
def _mkQuestionLabel(self, text):
|
||||||
question = QtGui.QLabel(text, alignment=QtCore.Qt.AlignCenter)
|
question = QtGui.QLabel(text, alignment=QtCore.Qt.AlignCenter)
|
||||||
question.setWordWrap(True)
|
question.setWordWrap(True)
|
||||||
|
@ -73,7 +83,8 @@ class QuestionWindow(QtGui.QDialog):
|
||||||
res = qawin.exec_()
|
res = qawin.exec_()
|
||||||
if res == QuestionAnswerWindow.CORRECT:
|
if res == QuestionAnswerWindow.CORRECT:
|
||||||
self.answers.add_try(player, correct=True)
|
self.answers.add_try(player, correct=True)
|
||||||
self.accept()
|
self._inWindow = False
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in New Issue