pyqtgraph/pyqtgraph/graphicsWindows.py
Adam Strzelecki 983cc1695e
Patch/window handling (#468)
* Do not wrap PlotView/ImageView

There is no need to wrap PlotView/ImageView into QMainWindow, since
only purpose of the QMainWindow is some default menu toolbar & menu
handling, that is not used by PyQtGraph anyway.

Moreover, every parent-less Qt widget can become window, so this
change just use PlotView/ImageView as windows, removing extra
complexity, eg. method forwarding, self.win property.

Another benefit of this change, it that these windows get initial
dimensions and titles as they were designed in .ui file.

* Properly cleanup on ImageView.close()

We should not close explicitly child widgets or clear scene, otherwise
Qt will deallocate children views, and cause "wrapped C/C++ object of
type ImageItem has been deleted" error next time we call close()
and/or some other methods.

All children, including self.ui.roiPlot, self.ui.graphicsView will be
closed together with its parent, so there is no need to close them
explicitly.

So the purpose of close it to reclaim the memory, but not to make the existing ImageView object dysfunctional.

* Remove references to plot & image windows after close

PyQtGraph images and plots module list variables are currently holding
references to all plots and image windows returned directly from main
module. This does not seem to be documented however, and causes the Qt
windows to be not released from memory, even if user releases all own
references.

This change removes the references from images/plots list once window
is closed, so when there is no other reference, window and all related
memory is reclaimed.

* Change all UI forms title from Form to PyQtGraph

Co-authored-by: Ogi Moore <ognyan.moore@gmail.com>
2020-06-01 11:23:18 -07:00

87 lines
2.4 KiB
Python

# -*- coding: utf-8 -*-
"""
DEPRECATED: The classes below are convenience classes that create a new window
containting a single, specific widget. These classes are now unnecessary because
it is possible to place any widget into its own window by simply calling its
show() method.
"""
from .Qt import QtCore, QtGui, mkQApp
from .widgets.PlotWidget import *
from .imageview import *
from .widgets.GraphicsLayoutWidget import GraphicsLayoutWidget
from .widgets.GraphicsView import GraphicsView
class GraphicsWindow(GraphicsLayoutWidget):
"""
(deprecated; use :class:`~pyqtgraph.GraphicsLayoutWidget` instead)
Convenience subclass of :class:`~pyqtgraph.GraphicsLayoutWidget`. This class
is intended for use from the interactive python prompt.
"""
def __init__(self, title=None, size=(800,600), **kargs):
mkQApp()
GraphicsLayoutWidget.__init__(self, **kargs)
self.resize(*size)
if title is not None:
self.setWindowTitle(title)
self.show()
class TabWindow(QtGui.QMainWindow):
"""
(deprecated)
"""
def __init__(self, title=None, size=(800,600)):
mkQApp()
QtGui.QMainWindow.__init__(self)
self.resize(*size)
self.cw = QtGui.QTabWidget()
self.setCentralWidget(self.cw)
if title is not None:
self.setWindowTitle(title)
self.show()
def __getattr__(self, attr):
return getattr(self.cw, attr)
class PlotWindow(PlotWidget):
sigClosed = QtCore.Signal(object)
"""
(deprecated; use :class:`~pyqtgraph.PlotWidget` instead)
"""
def __init__(self, title=None, **kargs):
mkQApp()
PlotWidget.__init__(self, **kargs)
if title is not None:
self.setWindowTitle(title)
self.show()
def closeEvent(self, event):
PlotWidget.closeEvent(self, event)
self.sigClosed.emit(self)
class ImageWindow(ImageView):
sigClosed = QtCore.Signal(object)
"""
(deprecated; use :class:`~pyqtgraph.ImageView` instead)
"""
def __init__(self, *args, **kargs):
mkQApp()
ImageView.__init__(self)
if 'title' in kargs:
self.setWindowTitle(kargs['title'])
del kargs['title']
if len(args) > 0 or len(kargs) > 0:
self.setImage(*args, **kargs)
self.show()
def closeEvent(self, event):
ImageView.closeEvent(self, event)
self.sigClosed.emit(self)