aboutsummaryrefslogtreecommitdiff
path: root/voctogui/voctogui.py
blob: 083b00400c4875a1885ef02aee81aa86b0e574c8 (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. from lib.loghandler import LogHandler
  26. import lib.connection as Connection
  27. # main class
  28. class Voctogui(object):
  29. def __init__(self):
  30. self.log = logging.getLogger('Voctogui')
  31. # Uf a UI-File was specified on the Command-Line, load it
  32. if Args.ui_file:
  33. self.log.info('loading ui-file from file specified on command-line: %s', self.options.ui_file)
  34. self.ui = Ui(Args.ui_file)
  35. else:
  36. # Paths to look for the gst-switch UI-File
  37. paths = [
  38. os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ui/voctogui.ui'),
  39. '/usr/lib/voctogui/ui/voctogui.ui'
  40. ]
  41. # Look for a gst-switch UI-File and load it
  42. for path in paths:
  43. self.log.debug('trying to load ui-file from file %s', path)
  44. if os.path.isfile(path):
  45. self.log.info('loading ui-file from file %s', path)
  46. self.ui = Ui(path)
  47. break
  48. if self.ui is None:
  49. raise Exception("Can't find any .ui-Files to use (searched %s)" % (', '.join(paths)))
  50. self.ui.setup()
  51. def run(self):
  52. self.log.info('setting UI visible')
  53. self.ui.show()
  54. try:
  55. self.log.info('running Gtk-MainLoop')
  56. Gtk.main()
  57. self.log.info('Gtk-MainLoop ended')
  58. except KeyboardInterrupt:
  59. self.log.info('Terminated via Ctrl-C')
  60. def quit(self):
  61. self.log.info('quitting Gtk-MainLoop')
  62. Gtk.main_quit()
  63. # run mainclass
  64. def main():
  65. # configure logging
  66. docolor = (Args.color == 'always') or (Args.color == 'auto' and sys.stderr.isatty())
  67. handler = LogHandler(docolor)
  68. logging.root.addHandler(handler)
  69. if Args.verbose >= 2:
  70. level = logging.DEBUG
  71. elif Args.verbose == 1:
  72. level = logging.INFO
  73. else:
  74. level = logging.WARNING
  75. logging.root.setLevel(level)
  76. # make killable by ctrl-c
  77. logging.debug('setting SIGINT handler')
  78. signal.signal(signal.SIGINT, signal.SIG_DFL)
  79. logging.info('Python Version: %s', sys.version_info)
  80. logging.info('GStreamer Version: %s', Gst.version())
  81. # establish a synchronus connection to server
  82. Connection.establish(
  83. Config.get('server', 'host'))
  84. # fetch config from server
  85. Config.fetchServerConfig()
  86. # switch connection to nonblocking, event-driven mode
  87. Connection.enterNonblockingMode()
  88. # init main-class and main-loop
  89. # (this binds all event-hander on the Connection)
  90. logging.debug('initializing Voctogui')
  91. voctogui = Voctogui()
  92. # start the Mainloop and show the Window
  93. logging.debug('running Voctogui')
  94. voctogui.run()
  95. if __name__ == '__main__':
  96. main()