diff --git a/pyqtgraph/Qt.py b/pyqtgraph/Qt.py index 749943f2..ad2a8007 100644 --- a/pyqtgraph/Qt.py +++ b/pyqtgraph/Qt.py @@ -272,3 +272,10 @@ 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)) + + +def mkQApp(): + app = QtGui.QApplication.instance() + if app is None: + app = QtGui.QApplication([]) + return app 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)