From e09a397ebcf244638e98371e015d324dea439d2d Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Mon, 22 Feb 2021 18:03:06 +0800 Subject: [PATCH] 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 --- examples/ExampleApp.py | 18 ++++++++++-------- examples/VideoSpeedTest.py | 3 +++ examples/initExample.py | 19 +------------------ 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/examples/ExampleApp.py b/examples/ExampleApp.py index 458daf76..c54d79b2 100644 --- a/examples/ExampleApp.py +++ b/examples/ExampleApp.py @@ -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() diff --git a/examples/VideoSpeedTest.py b/examples/VideoSpeedTest.py index d7ae7ed7..ecae3b30 100644 --- a/examples/VideoSpeedTest.py +++ b/examples/VideoSpeedTest.py @@ -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 diff --git a/examples/initExample.py b/examples/initExample.py index 97f46108..9b868803 100644 --- a/examples/initExample.py +++ b/examples/initExample.py @@ -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+