Skip to content

Commit 6bbd031

Browse files
committed
Python Console: Fix plotting with the Qt4 backend
Fixes spyder-ide#2231
1 parent 1896cbc commit 6bbd031

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

spyderlib/widgets/externalshell/sitecustomize.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def qt_nt_inputhook():
340340

341341
# Setting the right input hook according to mpl_backend,
342342
# IMPORTANT NOTE: Don't try to abstract the steps to set a PyOS
343-
# input hook callback in a function. It will *crash* the
343+
# input hook callback in a function. It will **crash** the
344344
# interpreter!!
345345
if mpl_backend == "Qt4Agg" and os.name == 'nt' and \
346346
monitor is not None:
@@ -355,9 +355,13 @@ def qt_nt_inputhook():
355355
callback = inputhooks.set_pyft_callback(qt_nt_inputhook)
356356
pyos_ih = inputhooks.get_pyos_inputhook()
357357
pyos_ih.value = ctypes.cast(callback, ctypes.c_void_p).value
358-
elif mpl_backend == "Qt4Agg" and os.environ["QT_API"] == 'pyside':
359-
# PySide doesn't have an input hook, so we need to install one
360-
# to be able to show plots.
358+
elif mpl_backend == "Qt4Agg":
359+
# PyQt4 input hook stopped working after we moved to the new
360+
# style for signals and slots, so we need to install our own
361+
if os.environ["QT_API"] == 'pyqt':
362+
inputhooks.remove_pyqt_inputhook()
363+
# This works for both PySide (which doesn't have an input hook)
364+
# and PyQt4 (whose input hook needs to be replaced, see above).
361365
# Note: This only works well for Posix systems
362366
callback = inputhooks.set_pyft_callback(inputhooks.qt4)
363367
pyos_ih = inputhooks.get_pyos_inputhook()

0 commit comments

Comments
 (0)