aboutsummaryrefslogtreecommitdiff
path: root/voctogui/voctogui.py
blob: 932b8f9d075da2a429e032542e2219de75fadddd (plain)
  1. #!/usr/bin/python3
  2. import gi, signal, logging, sys, os
  3. # import GStreamer and GLib-Helper classes
  4. gi.require_version('Gst', '1.0')
  5. from gi.repository import Gtk, Gdk, Gst, GObject, GdkX11, GstVideo
  6. # check min-version
  7. minGst = (1, 5)
  8. minPy = (3, 0)
  9. if Gst.version() < minGst:
  10. raise Exception("GStreamer version", Gst.version(), 'is too old, at least', minGst, 'is required')
  11. if sys.version_info < minPy:
  12. raise Exception("Python version", sys.version_info, 'is too old, at least', minPy, 'is required')
  13. # init GObject & Co. before importing local classes
  14. GObject.threads_init()
  15. Gdk.init([])
  16. Gtk.init([])
  17. Gst.init([])
  18. # import local classes
  19. from lib.args import Args
  20. from lib.config import Config
  21. from lib.ui import Ui
  22. import lib.connection as Connection
  23. # main class
  24. class Voctogui(object):
  25. def __init__(self):
  26. self.log = logging.getLogger('Voctogui')
  27. # Uf a UI-File was specified on the Command-Line, load it
  28. if Args.ui_file:
  29. self.log.info('loading ui-file from file specified on command-line: %s', self.options.ui_file)
  30. self.ui = Ui(Args.ui_file)
  31. else:
  32. # Paths to look for the gst-switch UI-File
  33. paths = [
  34. os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ui/voctogui.ui'),
  35. '/usr/lib/voctogui/ui/voctogui.ui'
  36. ]
  37. # Look for a gst-switch UI-File and load it
  38. for path in paths:
  39. self.log.debug('trying to load ui-file from file %s', path)
  40. if os.path.isfile(path):
  41. self.log.info('loading ui-file from file %s', path)
  42. self.ui = Ui(path)
  43. break
  44. if self.ui is None:
  45. raise Exception("Can't find any .ui-Files to use (searched %s)" % (', '.join(paths)))
  46. self.ui.setup()
  47. def run(self):
  48. self.log.info('setting UI visible')
  49. self.ui.show()
  50. try:
  51. self.log.info('running Gtk-MainLoop')
  52. Gtk.main()
  53. self.log.info('Gtk-MainLoop ended')
  54. except KeyboardInterrupt:
  55. self.log.info('Terminated via Ctrl-C')
  56. def quit(self):
  57. self.log.info('quitting Gtk-MainLoop')
  58. Gtk.main_quit()
  59. # run mainclass
  60. def main():
  61. # configure logging
  62. docolor = (Args.color == 'always') or (Args.color == 'auto' and sys.stderr.isatty())
  63. if Args.verbose == 2:
  64. level = logging.DEBUG
  65. elif Args.verbose == 1:
  66. level = logging.INFO
  67. else:
  68. level = logging.WARNING
  69. if docolor:
  70. format = '\x1b[33m%(levelname)8s\x1b[0m \x1b[32m%(name)s\x1b[0m: %(message)s'
  71. else:
  72. format = '%(levelname)8s %(name)s: %(message)s'
  73. logging.basicConfig(level=level, format=format)
  74. # make killable by ctrl-c
  75. logging.debug('setting SIGINT handler')
  76. signal.signal(signal.SIGINT, signal.SIG_DFL)
  77. logging.info('Python Version: %s', sys.version_info)
  78. logging.info('GStreamer Version: %s', Gst.version())
  79. # connect to server
  80. Connection.establish(
  81. Config.get('server', 'host'))
  82. # fetch serverconfig from server
  83. Config.fetchRemoteConfig()
  84. # init main-class and main-loop
  85. logging.debug('initializing Voctogui')
  86. voctogui = Voctogui()
  87. logging.debug('running Voctogui')
  88. voctogui.run()
  89. if __name__ == '__main__':
  90. main()