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
This commit is contained in:
KIU Shueng Chuan 2021-02-22 18:03:06 +08:00
parent 5b1ac7acaa
commit e09a397ebc
3 changed files with 14 additions and 26 deletions

View File

@ -344,18 +344,15 @@ class ExampleLoader(QtGui.QMainWindow):
def loadFile(self, edited=False):
extra = []
qtLib = str(self.ui.qtLibCombo.currentText())
gfxSys = str(self.ui.graphicsSystemCombo.currentText())
env = None
if qtLib != 'default':
extra.append(qtLib.lower())
elif gfxSys != 'default':
extra.append(gfxSys)
env = dict(os.environ, PYQTGRAPH_QT_LIB=qtLib)
if edited:
path = os.path.abspath(os.path.dirname(__file__))
proc = subprocess.Popen([sys.executable, '-'] + extra, stdin=subprocess.PIPE, cwd=path)
proc = subprocess.Popen([sys.executable, '-'], stdin=subprocess.PIPE, cwd=path, env=env)
code = str(self.ui.codeView.toPlainText()).encode('UTF-8')
proc.stdin.write(code)
proc.stdin.close()
@ -364,9 +361,14 @@ class ExampleLoader(QtGui.QMainWindow):
if fn is None:
return
if sys.platform.startswith('win'):
os.spawnl(os.P_NOWAIT, sys.executable, '"'+sys.executable+'"', '"' + fn + '"', *extra)
args = [os.P_NOWAIT, sys.executable, '"'+sys.executable+'"', '"' + fn + '"']
else:
os.spawnl(os.P_NOWAIT, sys.executable, sys.executable, fn, *extra)
args = [os.P_NOWAIT, sys.executable, sys.executable, fn]
if env is None:
os.spawnl(*args)
else:
args.append(env)
os.spawnle(*args)
def showFile(self):
fn = self.currentFile()

View File

@ -6,6 +6,9 @@ it is being scaled and/or converted by lookup table, and whether OpenGL
is used by the view widget
"""
## Add path to library (just for examples; you do not need this)
import initExample
import argparse
import sys

View File

@ -20,25 +20,8 @@ if not hasattr(sys, 'frozen'):
sys.path.remove(p)
sys.path.insert(0, p)
## should force example to use PySide instead of PyQt
for module in ['PyQt5', 'PySide2', 'PySide6', 'PyQt6']:
if module.lower() in sys.argv:
QtGui = importlib.import_module(module + '.QtGui')
break
else:
from pyqtgraph.Qt import QtGui
import pyqtgraph as pg
## Force use of a specific graphics system
use_gs = 'default'
for gs in ['raster', 'native', 'opengl']:
if gs in sys.argv:
use_gs = gs
QtGui.QApplication.setGraphicsSystem(gs)
break
print("Using %s (%s graphics system)" % (pg.Qt.QT_LIB, use_gs))
print("Using", pg.Qt.QT_LIB)
## Enable fault handling to give more helpful error messages on crash.
## Only available in python 3.3+