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