kcg.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/python
  2. """
  3. This is the main program for KCG
  4. It imports all modules and starts the Gui
  5. """
  6. from PyQt4 import QtGui, QtCore
  7. import sys
  8. import os
  9. import argparse as ap
  10. import base.kcgwidget as kcgw
  11. import config
  12. from config import Configuration
  13. translator = QtCore.QTranslator()
  14. kcgw.translator = translator
  15. # kcgw.tr = translator.translate
  16. kcgw.tr = QtCore.QCoreApplication.translate
  17. config.install_path = os.path.dirname(config.__file__) + "/"
  18. try: # Try to use Erax for exception logging
  19. sys.path.append(os.path.expanduser('~/Documents/PythonProjects/'))
  20. from erax import Erax
  21. exception_log_handler = Erax('https://psraspi.no-ip.biz/p/erax/insert/78e55a9524a191f7628f82a20bcaa167:kcg',
  22. no_epl_errors=True, cert='/tmp/raspi.pem')
  23. exception_log_handler.install()
  24. except ImportError:
  25. pass
  26. def print_version(verbose=False):
  27. # print "KCG - KAPTURE Control Gui"
  28. # print "=" * 30
  29. print "KCG",
  30. with open(config.install_path+'VERSION', 'r') as v:
  31. print v.read().strip()
  32. if verbose:
  33. print "=" * 30
  34. print "Using Python:"
  35. print sys.version
  36. print "=" * 30
  37. print "From: " + config.install_path
  38. def run():
  39. """
  40. Main Function, gets called when GUI is started
  41. :return:
  42. """
  43. parser = ap.ArgumentParser("KCG - KAPTURE Control Gui")
  44. parser.add_argument('--config', type=str, default='', help='Override Configuration file settings.'
  45. 'Format: "Section:setting=content;Section:setting2=content;Section2:setting3=content" etc.')
  46. parser.add_argument('--version', action='store_true', help="Print Version and exit")
  47. parser.add_argument('--vversion', action='store_true', help="Print Version verbose and exit")
  48. parser.add_argument('--testing', action='store_true', default=False,
  49. help="start KCG in testing version. DO NOT USE THIS IN PRODUCTION.")
  50. args = parser.parse_args()
  51. if args.version or args.vversion:
  52. print_version(args.vversion)
  53. sys.exit()
  54. kcgw.testing = args.testing
  55. app = QtGui.QApplication(sys.argv)
  56. app.installTranslator(translator)
  57. app.processEvents()
  58. # pixmap = QtGui.QPixmap(config.install_path+"icons/KCG_Logo.png").scaled(400, 400)
  59. # splash_screen = QtGui.QSplashScreen(pixmap)
  60. # splash_screen.setMask(pixmap.mask())
  61. # splash_screen.show()
  62. # splash_screen.update()
  63. # splash_screen.showMessage("Loading KCG", QtCore.Qt.AlignCenter | QtCore.Qt.AlignBottom, QtCore.Qt.red)
  64. # splash_screen.update()
  65. # app.processEvents()
  66. conf = Configuration(args.config)
  67. conf.setup()
  68. while conf.error:
  69. conf.doSetup()
  70. if args.testing:
  71. config.default_subdirectory_name='t'
  72. import base.kcg as kcg
  73. gui = kcg.Gui()
  74. # splash_screen.finish(gui)
  75. gui.show()
  76. sys.exit(app.exec_())