import os # Unix-like with GTK systems use gstreamer as media backend. # gstreamer leaves applications to invoke XInitThreads() # in libX11, and the wxWidgets wxMediaCtrl crashes # with X errors so frequently it is unusable if that # initialization is not done. # Fortunately, it can probably be done here, but perhaps # success is not certain. (Another hack is to use LD_PRELOAD # if supported to load a tiny shared library that merely # makes the call -- doing both that and this is probably OK.) X11hack = None if os.name == 'posix' and ('DISPLAY' in os.environ): # this env var has had no effect in my testing -- # probably needs later version -- but leave it os.environ["GST_GL_XINITTHREADS"] = "1" import ctypes import ctypes.util X11hack = { "libname" : ctypes.util.find_library("X11") or "libX11.so", "lib_ptr" : None, "lib_fun" : None, "lib_ret" : None, "lib_err" : None } try: X11hack["lib_ptr"] = ctypes.cdll.LoadLibrary(X11hack["libname"]) X11hack["lib_fun"] = X11hack["lib_ptr"].XInitThreads X11hack["lib_fun"].argtypes = [] X11hack["lib_fun"].restype = ctypes.c_int # X11 'Status' try: X11hack["lib_ret"] = X11hack["lib_fun"]() except Exception as m: X11hack["lib_err"] = "Call Exception: {}".format(m) except: X11hack["lib_err"] = "Call Exception: unknown" except AttributeError: X11hack["lib_err"] = "AttributeError" except Exception as m: X11hack["lib_err"] = "Exception: {}".format(m) except: X11hack["lib_err"] = "Exception: unknown" if False and X11hack["lib_err"]: print("Cannot load {} : '{}'".format( X11hack["libname"], X11hack["lib_err"]))