2013-11-06 20:42:00 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import argparse
|
2013-12-02 01:06:46 +01:00
|
|
|
import yaml
|
2013-11-06 20:42:00 +01:00
|
|
|
import sys
|
|
|
|
from PySide import QtGui
|
|
|
|
|
2013-12-02 00:23:05 +01:00
|
|
|
from music import MusicBox
|
2013-11-06 20:42:00 +01:00
|
|
|
from question import Questions
|
|
|
|
from gamestate import GameState
|
|
|
|
from game import SeopardyGame
|
2013-12-02 01:06:46 +01:00
|
|
|
from config import check_config
|
2013-11-06 20:42:00 +01:00
|
|
|
|
|
|
|
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")
|
2013-12-02 01:06:46 +01:00
|
|
|
parser.add_argument("--conf", action="store", default="seopardy.conf", help="Path to config file")
|
2013-11-06 20:42:00 +01:00
|
|
|
parser.add_argument("questions", action="store", help="Path to questionfile")
|
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = _parser()
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
questions = Questions(args.questions)
|
|
|
|
|
|
|
|
# start gui
|
2013-12-02 01:06:46 +01:00
|
|
|
app = QtGui.QApplication([sys.argv[0]])
|
|
|
|
|
|
|
|
# check and load config file
|
|
|
|
config = None
|
|
|
|
try:
|
|
|
|
config = yaml.load(open(args.conf))
|
|
|
|
except IOError as e:
|
|
|
|
print("Error: Could not load config: %s" % (str(e),), file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
except yaml.scanner.ScannerError as e:
|
|
|
|
print("Error: Could not parse config file: %s" % (str(e),), file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
check_config(config)
|
2013-12-01 22:41:44 +01:00
|
|
|
|
|
|
|
# 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" % (str(e),), file=sys.stderr)
|
|
|
|
sys.exit(1)
|
2013-12-02 01:06:46 +01:00
|
|
|
gamestate = GameState.load(sstream, config["savedir"])
|
2013-12-01 22:41:44 +01:00
|
|
|
else:
|
2013-12-02 01:06:46 +01:00
|
|
|
gamestate = GameState(config["savedir"])
|
2013-12-01 22:41:44 +01:00
|
|
|
|
2013-12-02 00:23:05 +01:00
|
|
|
# init music box
|
|
|
|
MusicBox.init()
|
2013-12-02 01:06:46 +01:00
|
|
|
for name, path in config["music"].iteritems():
|
|
|
|
if path:
|
|
|
|
MusicBox.add_music(name, path)
|
2013-12-02 00:23:05 +01:00
|
|
|
|
2013-12-01 22:41:44 +01:00
|
|
|
# create board
|
2013-11-06 20:42:00 +01:00
|
|
|
board = SeopardyGame(questions, gamestate)
|
|
|
|
board.show()
|
|
|
|
app.exec_()
|
|
|
|
sys.exit()
|