forked from voc/voctomix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoctogui.py
executable file
·207 lines (165 loc) · 6.12 KB
/
voctogui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env python3
import gi
import signal
import logging
import sys
import os
# import GStreamer and GLib-Helper classes
gi.require_version('Gtk', '3.0')
gi.require_version('Gst', '1.0')
gi.require_version('GdkX11', '3.0')
gi.require_version('GstVideo', '1.0')
gi.require_version('GstNet', '1.0')
from gi.repository import Gtk, Gdk, Gst, GObject, GdkX11, GstVideo
# check min-version
minGst = (1, 5)
minPy = (3, 0)
Gst.init([])
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([])
# main class
class Voctogui(object):
def __init__(self):
self.log = logging.getLogger('Voctogui')
from lib.args import Args
from lib.ui import Ui
# 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',
Args.ui_file
)
self.ui = Ui(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
self.ui = None
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.ui = Ui(path)
break
if self.ui is None:
raise Exception("Can't find any .ui-Files to use "
"(searched {})".format(', '.join(paths)))
#
# search for a .css style sheet file and load it
#
css_provider = Gtk.CssProvider()
context = Gtk.StyleContext()
css_paths = [
os.path.join(os.path.dirname(os.path.realpath(__file__)),
'ui/voctogui.css'),
'/usr/lib/voctogui/ui/voctogui.css'
]
for path in css_paths:
self.log.debug('trying to load css-file from file %s', path)
if os.path.isfile(path):
self.log.info('loading css-file from file %s', path)
css_provider.load_from_path(path)
break
else:
raise Exception("Can't find any .css-Files to use "
"(searched {})".format(', '.join(css_paths)))
context.add_provider_for_screen(
Gdk.Screen.get_default(),
css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_USER
)
self.ui.setup()
def run(self):
self.log.info('setting UI visible')
self.ui.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():
# parse command-line args
from lib import args
args.parse()
from lib.args import Args
docolor = (Args.color == 'always') \
or (Args.color == 'auto' and sys.stderr.isatty())
from lib.loghandler import LogHandler
handler = LogHandler(docolor, Args.timestamp)
logging.root.addHandler(handler)
if Args.verbose >= 2:
level = logging.DEBUG
elif Args.verbose == 1:
level = logging.INFO
else:
level = logging.WARNING
logging.root.setLevel(level)
# 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())
logging.debug('loading Config')
from lib import config
config.load()
from lib.config import Config
# establish a synchronus connection to server
import lib.connection as Connection
Connection.establish(
Args.host if Args.host else Config.get('server', 'host')
)
# fetch config from server
Config.fetchServerConfig()
# Warn when connecting to a non-local core without preview-encoders enabled
# The list-comparison is not complete
# (one could use a local hostname or the local system ip),
# but it's only here to warn that one might be making a mistake
use_previews = Config.getboolean('previews', 'enabled') \
and Config.getboolean('previews', 'use')
looks_like_localhost = Config.get('server', 'host') in ['::1',
'127.0.0.1',
'localhost']
if not use_previews and not looks_like_localhost:
logging.warning(
'Connecting to `%s` (which looks like a remote host) '
'might not work without enabeling the preview encoders '
'(set `[previews] enabled=true` on the core) or it might saturate '
'your ethernet link between the two machines.',
Config.get('server', 'host')
)
import lib.connection as Connection
import lib.clock as ClockManager
# obtain network-clock
ClockManager.obtainClock(Connection.ip)
# switch connection to nonblocking, event-driven mode
Connection.enterNonblockingMode()
# init main-class and main-loop
# (this binds all event-hander on the Connection)
logging.debug('initializing Voctogui')
voctogui = Voctogui()
# start the Mainloop and show the Window
logging.debug('running Voctogui')
voctogui.run()
if __name__ == '__main__':
try:
main()
except RuntimeError as e:
logging.error(str(e))
sys.exit(1)