summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--voctogui/default-config.ini2
-rw-r--r--voctogui/lib/args.py20
-rw-r--r--voctogui/lib/config.py24
-rw-r--r--voctogui/lib/uibuilder.py27
-rw-r--r--voctogui/ui/voctogui.ui11
-rw-r--r--voctogui/ui/voctogui.ui~12
-rwxr-xr-xvoctogui/voctogui.py111
7 files changed, 207 insertions, 0 deletions
diff --git a/voctogui/default-config.ini b/voctogui/default-config.ini
new file mode 100644
index 0000000..354a8c9
--- /dev/null
+++ b/voctogui/default-config.ini
@@ -0,0 +1,2 @@
+[gui]
+foo=bar
diff --git a/voctogui/lib/args.py b/voctogui/lib/args.py
new file mode 100644
index 0000000..3a9032f
--- /dev/null
+++ b/voctogui/lib/args.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python3
+import argparse
+
+__all__ = ['Args']
+
+parser = argparse.ArgumentParser(description='Voctogui')
+parser.add_argument('-v', '--verbose', action='count',
+ help="Also print INFO and DEBUG messages.")
+
+parser.add_argument('-c', '--color', action='store', choices=['auto', 'always', 'never'], default='auto',
+ help="Control the use of colors in the Log-Output")
+
+parser.add_argument('-i', '--ini-file', action='store',
+ help="Load a custom config.ini-File")
+
+parser.add_argument('-u', '--ui-file', action='store',
+ help="Load a custom .ui-File")
+
+
+Args = parser.parse_args()
diff --git a/voctogui/lib/config.py b/voctogui/lib/config.py
new file mode 100644
index 0000000..b06075c
--- /dev/null
+++ b/voctogui/lib/config.py
@@ -0,0 +1,24 @@
+#!/usr/bin/python3
+import os.path
+from configparser import SafeConfigParser
+from lib.args import Args
+
+__all__ = ['Config']
+
+def getlist(self, section, option):
+ return [x.strip() for x in self.get(section, option).split(',')]
+
+SafeConfigParser.getlist = getlist
+
+files = [
+ os.path.join(os.path.dirname(os.path.realpath(__file__)), '../default-config.ini'),
+ os.path.join(os.path.dirname(os.path.realpath(__file__)), '../config.ini'),
+ '/etc/voctogui.ini',
+ os.path.expanduser('~/.voctogui.ini'),
+]
+
+if Args.ini_file is not None:
+ files.append(Args.ini_file)
+
+Config = SafeConfigParser()
+Config.read(files)
diff --git a/voctogui/lib/uibuilder.py b/voctogui/lib/uibuilder.py
new file mode 100644
index 0000000..8d8b245
--- /dev/null
+++ b/voctogui/lib/uibuilder.py
@@ -0,0 +1,27 @@
+#!/usr/bin/python3
+import gi, logging
+from gi.repository import Gtk, Gst
+
+class UiBuilder(Gtk.Builder):
+ def __init__(self):
+ self.log = logging.getLogger('UiBuilder')
+ super().__init__()
+
+ def setup(self):
+ # Aquire the Main-Window from the UI-File
+ self.log.debug('Loading Main-Window "window" from .ui-File')
+ self.win = self.get_check_widget("window")
+
+ # Connect Close-Handler
+ self.win.connect("delete-event", Gtk.main_quit)
+
+ def show(self):
+ self.win.show_all()
+
+ def get_check_widget(self, widget_id):
+ widget = self.get_object(widget_id)
+ if not widget:
+ self.log.error('could not load required widget "%s" from the .ui-File', widget_id)
+ raise Exception('Widget not found in .ui-File')
+
+ return widget
diff --git a/voctogui/ui/voctogui.ui b/voctogui/ui/voctogui.ui
new file mode 100644
index 0000000..d94cea1
--- /dev/null
+++ b/voctogui/ui/voctogui.ui
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.3 -->
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <object class="GtkWindow" id="window">
+ <property name="can_focus">False</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+</interface>
diff --git a/voctogui/ui/voctogui.ui~ b/voctogui/ui/voctogui.ui~
new file mode 100644
index 0000000..84f6ff0
--- /dev/null
+++ b/voctogui/ui/voctogui.ui~
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.3 -->
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <object class="GtkApplicationWindow" id="window">
+ <property name="can_focus">False</property>
+ <property name="show_menubar">False</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+</interface>
diff --git a/voctogui/voctogui.py b/voctogui/voctogui.py
new file mode 100755
index 0000000..39c2957
--- /dev/null
+++ b/voctogui/voctogui.py
@@ -0,0 +1,111 @@
+#!/usr/bin/python3
+import gi, signal, logging, sys, os
+
+# import GStreamer and GLib-Helper classes
+gi.require_version('Gst', '1.0')
+from gi.repository import Gtk, Gdk, Gst, GObject, GdkX11, GstVideo
+
+# check min-version
+minGst = (1, 5)
+minPy = (3, 0)
+
+if Gst.version() < minGst:
+ raise Exception("GStreamer version", Gst.version(), 'is too old, at least', minGst, 'is required')
+
+if sys.version_info < minPy:
+ raise Exception("Python version", sys.version_info, 'is too old, at least', minPy, 'is required')
+
+
+# init GObject & Co. before importing local classes
+GObject.threads_init()
+Gdk.init([])
+Gtk.init([])
+Gst.init([])
+
+# import local classes
+from lib.args import Args
+from lib.uibuilder import UiBuilder
+
+# main class
+class Voctogui(object):
+ def __init__(self):
+ self.log = logging.getLogger('Voctogui')
+
+ # Instanciate GTK-Builder
+ self.builder = UiBuilder()
+
+ # Uf a UI-File was specified on the Command-Line, load it
+ if Args.ui_file:
+ self.log.info('loading ui-file from file specified on command-line: %s', self.options.ui_file)
+ self.builder.add_from_file(Args.ui_file)
+
+ else:
+ # Paths to look for the gst-switch UI-File
+ paths = [
+ os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ui/voctogui.ui'),
+ '/usr/lib/voctogui/ui/voctogui.ui'
+ ]
+
+ # Look for a gst-switch UI-File and load it
+ for path in paths:
+ self.log.debug('trying to load ui-file from file %s', path)
+
+ if os.path.isfile(path):
+ self.log.info('loading ui-file from file %s', path)
+ self.builder.add_from_file(path)
+ break
+
+ self.builder.setup()
+
+
+ def run(self):
+ self.log.info('setting UI visible')
+ self.builder.show()
+
+ try:
+ self.log.info('running Gtk-MainLoop')
+ Gtk.main()
+ self.log.info('Gtk-MainLoop ended')
+ except KeyboardInterrupt:
+ self.log.info('Terminated via Ctrl-C')
+
+ def quit(self):
+ self.log.info('quitting Gtk-MainLoop')
+ Gtk.main_quit()
+
+
+# run mainclass
+def main():
+ # configure logging
+ docolor = (Args.color == 'always') or (Args.color == 'auto' and sys.stderr.isatty())
+
+ if Args.verbose == 2:
+ level = logging.DEBUG
+ elif Args.verbose == 1:
+ level = logging.INFO
+ else:
+ level = logging.WARNING
+
+ if docolor:
+ format = '\x1b[33m%(levelname)8s\x1b[0m \x1b[32m%(name)s\x1b[0m: %(message)s'
+ else:
+ format = '%(levelname)8s %(name)s: %(message)s'
+
+ logging.basicConfig(level=level, format=format)
+
+ # make killable by ctrl-c
+ logging.debug('setting SIGINT handler')
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
+
+ logging.info('Python Version: %s', sys.version_info)
+ logging.info('GStreamer Version: %s', Gst.version())
+
+ # init main-class and main-loop
+ logging.debug('initializing Voctogui')
+ voctogui = Voctogui()
+
+ logging.debug('running Voctogui')
+ voctogui.run()
+
+if __name__ == '__main__':
+ main()