105 lines
3.1 KiB
Python
Executable File
105 lines
3.1 KiB
Python
Executable File
#!/usr/bin/python
|
|
|
|
# Licensed under GPLv3
|
|
# Written by Sebastian Lohff (seba@someserver.de)
|
|
# http://seba-geek.de/projects/seopardy/
|
|
|
|
from __future__ import print_function
|
|
|
|
import argparse
|
|
import yaml
|
|
import sys
|
|
from PySide import QtGui, QtCore
|
|
|
|
from music import MusicBox
|
|
from question import Questions, QuestionException
|
|
from gamestate import GameState
|
|
from game import SeopardyGame
|
|
from config import check_config
|
|
from buttonreader import get_input, InputException
|
|
|
|
def _parser():
|
|
parser = argparse.ArgumentParser(description="Sebas jeopardy/beopardy clone")
|
|
parser.add_argument("--gamestate", action="store", default=None, help="Gamestate to load to recover a crashed game")
|
|
parser.add_argument("--conf", action="store", default="seopardy.conf", help="Path to config file")
|
|
parser.add_argument("--no-cwd", action="store_true", default=False, help="Do not change working directory to question folder")
|
|
parser.add_argument("-v", "--verbose", action="store_true", default=False, help="Be more verbose, print filenames of missing files")
|
|
parser.add_argument("questions", action="store", help="Path to questionfile")
|
|
|
|
return parser
|
|
|
|
if __name__ == '__main__':
|
|
parser = _parser()
|
|
args = parser.parse_args()
|
|
|
|
questions = None
|
|
try:
|
|
questions = Questions(args.questions, appendPath=not args.no_cwd, verbose=args.verbose)
|
|
except QuestionException as e:
|
|
print(e.message, file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
# start gui
|
|
app = QtGui.QApplication([sys.argv[0]])
|
|
QtCore.QCoreApplication.setApplicationName("Seopardy")
|
|
|
|
# check and load config file
|
|
config = None
|
|
try:
|
|
config = yaml.safe_load(open(args.conf))
|
|
except IOError as e:
|
|
print("Error: Could not load config: %s" % (e,), file=sys.stderr)
|
|
sys.exit(1)
|
|
except yaml.scanner.ScannerError as e:
|
|
print("Error: Could not parse config file: %s" % (e,), file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
check_config(config)
|
|
|
|
# create or load gamestate
|
|
gamestate = None
|
|
if args.gamestate:
|
|
sstream = None
|
|
try:
|
|
sstream = open(args.gamestate, "r")
|
|
except IOError as e:
|
|
print("Error: Could not load gamestate: %s" % (e,), file=sys.stderr)
|
|
sys.exit(1)
|
|
gamestate = GameState.load(sstream, config["savedir"])
|
|
else:
|
|
gamestate = GameState(config["savedir"])
|
|
|
|
# init music box
|
|
MusicBox.init()
|
|
for name, path in config["music"].iteritems():
|
|
if path:
|
|
if not MusicBox.add_music(name, path):
|
|
print("Error: Could not load music %s (file %s)" % (name, path), file=sys.stderr)
|
|
sys.exit(1)
|
|
# BUG workaround: phonon is on 100% volume for some machines. try playing one song and immediately stopping it
|
|
MusicBox.play_music(MusicBox.media.keys()[0])
|
|
MusicBox.stop_music()
|
|
|
|
# create and start input threads
|
|
inputs = []
|
|
if config["playerInput"] is not None:
|
|
for playerInput in config["playerInput"]:
|
|
args = playerInput.get("Args", [])
|
|
if args is None:
|
|
args = []
|
|
|
|
try:
|
|
inp = get_input(playerInput["Type"], args, app)
|
|
inputs.append(inp)
|
|
except InputException as e:
|
|
print("Error: %s" % e, file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
inputs[-1].start()
|
|
|
|
# create board
|
|
board = SeopardyGame(questions, gamestate, inputs)
|
|
board.show()
|
|
app.exec_()
|
|
sys.exit()
|