pyqtgraph/examples/initExample.py
KIU Shueng Chuan e09a397ebc modify environment to choose binding
the Example App allows the user to choose a binding and a graphics
system to use to execute an example.

issue 1: setGraphicsSystem is obsolete and the method no longer exists.
thus selecting a graphics system causes an error.

issue 2: the choice of binding to use is passed as an extra command
line argument to be parsed by initExample. this is problematic for
examples that use argparse, such as VideoSpeedTest.py

issue 3: if the user has set PYQTGRAPH_QT_LIB, that takes precedence
over the choice made in the Example App.

this patch fixes the above 3 issues by setting PYQTGRAPH_QT_LIB in
the child process' environment and removing the old parsing of the
command line arguments
2021-02-22 18:13:49 +08:00

32 lines
1.1 KiB
Python

## make this version of pyqtgraph importable before any others
## we do this to make sure that, when running examples, the correct library
## version is imported (if there are multiple versions present).
import sys, os
import importlib
if not hasattr(sys, 'frozen'):
if __file__ == '<stdin>':
path = os.getcwd()
else:
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
path.rstrip(os.path.sep)
if 'pyqtgraph' in os.listdir(path):
sys.path.insert(0, path) ## examples adjacent to pyqtgraph (as in source tree)
else:
for p in sys.path:
if len(p) < 3:
continue
if path.startswith(p): ## If the example is already in an importable location, promote that location
sys.path.remove(p)
sys.path.insert(0, p)
import pyqtgraph as pg
print("Using", pg.Qt.QT_LIB)
## Enable fault handling to give more helpful error messages on crash.
## Only available in python 3.3+
try:
import faulthandler
faulthandler.enable()
except ImportError:
pass