summaryrefslogtreecommitdiff
path: root/voctogui/voctogui.py
blob: 39c2957e7f93e4c581dc87580b10bfe4c5384fad (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.uibuilder import UiBuilder
  21. # main class
  22. class Voctogui(object):
  23. def __init__(self):
  24. self.log = logging.getLogger('Voctogui')
  25. # Instanciate GTK-Builder
  26. self.builder = UiBuilder()
  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.builder.add_from_file(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.builder.add_from_file(path)
  43. break
  44. self.builder.setup()
  45. def run(self):
  46. self.log.info('setting UI visible')
  47. self.builder.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()