megies / obspyck

ObsPyck is a GUI application that is intended to cover the tasks in a standard analysis workflow for seismic events in seismological observatory practice.
https://github.com/megies/obspyck/wiki
GNU General Public License v2.0
61 stars 32 forks source link

Problems with key modifiers (holding down keys in GUI to change behavior) after port to Py3/Qt5 #97

Open megies opened 3 years ago

megies commented 3 years ago

This is just a reminder that there seem to be some problems in some cases where PyQt5.QtCore.Qt.ShiftModifier (enum with integer value 33554432) does not match the key number emitted by holding shift.

A quick hack is to modify the code, but curious how this happens..

Use the above logging to find out what holding shift emits as modifier value and hardcode it below to make holding shift in the GUI work again..

diff --git a/obspyck/obspyck.py b/obspyck/obspyck.py
index 42cf70a..040ac5a 100755
--- a/obspyck/obspyck.py
+++ b/obspyck/obspyck.py
@@ -1827,6 +1827,7 @@ class ObsPyck(QtWidgets.QMainWindow):
         (bottom, top) = ax.get_ybound()
         # Get the keyboard modifiers. They are a enum type.
         # Use bitwise or to compare...hope this is correct.
+        self.critical("%d" % ev.modifiers())
         if ev.modifiers() == QtCore.Qt.NoModifier:
             # Zoom in.
             if ev.angleDelta().y() < 0:
@@ -1843,8 +1844,7 @@ class ObsPyck(QtWidgets.QMainWindow):
                     top += (mpl_ev.ydata - top) / 2
                     bottom -= (bottom - mpl_ev.ydata) / 2
         # Still able to use the dictionary.
-        elif ev.modifiers() == getattr(QtCore.Qt,
-                '%sModifier' % self.keys['switchWheelZoomAxis'].capitalize()):
+        elif int(ev.modifiers()) == 33554432:
             if self.widgets.qToolButton_spectrogram.isChecked():
             # Zoom in on wheel-up
                 if ev.angleDelta().y() < 0: