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 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/python
  2. # Licensed under GPLv3
  3. # Written by Sebastian Lohff (seba@someserver.de)
  4. # http://seba-geek.de/projects/seopardy/
  5. from __future__ import print_function
  6. import argparse
  7. import yaml
  8. import sys
  9. from PySide import QtGui, QtCore
  10. from music import MusicBox
  11. from question import Questions, QuestionException
  12. from gamestate import GameState
  13. from game import SeopardyGame
  14. from config import check_config
  15. from buttonreader import get_input, InputException
  16. def _parser():
  17. parser = argparse.ArgumentParser(description="Sebas jeopardy/beopardy clone")
  18. parser.add_argument("--gamestate", action="store", default=None, help="Gamestate to load to recover a crashed game")
  19. parser.add_argument("--conf", action="store", default="seopardy.conf", help="Path to config file")
  20. parser.add_argument("--no-cwd", action="store_true", default=False, help="Do not change working directory to question folder")
  21. parser.add_argument("-v", "--verbose", action="store_true", default=False, help="Be more verbose, print filenames of missing files")
  22. parser.add_argument("questions", action="store", help="Path to questionfile")
  23. return parser
  24. if __name__ == '__main__':
  25. parser = _parser()
  26. args = parser.parse_args()
  27. questions = None
  28. try:
  29. questions = Questions(args.questions, appendPath=not args.no_cwd, verbose=args.verbose)
  30. except QuestionException as e:
  31. print(e.message, file=sys.stderr)
  32. sys.exit(1)
  33. # start gui
  34. app = QtGui.QApplication([sys.argv[0]])
  35. QtCore.QCoreApplication.setApplicationName("Seopardy")
  36. # check and load config file
  37. config = None
  38. try:
  39. config = yaml.safe_load(open(args.conf))
  40. except IOError as e:
  41. print("Error: Could not load config: %s" % (e,), file=sys.stderr)
  42. sys.exit(1)
  43. except yaml.scanner.ScannerError as e:
  44. print("Error: Could not parse config file: %s" % (e,), file=sys.stderr)
  45. sys.exit(1)
  46. check_config(config)
  47. # create or load gamestate
  48. gamestate = None
  49. if args.gamestate:
  50. sstream = None
  51. try:
  52. sstream = open(args.gamestate, "r")
  53. except IOError as e:
  54. print("Error: Could not load gamestate: %s" % (e,), file=sys.stderr)
  55. sys.exit(1)
  56. gamestate = GameState.load(sstream, config["savedir"])
  57. else:
  58. gamestate = GameState(config["savedir"])
  59. # init music box
  60. MusicBox.init()
  61. for name, path in config["music"].iteritems():
  62. if path:
  63. if not MusicBox.add_music(name, path):
  64. print("Error: Could not load music %s (file %s)" % (name, path), file=sys.stderr)
  65. sys.exit(1)
  66. # BUG workaround: phonon is on 100% volume for some machines. try playing one song and immediately stopping it
  67. MusicBox.play_music(MusicBox.media.keys()[0])
  68. MusicBox.stop_music()
  69. # create and start input threads
  70. inputs = []
  71. if config["playerInput"] is not None:
  72. for playerInput in config["playerInput"]:
  73. args = playerInput.get("Args", [])
  74. if args is None:
  75. args = []
  76. try:
  77. inp = get_input(playerInput["Type"], args, app)
  78. inputs.append(inp)
  79. except InputException as e:
  80. print("Error: %s" % e, file=sys.stderr)
  81. sys.exit(1)
  82. inputs[-1].start()
  83. # create board
  84. board = SeopardyGame(questions, gamestate, inputs)
  85. board.show()
  86. app.exec_()
  87. sys.exit()