aboutsummaryrefslogtreecommitdiff
path: root/voctogui/voctogui.py
blob: 52bc3c0a668d7cfb84481bb60cd304cb9b911f06 (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.ui import Ui
  21. # main class
  22. class Voctogui(object):
  23. def __init__(self):
  24. self.log = logging.getLogger('Voctogui')
  25. # Uf a UI-File was specified on the Command-Line, load it
  26. if Args.ui_file:
  27. self.log.info('loading ui-file from file specified on command-line: %s', self.options.ui_file)
  28. self.ui = Ui(Args.ui_file)
  29. else:
  30. # Paths to look for the gst-switch UI-File
  31. paths = [
  32. os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ui/voctogui.ui'),
  33. '/usr/lib/voctogui/ui/voctogui.ui'
  34. ]
  35. # Look for a gst-switch UI-File and load it
  36. for path in paths:
  37. self.log.debug('trying to load ui-file from file %s', path)
  38. if os.path.isfile(path):
  39. self.log.info('loading ui-file from file %s', path)
  40. self.ui = Ui(path)
  41. break
  42. if self.ui is None:
  43. raise Exception("Can't find any .ui-Files to use (searched %s)" % (', '.join(paths)))
  44. self.ui.setup()
  45. def run(self):
  46. self.log.info('setting UI visible')
  47. self.ui.show()
  48. try:
  49. self.log.info('running Gtk-MainLoop')
  50. Gtk.main()
  51. self.log.info('Gtk-MainLoop ended')
  52. except KeyboardInterrupt:
  53. self.log.info('Terminated via Ctrl-C')
  54. def quit(self):
  55. self.log.info('quitting Gtk-MainLoop')
  56. Gtk.main_quit()
  57. # run mainclass
  58. def main():
  59. # configure logging
  60. docolor = (Args.color == 'always') or (Args.color == 'auto' and sys.stderr.isatty())
  61. if Args.verbose == 2:
  62. level = logging.DEBUG
  63. elif Args.verbose == 1:
  64. level = logging.INFO
  65. else:
  66. level = logging.WARNING
  67. if docolor:
  68. format = '\x1b[33m%(levelname)8s\x1b[0m \x1b[32m%(name)s\x1b[0m: %(message)s'
  69. else:
  70. format = '%(levelname)8s %(name)s: %(message)s'
  71. logging.basicConfig(level=level, format=format)
  72. # make killable by ctrl-c
  73. logging.debug('setting SIGINT handler')
  74. signal.signal(signal.SIGINT, signal.SIG_DFL)
  75. logging.info('Python Version: %s', sys.version_info)
  76. logging.info('GStreamer Version: %s', Gst.version())
  77. # init main-class and main-loop
  78. logging.debug('initializing Voctogui')
  79. voctogui = Voctogui()
  80. logging.debug('running Voctogui')
  81. voctogui.run()
  82. if __name__ == '__main__':
  83. main()