No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

seopardy.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/python
  2. from __future__ import print_function
  3. import argparse
  4. import yaml
  5. import sys
  6. from PySide import QtGui, QtCore
  7. from music import MusicBox
  8. from question import Questions, QuestionException
  9. from gamestate import GameState
  10. from game import SeopardyGame
  11. from config import check_config
  12. def _parser():
  13. parser = argparse.ArgumentParser(description="Sebas jeopardy/beopardy clone")
  14. parser.add_argument("--gamestate", action="store", default=None, help="Gamestate to load to recover a crashed game")
  15. parser.add_argument("--conf", action="store", default="seopardy.conf", help="Path to config file")
  16. parser.add_argument("questions", action="store", help="Path to questionfile")
  17. return parser
  18. if __name__ == '__main__':
  19. parser = _parser()
  20. args = parser.parse_args()
  21. questions = None
  22. try:
  23. questions = Questions(args.questions)
  24. except QuestionException as e:
  25. print(str(e), file=sys.stderr)
  26. sys.exit(1)
  27. # start gui
  28. app = QtGui.QApplication([sys.argv[0]])
  29. QtCore.QCoreApplication.setApplicationName("Seopardy")
  30. # check and load config file
  31. config = None
  32. try:
  33. config = yaml.safe_load(open(args.conf))
  34. except IOError as e:
  35. print("Error: Could not load config: %s" % (str(e),), file=sys.stderr)
  36. sys.exit(1)
  37. except yaml.scanner.ScannerError as e:
  38. print("Error: Could not parse config file: %s" % (str(e),), file=sys.stderr)
  39. sys.exit(1)
  40. check_config(config)
  41. # create or load gamestate
  42. gamestate = None
  43. if args.gamestate:
  44. sstream = None
  45. try:
  46. sstream = open(args.gamestate, "r")
  47. except IOError as e:
  48. print("Error: Could not load gamestate: %s" % (str(e),), file=sys.stderr)
  49. sys.exit(1)
  50. gamestate = GameState.load(sstream, config["savedir"])
  51. else:
  52. gamestate = GameState(config["savedir"])
  53. # init music box
  54. MusicBox.init()
  55. for name, path in config["music"].iteritems():
  56. if path:
  57. if not MusicBox.add_music(name, path):
  58. print("Error: Could not load music %s (file %s)" % (name, path), file=sys.stderr)
  59. sys.exit(1)
  60. # create board
  61. board = SeopardyGame(questions, gamestate)
  62. board.show()
  63. app.exec_()
  64. sys.exit()