Warn if visible GraphicsView is garbage collected (#942)
* Warn if visible window is garbage collected * (Py)Qt does not rely on Python GC * Only warn if deleted widget has no parents (if it is a standalone window) * Hide windows when closing * Only implement GraphicsView.__del__ if it does not prevent circular reference garbage collection
This commit is contained in:
parent
7b70d66c6a
commit
08c0de768b
@ -121,7 +121,7 @@ def test_ImageItem(transpose=False):
|
||||
assertImageApproved(w, 'imageitem/resolution_with_downsampling_y', 'Resolution test with downsampling across y axis.')
|
||||
assert img._lastDownsample == (1, 4)
|
||||
|
||||
view.hide()
|
||||
w.hide()
|
||||
|
||||
def test_ImageItem_axisorder():
|
||||
# All image tests pass again using the opposite axis order
|
||||
|
@ -153,6 +153,7 @@ def check_getArrayRegion(roi, name, testResize=True, transpose=False):
|
||||
# allow the roi to be re-used
|
||||
roi.scene().removeItem(roi)
|
||||
|
||||
win.hide()
|
||||
|
||||
def test_PolyLineROI():
|
||||
rois = [
|
||||
@ -234,5 +235,6 @@ def test_PolyLineROI():
|
||||
r.setState(initState)
|
||||
assertImageApproved(plt, 'roi/polylineroi/'+name+'_setstate', 'Reset ROI to initial state.')
|
||||
assert len(r.getState()['points']) == 3
|
||||
|
||||
|
||||
|
||||
plt.hide()
|
||||
|
||||
|
@ -15,6 +15,7 @@ except ImportError:
|
||||
|
||||
from ..Point import Point
|
||||
import sys, os
|
||||
import warnings
|
||||
from .FileDialog import FileDialog
|
||||
from ..GraphicsScene import GraphicsScene
|
||||
import numpy as np
|
||||
@ -396,5 +397,11 @@ class GraphicsView(QtGui.QGraphicsView):
|
||||
|
||||
def dragEnterEvent(self, ev):
|
||||
ev.ignore() ## not sure why, but for some reason this class likes to consume drag events
|
||||
|
||||
|
||||
def _del(self):
|
||||
if self.parentWidget() is None and self.isVisible():
|
||||
msg = "Visible window deleted. To prevent this, store a reference to the window object."
|
||||
warnings.warn(msg, RuntimeWarning, stacklevel=2)
|
||||
|
||||
if sys.version_info[0] == 3 and sys.version_info[1] >= 4:
|
||||
GraphicsView.__del__ = GraphicsView._del
|
||||
|
Loading…
Reference in New Issue
Block a user