PyDev.Debugger icon indicating copy to clipboard operation
PyDev.Debugger copied to clipboard

Need a way to disable ipython qt4 inputhook

Open stuarteberg opened this issue 9 years ago • 0 comments

The PyDev interactive console has a nice feature for debugging GUI applications: Even when the debugger is stopped at a breakpoint, your app will continue processing input events.

In the case of a PyQt app, this is achieved using the inputhookqt4 module (originally from the IPython project). It keeps the app responsive by periodically calling QApplication.processEvents().

That works well within a REPL such as IPython because it is usually called from "outside" the main eventloop. But it can cause problems when used from PyDev's interactive debugger, if the debugger is stopped at a breakpoint within some code that is already handling an event.

In particular, it is illegal to call QApplication.processEvents() from within a paint() function (or drawBackground(), etc.). Doing so violates some rules about how QWidgets are supposed to be used. If you're lucky, you'll just see warnings like this:

QWidget::repaint: Recursive repaint detected
QWidget: It is dangerous to leave painters active on a widget outside of the PaintEvent

...but if you're not lucky, you'll see a Segmentation Fault.

I am currently trying to debug some code of mine that happens to run within the drawing functions of some QWidget classes, but every time I set a breakpoint in that code, I encounter this problem. Is there an easy way to disable the qt inputhook code?

I already tried disabling "event loop integration" in the PyDev preferences as shown below, but that doesn't seem to make a difference. (Actually, it was already configured this way -- this was apparently the default setting.)

screen shot 2016-04-24 at 2 18 33 pm

OK, I can forcibly disable it by editing /Applications/eclipse/plugins/org.python.pydev_4.5.5.201603221110/pysrc/pydev_ipython/inputhookqt4.py as follows:

def create_inputhook_qt4(mgr, app=None):

    ...

    def inputhook_qt4():
        return 0 # Permanently disable

    ...

...but if there's a more elegant solution, I'd love to hear about it.

stuarteberg avatar Apr 24 '16 18:04 stuarteberg