Commit d83869c9 authored by Luke Campagnola's avatar Luke Campagnola
Browse files

GraphicsItem.getViewWidget() returns None if widget has been deleted by Qt

Merge remote-tracking branch 'fabioz/fix_widget_dead' into develop
parents 6c6beed7 e46bb314
from ..Qt import QtGui, QtCore from ..Qt import QtGui, QtCore, isQObjectAlive
from ..GraphicsScene import GraphicsScene from ..GraphicsScene import GraphicsScene
from ..Point import Point from ..Point import Point
from .. import functions as fn from .. import functions as fn
...@@ -42,8 +42,11 @@ class GraphicsItem(object): ...@@ -42,8 +42,11 @@ class GraphicsItem(object):
def getViewWidget(self): def getViewWidget(self):
""" """
Return the view widget for this item. If the scene has multiple views, only the first view is returned. Return the view widget for this item.
The return value is cached; clear the cached value with forgetViewWidget()
If the scene has multiple views, only the first view is returned.
The return value is cached; clear the cached value with forgetViewWidget().
If the view has been deleted by Qt, return None.
""" """
if self._viewWidget is None: if self._viewWidget is None:
scene = self.scene() scene = self.scene()
...@@ -53,7 +56,12 @@ class GraphicsItem(object): ...@@ -53,7 +56,12 @@ class GraphicsItem(object):
if len(views) < 1: if len(views) < 1:
return None return None
self._viewWidget = weakref.ref(self.scene().views()[0]) self._viewWidget = weakref.ref(self.scene().views()[0])
return self._viewWidget()
v = self._viewWidget()
if v is not None and not isQObjectAlive(v):
return None
return v
def forgetViewWidget(self): def forgetViewWidget(self):
self._viewWidget = None self._viewWidget = None
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment