diff --git a/examples/CustomGraphItem.py b/examples/CustomGraphItem.py index 695768e2..8e494c3a 100644 --- a/examples/CustomGraphItem.py +++ b/examples/CustomGraphItem.py @@ -12,7 +12,7 @@ import numpy as np # Enable antialiasing for prettier plots pg.setConfigOptions(antialias=True) -w = pg.GraphicsWindow() +w = pg.GraphicsLayoutWidget(show=True) w.setWindowTitle('pyqtgraph example: CustomGraphItem') v = w.addViewBox() v.setAspectLocked() diff --git a/examples/GraphItem.py b/examples/GraphItem.py index c6362295..094b84bd 100644 --- a/examples/GraphItem.py +++ b/examples/GraphItem.py @@ -13,7 +13,7 @@ import numpy as np # Enable antialiasing for prettier plots pg.setConfigOptions(antialias=True) -w = pg.GraphicsWindow() +w = pg.GraphicsLayoutWidget(show=True) w.setWindowTitle('pyqtgraph example: GraphItem') v = w.addViewBox() v.setAspectLocked() diff --git a/examples/InfiniteLine.py b/examples/InfiniteLine.py index 50efbd04..55020776 100644 --- a/examples/InfiniteLine.py +++ b/examples/InfiniteLine.py @@ -10,7 +10,7 @@ import pyqtgraph as pg app = QtGui.QApplication([]) -win = pg.GraphicsWindow(title="Plotting items examples") +win = pg.GraphicsLayoutWidget(show=True, title="Plotting items examples") win.resize(1000,600) # Enable antialiasing for prettier plots diff --git a/examples/LogPlotTest.py b/examples/LogPlotTest.py index d408a2b4..5ae9d17e 100644 --- a/examples/LogPlotTest.py +++ b/examples/LogPlotTest.py @@ -12,7 +12,7 @@ import pyqtgraph as pg app = QtGui.QApplication([]) -win = pg.GraphicsWindow(title="Basic plotting examples") +win = pg.GraphicsLayoutWidget(show=True, title="Basic plotting examples") win.resize(1000,600) win.setWindowTitle('pyqtgraph example: LogPlotTest') diff --git a/examples/PanningPlot.py b/examples/PanningPlot.py index 165240b2..874bf330 100644 --- a/examples/PanningPlot.py +++ b/examples/PanningPlot.py @@ -9,7 +9,7 @@ import pyqtgraph as pg from pyqtgraph.Qt import QtCore, QtGui import numpy as np -win = pg.GraphicsWindow() +win = pg.GraphicsLayoutWidget(show=True) win.setWindowTitle('pyqtgraph example: PanningPlot') plt = win.addPlot() diff --git a/examples/PlotAutoRange.py b/examples/PlotAutoRange.py index 46aa3a44..0e3cd422 100644 --- a/examples/PlotAutoRange.py +++ b/examples/PlotAutoRange.py @@ -16,7 +16,7 @@ app = QtGui.QApplication([]) #mw = QtGui.QMainWindow() #mw.resize(800,800) -win = pg.GraphicsWindow(title="Plot auto-range examples") +win = pg.GraphicsLayoutWidget(show=True, title="Plot auto-range examples") win.resize(800,600) win.setWindowTitle('pyqtgraph example: PlotAutoRange') diff --git a/examples/Plotting.py b/examples/Plotting.py index 44996ae5..130698a4 100644 --- a/examples/Plotting.py +++ b/examples/Plotting.py @@ -17,7 +17,7 @@ app = QtGui.QApplication([]) #mw = QtGui.QMainWindow() #mw.resize(800,800) -win = pg.GraphicsWindow(title="Basic plotting examples") +win = pg.GraphicsLayoutWidget(show=True, title="Basic plotting examples") win.resize(1000,600) win.setWindowTitle('pyqtgraph example: Plotting') diff --git a/examples/ROIExamples.py b/examples/ROIExamples.py index a48fa7b5..2b922359 100644 --- a/examples/ROIExamples.py +++ b/examples/ROIExamples.py @@ -33,7 +33,7 @@ arr[8:13, 44:46] = 10 ## create GUI app = QtGui.QApplication([]) -w = pg.GraphicsWindow(size=(1000,800), border=True) +w = pg.GraphicsLayoutWidget(show=True, size=(1000,800), border=True) w.setWindowTitle('pyqtgraph example: ROI Examples') text = """Data Selection From Image.
\n diff --git a/examples/ROItypes.py b/examples/ROItypes.py index 9e67ebe1..1a064d33 100644 --- a/examples/ROItypes.py +++ b/examples/ROItypes.py @@ -13,7 +13,7 @@ pg.setConfigOptions(imageAxisOrder='row-major') ## create GUI app = QtGui.QApplication([]) -w = pg.GraphicsWindow(size=(800,800), border=True) +w = pg.GraphicsLayoutWidget(show=True, size=(800,800), border=True) v = w.addViewBox(colspan=2) v.invertY(True) ## Images usually have their Y-axis pointing downward v.setAspectLocked(True) diff --git a/examples/ScaleBar.py b/examples/ScaleBar.py index 5f9675e4..f125eb73 100644 --- a/examples/ScaleBar.py +++ b/examples/ScaleBar.py @@ -9,7 +9,7 @@ from pyqtgraph.Qt import QtCore, QtGui import numpy as np pg.mkQApp() -win = pg.GraphicsWindow() +win = pg.GraphicsLayoutWidget(show=True) win.setWindowTitle('pyqtgraph example: ScaleBar') vb = win.addViewBox() diff --git a/examples/Symbols.py b/examples/Symbols.py index 3dd28e13..417df35e 100755 --- a/examples/Symbols.py +++ b/examples/Symbols.py @@ -11,7 +11,7 @@ from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg app = QtGui.QApplication([]) -win = pg.GraphicsWindow(title="Scatter Plot Symbols") +win = pg.GraphicsLayoutWidget(show=True, title="Scatter Plot Symbols") win.resize(1000,600) pg.setConfigOptions(antialias=True) diff --git a/examples/ViewBoxFeatures.py b/examples/ViewBoxFeatures.py index 6388e41b..5757924b 100644 --- a/examples/ViewBoxFeatures.py +++ b/examples/ViewBoxFeatures.py @@ -16,7 +16,7 @@ x = np.arange(1000, dtype=float) y = np.random.normal(size=1000) y += 5 * np.sin(x/100) -win = pg.GraphicsWindow() +win = pg.GraphicsLayoutWidget(show=True) win.setWindowTitle('pyqtgraph example: ____') win.resize(1000, 800) win.ci.setBorder((50, 50, 100)) diff --git a/examples/contextMenu.py b/examples/contextMenu.py index c2c5918d..c08008aa 100644 --- a/examples/contextMenu.py +++ b/examples/contextMenu.py @@ -14,7 +14,7 @@ import pyqtgraph as pg from pyqtgraph.Qt import QtCore, QtGui import numpy as np -win = pg.GraphicsWindow() +win = pg.GraphicsLayoutWidget(show=True) win.setWindowTitle('pyqtgraph example: context menu') diff --git a/examples/crosshair.py b/examples/crosshair.py index 076fab49..584eced8 100644 --- a/examples/crosshair.py +++ b/examples/crosshair.py @@ -13,7 +13,7 @@ from pyqtgraph.Point import Point #generate layout app = QtGui.QApplication([]) -win = pg.GraphicsWindow() +win = pg.GraphicsLayoutWidget(show=True) win.setWindowTitle('pyqtgraph example: crosshair') label = pg.LabelItem(justify='right') win.addItem(label) diff --git a/examples/histogram.py b/examples/histogram.py index 2674ba30..a25f0947 100644 --- a/examples/histogram.py +++ b/examples/histogram.py @@ -8,7 +8,7 @@ import pyqtgraph as pg from pyqtgraph.Qt import QtCore, QtGui import numpy as np -win = pg.GraphicsWindow() +win = pg.GraphicsLayoutWidget(show=True) win.resize(800,350) win.setWindowTitle('pyqtgraph example: Histogram') plt1 = win.addPlot() diff --git a/examples/isocurve.py b/examples/isocurve.py index b401dfe1..6d89bbec 100644 --- a/examples/isocurve.py +++ b/examples/isocurve.py @@ -20,7 +20,7 @@ data = np.concatenate([data, data], axis=0) data = pg.gaussianFilter(data, (10, 10, 10))[frames/2:frames + frames/2] data[:, 15:16, 15:17] += 1 -win = pg.GraphicsWindow() +win = pg.GraphicsLayoutWidget(show=True) win.setWindowTitle('pyqtgraph example: Isocurve') vb = win.addViewBox() img = pg.ImageItem(data[0]) diff --git a/examples/linkedViews.py b/examples/linkedViews.py index e7eb18af..34f2b698 100644 --- a/examples/linkedViews.py +++ b/examples/linkedViews.py @@ -20,7 +20,7 @@ app = QtGui.QApplication([]) x = np.linspace(-50, 50, 1000) y = np.sin(x) / x -win = pg.GraphicsWindow(title="pyqtgraph example: Linked Views") +win = pg.GraphicsLayoutWidget(show=True, title="pyqtgraph example: Linked Views") win.resize(800,600) win.addLabel("Linked Views", colspan=2) diff --git a/examples/logAxis.py b/examples/logAxis.py index a0c7fc53..3b30c50b 100644 --- a/examples/logAxis.py +++ b/examples/logAxis.py @@ -11,7 +11,7 @@ import pyqtgraph as pg app = QtGui.QApplication([]) -w = pg.GraphicsWindow() +w = pg.GraphicsLayoutWidget(show=True) w.setWindowTitle('pyqtgraph example: logAxis') p1 = w.addPlot(0,0, title="X Semilog") p2 = w.addPlot(1,0, title="Y Semilog") diff --git a/examples/optics_demos.py b/examples/optics_demos.py index 36bfc7f9..b2ac5c8a 100644 --- a/examples/optics_demos.py +++ b/examples/optics_demos.py @@ -17,7 +17,7 @@ from pyqtgraph import Point app = pg.QtGui.QApplication([]) -w = pg.GraphicsWindow(border=0.5) +w = pg.GraphicsLayoutWidget(show=True, border=0.5) w.resize(1000, 900) w.show() diff --git a/examples/scrollingPlots.py b/examples/scrollingPlots.py index 313d4e8d..d370aa46 100644 --- a/examples/scrollingPlots.py +++ b/examples/scrollingPlots.py @@ -8,7 +8,7 @@ import pyqtgraph as pg from pyqtgraph.Qt import QtCore, QtGui import numpy as np -win = pg.GraphicsWindow() +win = pg.GraphicsLayoutWidget(show=True) win.setWindowTitle('pyqtgraph example: Scrolling Plots') diff --git a/pyqtgraph/Qt.py b/pyqtgraph/Qt.py index 749943f2..8c0041df 100644 --- a/pyqtgraph/Qt.py +++ b/pyqtgraph/Qt.py @@ -272,3 +272,11 @@ m = re.match(r'(\d+)\.(\d+).*', QtVersion) if m is not None and list(map(int, m.groups())) < versionReq: print(list(map(int, m.groups()))) raise Exception('pyqtgraph requires Qt version >= %d.%d (your version is %s)' % (versionReq[0], versionReq[1], QtVersion)) + + +QAPP = None +def mkQApp(): + global QAPP + if QtGui.QApplication.instance() is None: + QAPP = QtGui.QApplication([]) + return QAPP diff --git a/pyqtgraph/__init__.py b/pyqtgraph/__init__.py index 520ea196..583aeaa0 100644 --- a/pyqtgraph/__init__.py +++ b/pyqtgraph/__init__.py @@ -10,7 +10,7 @@ __version__ = '0.10.0' ## 'Qt' is a local module; it is intended mainly to cover up the differences ## between PyQt4 and PySide. -from .Qt import QtGui +from .Qt import QtGui, mkQApp ## not really safe--If we accidentally create another QApplication, the process hangs (and it is very difficult to trace the cause) #if QtGui.QApplication.instance() is None: @@ -466,14 +466,3 @@ def stack(*args, **kwds): except NameError: consoles = [c] return c - - -def mkQApp(): - global QAPP - inst = QtGui.QApplication.instance() - if inst is None: - QAPP = QtGui.QApplication([]) - else: - QAPP = inst - return QAPP - diff --git a/pyqtgraph/graphicsWindows.py b/pyqtgraph/graphicsWindows.py index 41c8b4d2..b6598685 100644 --- a/pyqtgraph/graphicsWindows.py +++ b/pyqtgraph/graphicsWindows.py @@ -6,17 +6,11 @@ it is possible to place any widget into its own window by simply calling its show() method. """ -from .Qt import QtCore, QtGui +from .Qt import QtCore, QtGui, mkQApp from .widgets.PlotWidget import * from .imageview import * from .widgets.GraphicsLayoutWidget import GraphicsLayoutWidget from .widgets.GraphicsView import GraphicsView -QAPP = None - -def mkQApp(): - if QtGui.QApplication.instance() is None: - global QAPP - QAPP = QtGui.QApplication([]) class GraphicsWindow(GraphicsLayoutWidget): diff --git a/pyqtgraph/widgets/GraphicsLayoutWidget.py b/pyqtgraph/widgets/GraphicsLayoutWidget.py index d42378d5..3b41a3ca 100644 --- a/pyqtgraph/widgets/GraphicsLayoutWidget.py +++ b/pyqtgraph/widgets/GraphicsLayoutWidget.py @@ -1,4 +1,4 @@ -from ..Qt import QtGui +from ..Qt import QtGui, mkQApp from ..graphicsItems.GraphicsLayout import GraphicsLayout from .GraphicsView import GraphicsView @@ -48,6 +48,7 @@ class GraphicsLayoutWidget(GraphicsView): :func:`clear ` """ def __init__(self, parent=None, show=False, size=None, title=None, **kargs): + mkQApp() GraphicsView.__init__(self, parent) self.ci = GraphicsLayout(**kargs) for n in ['nextRow', 'nextCol', 'nextColumn', 'addPlot', 'addViewBox', 'addItem', 'getItem', 'addLayout', 'addLabel', 'removeItem', 'itemIndex', 'clear']: diff --git a/pyqtgraph/widgets/__init__.py b/pyqtgraph/widgets/__init__.py index a81fe391..e69de29b 100644 --- a/pyqtgraph/widgets/__init__.py +++ b/pyqtgraph/widgets/__init__.py @@ -1,21 +0,0 @@ -## just import everything from sub-modules - -#import os - -#d = os.path.split(__file__)[0] -#files = [] -#for f in os.listdir(d): - #if os.path.isdir(os.path.join(d, f)): - #files.append(f) - #elif f[-3:] == '.py' and f != '__init__.py': - #files.append(f[:-3]) - -#for modName in files: - #mod = __import__(modName, globals(), locals(), fromlist=['*']) - #if hasattr(mod, '__all__'): - #names = mod.__all__ - #else: - #names = [n for n in dir(mod) if n[0] != '_'] - #for k in names: - #print modName, k - #globals()[k] = getattr(mod, k)