Skip to content

Commit

Permalink
Python Console: Fix crash after first execution
Browse files Browse the repository at this point in the history
Fixes #2308

- The crash was caused because we were trying to install our own input
hook in PyQt4, which seems to be not possible.
- It also reverts commit 6bbd031 because it was the wrong solution.
  • Loading branch information
ccordoba12 committed Jul 12, 2015
1 parent 5cb29ef commit fbd66cb
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions spyderlib/widgets/externalshell/sitecustomize.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,23 +262,21 @@ def open_in_spyder(source, lineno=1):
_print("Can't open file %s" % source, file=sys.stderr)
builtins.open_in_spyder = open_in_spyder

if os.environ["QT_API"] == 'pyqt5':
from PyQt5 import QtCore
# Removing PyQt's PyOS_InputHook implementation:
QtCore.pyqtRemoveInputHook()
elif os.environ["QT_API"] == 'pyqt':
from PyQt4 import QtCore
QtCore.pyqtRemoveInputHook()
elif os.environ["QT_API"] == 'pyside':
from PySide import QtCore #analysis:ignore

def qt_nt_inputhook():
"""Qt input hook for Windows
This input hook wait for available stdin data (notified by
ExternalPythonShell through the monitor's inputhook_flag
attribute), and in the meantime it processes Qt events.
"""
# Qt imports
if os.environ["QT_API"] == 'pyqt5':
from PyQt5 import QtCore
elif os.environ["QT_API"] == 'pyqt':
from PyQt4 import QtCore # analysis:ignore
elif os.environ["QT_API"] == 'pyside':
from PySide import QtCore # analysis:ignore

# Refreshing variable explorer, except on first input hook call:
# (otherwise, on slow machines, this may freeze Spyder)
monitor.refresh_from_inputhook()
Expand Down Expand Up @@ -355,13 +353,9 @@ def qt_nt_inputhook():
callback = inputhooks.set_pyft_callback(qt_nt_inputhook)
pyos_ih = inputhooks.get_pyos_inputhook()
pyos_ih.value = ctypes.cast(callback, ctypes.c_void_p).value
elif mpl_backend == "Qt4Agg":
# PyQt4 input hook stopped working after we moved to the new
# style for signals and slots, so we need to install our own
if os.environ["QT_API"] == 'pyqt':
inputhooks.remove_pyqt_inputhook()
# This works for both PySide (which doesn't have an input hook)
# and PyQt4 (whose input hook needs to be replaced, see above).
elif mpl_backend == "Qt4Agg" and os.environ["QT_API"] == 'pyside':
# PySide doesn't have an input hook, so we need to install one
# to be able to show plots
# Note: This only works well for Posix systems
callback = inputhooks.set_pyft_callback(inputhooks.qt4)
pyos_ih = inputhooks.get_pyos_inputhook()
Expand Down

0 comments on commit fbd66cb

Please sign in to comment.