pyapp-kit / superqt

Missing widgets and components for Qt-python
https://pyapp-kit.github.io/superqt/
BSD 3-Clause "New" or "Revised" License
210 stars 38 forks source link

Add qt_set_trace and install_qt_breakpoint #40

Closed tlambert03 closed 2 years ago

tlambert03 commented 3 years ago

This PR adds a few conveniences around using a debugger with Qt.

to add a breakpoint in Qt code, use it like pdb.set_trace()

from superqt.utils import qt_set_trace; qt_set_trace()

This will stop the event loop so you don't get an endless chain of

QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running
QCoreApplication::exec: The event loop is already running

or to permanently install it so that you can use the builtin breakpoint() anywhere

from superqt.utils import install_qt_breakpoint

install_qt_breakpoint()
codecov-commenter commented 3 years ago

Codecov Report

Merging #40 (132f8b9) into main (e1d2edb) will decrease coverage by 0.70%. The diff coverage is 45.16%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #40      +/-   ##
==========================================
- Coverage   83.95%   83.25%   -0.71%     
==========================================
  Files          20       21       +1     
  Lines        1677     1708      +31     
==========================================
+ Hits         1408     1422      +14     
- Misses        269      286      +17     
Impacted Files Coverage Δ
src/superqt/utils/_breakpoint.py 43.33% <43.33%> (ø)
src/superqt/utils/__init__.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update e1d2edb...132f8b9. Read the comment docs.

tlambert03 commented 3 years ago

holding on this for now.
first: it's only necessary for PyQt5 (pyside already works fine)... second: i want to add a way to accept an arbitrary debugger's set_trace function. The main issue I'm running into (if I don't use the subclass approach here) is that the breakpoint starts at the wrong frame. I essentially want to remove the QtCore.pyqtRemoveInputHook() from the frame stack before starting the debugger...