From 96a4ff7cd5235441b890433154c72972a7977fc9 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Mon, 4 Nov 2013 22:07:43 -0500 Subject: [PATCH] Fixes: - ROI updates on sigTransformChanged - ViewBox is more careful about accepting all auto-range changes up to the point it is disabled, even if the auto-range calculation is deferred. --- examples/ROIExamples.py | 2 +- examples/crosshair.py | 4 ++- pyqtgraph/graphicsItems/ROI.py | 7 ++-- pyqtgraph/graphicsItems/ViewBox/ViewBox.py | 38 ++++++++++++---------- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/examples/ROIExamples.py b/examples/ROIExamples.py index a67e279d..56b15bcf 100644 --- a/examples/ROIExamples.py +++ b/examples/ROIExamples.py @@ -27,7 +27,7 @@ arr += np.random.normal(size=(100,100)) ## create GUI app = QtGui.QApplication([]) -w = pg.GraphicsWindow(size=(800,800), border=True) +w = pg.GraphicsWindow(size=(1000,800), border=True) w.setWindowTitle('pyqtgraph example: ROI Examples') text = """Data Selection From Image.
\n diff --git a/examples/crosshair.py b/examples/crosshair.py index c41dfff1..67d3cc5f 100644 --- a/examples/crosshair.py +++ b/examples/crosshair.py @@ -23,7 +23,9 @@ p2 = win.addPlot(row=2, col=0) region = pg.LinearRegionItem() region.setZValue(10) -p2.addItem(region) +# Add the LinearRegionItem to the ViewBox, but tell the ViewBox to exclude this +# item when doing auto-range calculations. +p2.addItem(region, ignoreBounds=True) #pg.dbg() p1.setAutoVisible(y=True) diff --git a/pyqtgraph/graphicsItems/ROI.py b/pyqtgraph/graphicsItems/ROI.py index 033aab42..f6ce4680 100644 --- a/pyqtgraph/graphicsItems/ROI.py +++ b/pyqtgraph/graphicsItems/ROI.py @@ -1320,7 +1320,6 @@ class Handle(UIGraphicsItem): ## determine rotation of transform #m = self.sceneTransform() ## Qt bug: do not access sceneTransform() until we know this object has a scene. #mi = m.inverted()[0] - dt = self.deviceTransform() if dt is None: @@ -1339,10 +1338,10 @@ class Handle(UIGraphicsItem): return dti.map(tr.map(self.path)) - def viewRangeChanged(self): - GraphicsObject.viewRangeChanged(self) + def viewTransformChanged(self): + GraphicsObject.viewTransformChanged(self) self._shape = None ## invalidate shape, recompute later if requested. - #self.updateShape() + self.update() #def itemChange(self, change, value): #if change == self.ItemScenePositionHasChanged: diff --git a/pyqtgraph/graphicsItems/ViewBox/ViewBox.py b/pyqtgraph/graphicsItems/ViewBox/ViewBox.py index 8dbaf9ef..f0ea1e57 100644 --- a/pyqtgraph/graphicsItems/ViewBox/ViewBox.py +++ b/pyqtgraph/graphicsItems/ViewBox/ViewBox.py @@ -213,8 +213,9 @@ class ViewBox(GraphicsWidget): return ret def prepareForPaint(self): - autoRangeEnabled = (self.state['autoRange'][0] is not False) or (self.state['autoRange'][1] is not False) - if self._autoRangeNeedsUpdate and autoRangeEnabled: + #autoRangeEnabled = (self.state['autoRange'][0] is not False) or (self.state['autoRange'][1] is not False) + # don't check whether auto range is enabled here--only check when setting dirty flag. + if self._autoRangeNeedsUpdate: # and autoRangeEnabled: self.updateAutoRange() if self._matrixNeedsUpdate: self.updateMatrix() @@ -332,22 +333,15 @@ class ViewBox(GraphicsWidget): ch.setParentItem(None) def resizeEvent(self, ev): - #print self.name, "ViewBox.resizeEvent", self.size() - #self.setRange(self.range, padding=0) - #x,y = self.targetRange() - #self.setRange(xRange=x, yRange=y, padding=0) self.linkedXChanged() self.linkedYChanged() self.updateAutoRange() self.updateViewRange() - #self.updateMatrix() self.sigStateChanged.emit(self) self.background.setRect(self.rect()) - #self._itemBoundsCache.clear() - #self.linkedXChanged() - #self.linkedYChanged() self.sigResized.emit(self) + def viewRange(self): """Return a the view's visible range as a list: [[xmin, xmax], [ymin, ymax]]""" return [x[:] for x in self.state['viewRange']] ## return copy @@ -485,10 +479,10 @@ class ViewBox(GraphicsWidget): # If ortho axes have auto-visible-only, update them now # Note that aspect ratio constraints and auto-visible probably do not work together.. - if changed[0] and self.state['autoVisibleOnly'][1]: + if changed[0] and self.state['autoVisibleOnly'][1] and (self.state['autoRange'][0] is not False): self._autoRangeNeedsUpdate = True #self.updateAutoRange() ## Maybe just indicate that auto range needs to be updated? - elif changed[1] and self.state['autoVisibleOnly'][0]: + elif changed[1] and self.state['autoVisibleOnly'][0] and (self.state['autoRange'][1] is not False): self._autoRangeNeedsUpdate = True #self.updateAutoRange() @@ -662,11 +656,18 @@ class ViewBox(GraphicsWidget): for ax in axes: if self.state['autoRange'][ax] != enable: + # If we are disabling, do one last auto-range to make sure that + # previously scheduled auto-range changes are enacted + if enable is False and self._autoRangeNeedsUpdate: + self.updateAutoRange() + self.state['autoRange'][ax] = enable - needAutoRangeUpdate |= (enable is not False) - - if needAutoRangeUpdate: - self.updateAutoRange() + self._autoRangeNeedsUpdate |= (enable is not False) + self.update() + + + #if needAutoRangeUpdate: + # self.updateAutoRange() self.sigStateChanged.emit(self) @@ -901,8 +902,9 @@ class ViewBox(GraphicsWidget): def itemBoundsChanged(self, item): self._itemBoundsCache.pop(item, None) - self._autoRangeNeedsUpdate = True - self.update() + if (self.state['autoRange'][0] is not False) or (self.state['autoRange'][1] is not False): + self._autoRangeNeedsUpdate = True + self.update() #self.updateAutoRange() def invertY(self, b=True):