import template files using importlib

this lets us support the various bindings w/o having to add binding
specific code.

it breaks PyQt4 support since PyQt4 template files are suffixed as
"_pyqt" rather than "_pyqt4"
This commit is contained in:
KIU Shueng Chuan 2021-01-14 11:15:34 +08:00
parent 5732ca8213
commit 966ae7a3df
11 changed files with 42 additions and 126 deletions

View File

@ -12,16 +12,9 @@ path = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, path)
app = pg.mkQApp()
if QT_LIB == 'PySide':
from exampleLoaderTemplate_pyside import Ui_Form
elif QT_LIB == 'PySide2':
from exampleLoaderTemplate_pyside2 import Ui_Form
elif QT_LIB == 'PySide6':
from exampleLoaderTemplate_pyside6 import Ui_Form
elif QT_LIB == 'PyQt5':
from exampleLoaderTemplate_pyqt5 import Ui_Form
else:
from exampleLoaderTemplate_pyqt import Ui_Form
import importlib
ui_template = importlib.import_module(
f'exampleLoaderTemplate_{QT_LIB.lower()}')
examples = OrderedDict([
('Command-line usage', 'CLIexample.py'),
@ -352,7 +345,7 @@ class PythonHighlighter(QSyntaxHighlighter):
class ExampleLoader(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.ui = Ui_Form()
self.ui = ui_template.Ui_Form()
self.cw = QtGui.QWidget()
self.setCentralWidget(self.cw)
self.ui.setupUi(self.cw)

View File

@ -20,20 +20,13 @@ from pyqtgraph.ptime import time
app = QtGui.QApplication([])
#mw = QtGui.QMainWindow()
#mw.resize(800,800)
if QT_LIB == 'PySide':
from ScatterPlotSpeedTestTemplate_pyside import Ui_Form
elif QT_LIB == 'PySide2':
from ScatterPlotSpeedTestTemplate_pyside2 import Ui_Form
elif QT_LIB == 'PySide6':
from ScatterPlotSpeedTestTemplate_pyside6 import Ui_Form
elif QT_LIB == 'PyQt5':
from ScatterPlotSpeedTestTemplate_pyqt5 import Ui_Form
else:
from ScatterPlotSpeedTestTemplate_pyqt import Ui_Form
import importlib
ui_template = importlib.import_module(
f'ScatterPlotSpeedTestTemplate_{QT_LIB.lower()}')
win = QtGui.QWidget()
win.setWindowTitle('pyqtgraph example: ScatterPlotSpeedTest')
ui = Ui_Form()
ui = ui_template.Ui_Form()
ui.setupUi(win)
win.show()

View File

@ -15,16 +15,8 @@ import numpy as np
import pyqtgraph as pg
import pyqtgraph.ptime as ptime
if QT_LIB == 'PySide':
import VideoTemplate_pyside as VideoTemplate
elif QT_LIB == 'PySide2':
import VideoTemplate_pyside2 as VideoTemplate
elif QT_LIB == 'PySide6':
import VideoTemplate_pyside6 as VideoTemplate
elif QT_LIB == 'PyQt5':
import VideoTemplate_pyqt5 as VideoTemplate
else:
import VideoTemplate_pyqt as VideoTemplate
import importlib
ui_template = importlib.import_module(f'VideoTemplate_{QT_LIB.lower()}')
#QtGui.QApplication.setGraphicsSystem('raster')
@ -32,7 +24,7 @@ app = QtGui.QApplication([])
win = QtGui.QMainWindow()
win.setWindowTitle('pyqtgraph example: VideoSpeedTest')
ui = VideoTemplate.Ui_MainWindow()
ui = ui_template.Ui_MainWindow()
ui.setupUi(win)
win.show()

View File

@ -4,16 +4,9 @@ from .. import functions as fn
from ..graphicsItems.ViewBox import ViewBox
from ..graphicsItems.PlotItem import PlotItem
if QT_LIB == 'PySide':
from . import exportDialogTemplate_pyside as exportDialogTemplate
elif QT_LIB == 'PySide2':
from . import exportDialogTemplate_pyside2 as exportDialogTemplate
elif QT_LIB == 'PySide6':
from . import exportDialogTemplate_pyside6 as exportDialogTemplate
elif QT_LIB == 'PyQt5':
from . import exportDialogTemplate_pyqt5 as exportDialogTemplate
else:
from . import exportDialogTemplate_pyqt as exportDialogTemplate
import importlib
ui_template = importlib.import_module(
f'.exportDialogTemplate_{QT_LIB.lower()}', package=__package__)
class ExportDialog(QtGui.QWidget):
@ -30,7 +23,7 @@ class ExportDialog(QtGui.QWidget):
self.selectBox.hide()
self.scene.addItem(self.selectBox)
self.ui = exportDialogTemplate.Ui_Form()
self.ui = ui_template.Ui_Form()
self.ui.setupUi(self)
self.ui.closeBtn.clicked.connect(self.close)

View File

@ -5,16 +5,9 @@ from ..graphicsItems.ROI import ROI
from ..graphicsItems.ViewBox import ViewBox
from ..graphicsItems.GridItem import GridItem
if QT_LIB == 'PySide':
from .CanvasTemplate_pyside import *
elif QT_LIB == 'PyQt4':
from .CanvasTemplate_pyqt import *
elif QT_LIB == 'PySide2':
from .CanvasTemplate_pyside2 import *
elif QT_LIB == 'PySide6':
from .CanvasTemplate_pyside6 import *
elif QT_LIB == 'PyQt5':
from .CanvasTemplate_pyqt5 import *
import importlib
ui_template = importlib.import_module(
f'.CanvasTemplate_{QT_LIB.lower()}', package=__package__)
import numpy as np
from .. import debug
@ -32,7 +25,7 @@ class Canvas(QtGui.QWidget):
def __init__(self, parent=None, allowTransforms=True, hideCtrl=False, name=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Form()
self.ui = ui_template.Ui_Form()
self.ui.setupUi(self)
self.view = ViewBox()
self.ui.view.setCentralItem(self.view)

View File

@ -3,16 +3,9 @@ import numpy as np
from ..Qt import QtGui, QtCore, QtSvg, QT_LIB
from ..graphicsItems.ROI import ROI
from .. import SRTTransform, ItemGroup
if QT_LIB == 'PySide':
from . import TransformGuiTemplate_pyside as TransformGuiTemplate
elif QT_LIB == 'PyQt4':
from . import TransformGuiTemplate_pyqt as TransformGuiTemplate
elif QT_LIB == 'PySide2':
from . import TransformGuiTemplate_pyside2 as TransformGuiTemplate
elif QT_LIB == 'PySide6':
from . import TransformGuiTemplate_pyside6 as TransformGuiTemplate
elif QT_LIB == 'PyQt5':
from . import TransformGuiTemplate_pyqt5 as TransformGuiTemplate
import importlib
ui_template = importlib.import_module(
f'.TransformGuiTemplate_{QT_LIB.lower()}', package=__package__)
from .. import debug
@ -80,7 +73,7 @@ class CanvasItem(QtCore.QObject):
self.pasteBtn = QtGui.QPushButton('Paste')
self.transformWidget = QtGui.QWidget()
self.transformGui = TransformGuiTemplate.Ui_Form()
self.transformGui = ui_template.Ui_Form()
self.transformGui.setupUi(self.transformWidget)
self.layout.addWidget(self.transformWidget, 3, 0, 1, 2)
self.transformGui.mirrorImageBtn.clicked.connect(self.mirrorY)

View File

@ -7,16 +7,9 @@ from ..python2_3 import basestring
from .. import exceptionHandling as exceptionHandling
from .. import getConfigOption
from ..functions import SignalBlock
if QT_LIB == 'PySide':
from . import template_pyside as template
elif QT_LIB == 'PySide2':
from . import template_pyside2 as template
elif QT_LIB == 'PySide6':
from . import template_pyside6 as template
elif QT_LIB == 'PyQt5':
from . import template_pyqt5 as template
else:
from . import template_pyqt as template
import importlib
ui_template = importlib.import_module(
f'.template_{QT_LIB.lower()}', package=__package__)
class ConsoleWidget(QtGui.QWidget):
@ -62,7 +55,7 @@ class ConsoleWidget(QtGui.QWidget):
self.inCmd = False
self.frames = [] # stack frames to access when an item in the stack list is selected
self.ui = template.Ui_Form()
self.ui = ui_template.Ui_Form()
self.ui.setupUi(self)
self.output = self.ui.output
self.input = self.ui.input

View File

@ -5,22 +5,9 @@ from ..pgcollections import OrderedDict
from ..widgets.TreeWidget import *
from .. import FileDialog, DataTreeWidget
## pyside and pyqt use incompatible ui files.
if QT_LIB == 'PySide':
from . import FlowchartTemplate_pyside as FlowchartTemplate
from . import FlowchartCtrlTemplate_pyside as FlowchartCtrlTemplate
elif QT_LIB == 'PySide2':
from . import FlowchartTemplate_pyside2 as FlowchartTemplate
from . import FlowchartCtrlTemplate_pyside2 as FlowchartCtrlTemplate
elif QT_LIB == 'PySide6':
from . import FlowchartTemplate_pyside6 as FlowchartTemplate
from . import FlowchartCtrlTemplate_pyside6 as FlowchartCtrlTemplate
elif QT_LIB == 'PyQt5':
from . import FlowchartTemplate_pyqt5 as FlowchartTemplate
from . import FlowchartCtrlTemplate_pyqt5 as FlowchartCtrlTemplate
else:
from . import FlowchartTemplate_pyqt as FlowchartTemplate
from . import FlowchartCtrlTemplate_pyqt as FlowchartCtrlTemplate
import importlib
FlowchartCtrlTemplate = importlib.import_module(
f'.FlowchartCtrlTemplate_{QT_LIB.lower()}', package=__package__)
from .Terminal import Terminal
from numpy import ndarray

View File

@ -19,16 +19,9 @@ from .. InfiniteLine import InfiniteLine
from ...WidgetGroup import WidgetGroup
from ...python2_3 import basestring
if QT_LIB == 'PyQt4':
from .plotConfigTemplate_pyqt import *
elif QT_LIB == 'PySide':
from .plotConfigTemplate_pyside import *
elif QT_LIB == 'PyQt5':
from .plotConfigTemplate_pyqt5 import *
elif QT_LIB == 'PySide2':
from .plotConfigTemplate_pyside2 import *
elif QT_LIB == 'PySide6':
from .plotConfigTemplate_pyside6 import *
import importlib
ui_template = importlib.import_module(
f'.plotConfigTemplate_{QT_LIB.lower()}', package=__package__)
__all__ = ['PlotItem']
@ -191,7 +184,7 @@ class PlotItem(GraphicsWidget):
### Set up context menu
w = QtGui.QWidget()
self.ctrl = c = Ui_Form()
self.ctrl = c = ui_template.Ui_Form()
c.setupUi(w)
dv = QtGui.QDoubleValidator(self)

View File

@ -3,16 +3,9 @@ from ...Qt import QtCore, QtGui, QT_LIB
from ...python2_3 import asUnicode
from ...WidgetGroup import WidgetGroup
if QT_LIB == 'PyQt4':
from .axisCtrlTemplate_pyqt import Ui_Form as AxisCtrlTemplate
elif QT_LIB == 'PySide':
from .axisCtrlTemplate_pyside import Ui_Form as AxisCtrlTemplate
elif QT_LIB == 'PyQt5':
from .axisCtrlTemplate_pyqt5 import Ui_Form as AxisCtrlTemplate
elif QT_LIB == 'PySide2':
from .axisCtrlTemplate_pyside2 import Ui_Form as AxisCtrlTemplate
elif QT_LIB == 'PySide6':
from .axisCtrlTemplate_pyside6 import Ui_Form as AxisCtrlTemplate
import importlib
ui_template = importlib.import_module(
f'.axisCtrlTemplate_{QT_LIB.lower()}', package=__package__)
import weakref
@ -37,7 +30,7 @@ class ViewBoxMenu(QtGui.QMenu):
m = QtGui.QMenu()
m.setTitle("%s Axis" % axis)
w = QtGui.QWidget()
ui = AxisCtrlTemplate()
ui = ui_template.Ui_Form()
ui.setupUi(w)
a = QtGui.QWidgetAction(self)
a.setDefaultWidget(w)

View File

@ -16,16 +16,9 @@ import os, sys
import numpy as np
from ..Qt import QtCore, QtGui, QT_LIB
if QT_LIB == 'PySide':
from .ImageViewTemplate_pyside import *
elif QT_LIB == 'PySide2':
from .ImageViewTemplate_pyside2 import *
elif QT_LIB == 'PySide6':
from .ImageViewTemplate_pyside6 import *
elif QT_LIB == 'PyQt5':
from .ImageViewTemplate_pyqt5 import *
else:
from .ImageViewTemplate_pyqt import *
import importlib
ui_template = importlib.import_module(
f'.ImageViewTemplate_{QT_LIB.lower()}', package=__package__)
from ..graphicsItems.ImageItem import *
from ..graphicsItems.ROI import *
@ -128,7 +121,7 @@ class ImageView(QtGui.QWidget):
self.image = None
self.axes = {}
self.imageDisp = None
self.ui = Ui_Form()
self.ui = ui_template.Ui_Form()
self.ui.setupUi(self)
self.scene = self.ui.graphicsView.scene()
self.ui.histogram.setLevelMode(levelMode)