Have __init__.plot() use PlotWidget, not deprecated PlotWindow

This commit is contained in:
Ogi Moore 2021-02-11 21:55:04 -08:00
parent ff71b6be6b
commit b45386ebc5
2 changed files with 12 additions and 35 deletions

View File

@ -384,29 +384,18 @@ def exit():
os._exit(0) os._exit(0)
## Convenience functions for command-line use ## Convenience functions for command-line use
plots = [] plots = []
images = [] images = []
QAPP = None QAPP = None
def plot(*args, **kargs): def plot(*args, **kargs):
""" """
Create and return a :class:`PlotWindow <pyqtgraph.PlotWindow>` Create and return a :class:`PlotWidget <pyqtgraph.PlotWinPlotWidgetdow>`
(this is just a window with :class:`PlotWidget <pyqtgraph.PlotWidget>` inside), plot data in it.
Accepts a *title* argument to set the title of the window. Accepts a *title* argument to set the title of the window.
All other arguments are used to plot data. (see :func:`PlotItem.plot() <pyqtgraph.PlotItem.plot>`) All other arguments are used to plot data. (see :func:`PlotItem.plot() <pyqtgraph.PlotItem.plot>`)
""" """
mkQApp() mkQApp()
#if 'title' in kargs:
#w = PlotWindow(title=kargs['title'])
#del kargs['title']
#else:
#w = PlotWindow()
#if len(args)+len(kargs) > 0:
#w.plot(*args, **kargs)
pwArgList = ['title', 'labels', 'name', 'left', 'right', 'top', 'bottom', 'background'] pwArgList = ['title', 'labels', 'name', 'left', 'right', 'top', 'bottom', 'background']
pwArgs = {} pwArgs = {}
dataArgs = {} dataArgs = {}
@ -415,44 +404,32 @@ def plot(*args, **kargs):
pwArgs[k] = kargs[k] pwArgs[k] = kargs[k]
else: else:
dataArgs[k] = kargs[k] dataArgs[k] = kargs[k]
windowTitle = pwArgs.pop("title", "PlotWidget")
w = PlotWindow(**pwArgs) w = PlotWidget(**pwArgs)
w.sigClosed.connect(_plotWindowClosed) w.setWindowTitle(windowTitle)
if len(args) > 0 or len(dataArgs) > 0: if len(args) > 0 or len(dataArgs) > 0:
w.plot(*args, **dataArgs) w.plot(*args, **dataArgs)
plots.append(w) plots.append(w)
w.show() w.show()
return w return w
def _plotWindowClosed(w):
w.close()
try:
plots.remove(w)
except ValueError:
pass
def image(*args, **kargs): def image(*args, **kargs):
""" """
Create and return an :class:`ImageWindow <pyqtgraph.ImageWindow>` Create and return an :class:`ImageView <pyqtgraph.ImageView>`
(this is just a window with :class:`ImageView <pyqtgraph.ImageView>` widget inside), show image data inside.
Will show 2D or 3D image data. Will show 2D or 3D image data.
Accepts a *title* argument to set the title of the window. Accepts a *title* argument to set the title of the window.
All other arguments are used to show data. (see :func:`ImageView.setImage() <pyqtgraph.ImageView.setImage>`) All other arguments are used to show data. (see :func:`ImageView.setImage() <pyqtgraph.ImageView.setImage>`)
""" """
mkQApp() mkQApp()
w = ImageWindow(*args, **kargs) w = ImageView()
w.sigClosed.connect(_imageWindowClosed) windowTitle = kargs.pop("title", "ImageView")
w.setWindowTitle(windowTitle)
w.setImage(*args, **kargs)
images.append(w) images.append(w)
w.show() w.show()
return w return w
show = image ## for backward compatibility show = image ## for backward compatibility
def _imageWindowClosed(w):
w.close()
try:
images.remove(w)
except ValueError:
pass
def dbg(*args, **kwds): def dbg(*args, **kwds):
""" """

View File

@ -10,11 +10,11 @@ app = pg.mkQApp()
def test_ImageItem(transpose=False): def test_ImageItem(transpose=False):
w = pg.GraphicsWindow() w = pg.GraphicsLayoutWidget()
w.show()
view = pg.ViewBox() view = pg.ViewBox()
w.setCentralWidget(view) w.setCentralWidget(view)
w.resize(200, 200) w.resize(200, 200)
w.show()
img = TransposedImageItem(border=0.5, transpose=transpose) img = TransposedImageItem(border=0.5, transpose=transpose)
view.addItem(img) view.addItem(img)