From f1999d9a2c2f7e72c42524f95754bb30f392641f Mon Sep 17 00:00:00 2001 From: Kenneth Lyons Date: Fri, 5 Feb 2021 20:23:15 -0800 Subject: [PATCH] Guard against key events when there's no time axis in ImageView --- pyqtgraph/imageview/ImageView.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pyqtgraph/imageview/ImageView.py b/pyqtgraph/imageview/ImageView.py index 4d438289..2cbafce7 100644 --- a/pyqtgraph/imageview/ImageView.py +++ b/pyqtgraph/imageview/ImageView.py @@ -429,7 +429,10 @@ class ImageView(QtGui.QWidget): self.setParent(None) def keyPressEvent(self, ev): - #print ev.key() + if not self.hasTimeAxis(): + super().keyPressEvent(ev) + return + if ev.key() == QtCore.Qt.Key_Space: if self.playRate == 0: self.play() @@ -454,6 +457,10 @@ class ImageView(QtGui.QWidget): super().keyPressEvent(ev) def keyReleaseEvent(self, ev): + if not self.hasTimeAxis(): + super().keyReleaseEvent(ev) + return + if ev.key() in [QtCore.Qt.Key_Space, QtCore.Qt.Key_Home, QtCore.Qt.Key_End]: ev.accept() elif ev.key() in self.noRepeatKeys: @@ -756,7 +763,7 @@ class ImageView(QtGui.QWidget): def timeIndex(self, slider): ## Return the time and frame index indicated by a slider - if self.image is None: + if not self.hasTimeAxis(): return (0,0) t = slider.value()