From 585390e16ebbc7eb993c78216cc88e439c5bfe60 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Tue, 10 Jul 2018 05:23:53 -0700 Subject: [PATCH 1/2] fix: mouse wheel on viewbox leaves autorange unaffected if mouse is disabled for one axis --- pyqtgraph/graphicsItems/ViewBox/ViewBox.py | 34 +++++++++------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/pyqtgraph/graphicsItems/ViewBox/ViewBox.py b/pyqtgraph/graphicsItems/ViewBox/ViewBox.py index 02a8ddad..b1cd3c10 100644 --- a/pyqtgraph/graphicsItems/ViewBox/ViewBox.py +++ b/pyqtgraph/graphicsItems/ViewBox/ViewBox.py @@ -662,21 +662,13 @@ class ViewBox(GraphicsWidget): cause slight changes due to floating-point error). """ if s is not None: - scale = Point(s) - else: - scale = [x, y] + x, y = s[0], s[1] - affect = [True, True] - if scale[0] is None and scale[1] is None: + affect = [x is not None, y is not None] + if not any(affect): return - elif scale[0] is None: - affect[0] = False - scale[0] = 1.0 - elif scale[1] is None: - affect[1] = False - scale[1] = 1.0 - - scale = Point(scale) + + scale = Point([1.0 if x is None else x, 1.0 if y is None else y]) if self.state['aspectLocked'] is not False: scale[0] = scale[1] @@ -1132,19 +1124,19 @@ class ViewBox(GraphicsWidget): """Return the bounding rect of the item in view coordinates""" return self.mapSceneToView(item.sceneBoundingRect()).boundingRect() - def wheelEvent(self, ev, axis=None): - mask = np.array(self.state['mouseEnabled'], dtype=np.float) + def wheelEvent(self, ev, axis=None): if axis is not None and axis >= 0 and axis < len(mask): - mv = mask[axis] - mask[:] = 0 - mask[axis] = mv - s = ((mask * 0.02) + 1) ** (ev.delta() * self.state['wheelScaleFactor']) # actual scaling factor - + mask = [False, False] + mask[axis] = self.state['mouseEnabled'][axis] + else: + mask = self.state['mouseEnabled'][:] + s = 1.02 ** (ev.delta() * self.state['wheelScaleFactor']) # actual scaling factor + s = [(None if m is False else s) for m in mask] center = Point(fn.invertQTransform(self.childGroup.transform()).map(ev.pos())) self._resetTarget() self.scaleBy(s, center) - self.sigRangeChangedManually.emit(self.state['mouseEnabled']) + self.sigRangeChangedManually.emit(mask) ev.accept() def mouseClickEvent(self, ev): From 2884eef0796351555b4cc80abcb070b00f187be0 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Tue, 10 Jul 2018 05:56:35 -0700 Subject: [PATCH 2/2] Add ViewBoxFeatures to example menu --- examples/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/utils.py b/examples/utils.py index b004a0d3..f7786dba 100644 --- a/examples/utils.py +++ b/examples/utils.py @@ -19,6 +19,7 @@ examples = OrderedDict([ ('Data Slicing', 'DataSlicing.py'), ('Plot Customization', 'customPlot.py'), ('Image Analysis', 'imageAnalysis.py'), + ('ViewBox Features', 'ViewBoxFeatures.py'), ('Dock widgets', 'dockarea.py'), ('Console', 'ConsoleWidget.py'), ('Histograms', 'histogram.py'), @@ -50,7 +51,7 @@ examples = OrderedDict([ ('Text Item', 'text.py'), ('Linked Views', 'linkedViews.py'), ('Arrow', 'Arrow.py'), - ('ViewBox', 'ViewBox.py'), + ('ViewBox', 'ViewBoxFeatures.py'), ('Custom Graphics', 'customGraphicsItem.py'), ('Labeled Graph', 'CustomGraphItem.py'), ])),