'Return the first ViewBox or GraphicsView which bounds this item\'s visible space.
If this item is not contained within a ViewBox, then the GraphicsView is returned.
If the item is contained inside nested ViewBoxes, then the inner-most ViewBox is returned.
The result is cached; clear the cache with forgetViewBox()'

def getViewBox(self):

    if (self._viewBox is None):
        p = self
        while True:
            try:
                p = p.parentItem()
            except RuntimeError:
                return None
            if (p is None):
                vb = self.getViewWidget()
                if (vb is None):
                    return None
                else:
                    self._viewBox = weakref.ref(vb)
                    break
            if (hasattr(p, 'implements') and p.implements('ViewBox')):
                self._viewBox = weakref.ref(p)
                break
    return self._viewBox()
