MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / create_inputhook_qt4

Function create_inputhook_qt4

pydev_ipython/inputhookqt4.py:57–198  ·  view source on GitHub ↗

Create an input hook for running the Qt4 application event loop. Parameters ---------- mgr : an InputHookManager app : Qt Application, optional. Running application to use. If not given, we probe Qt for an existing application object, and create a new one if none i

(mgr, app=None)

Source from the content-addressed store, hash-verified

55
56
57def create_inputhook_qt4(mgr, app=None):
58 """Create an input hook for running the Qt4 application event loop.
59
60 Parameters
61 ----------
62 mgr : an InputHookManager
63
64 app : Qt Application, optional.
65 Running application to use. If not given, we probe Qt for an
66 existing application object, and create a new one if none is found.
67
68 Returns
69 -------
70 A pair consisting of a Qt Application (either the one given or the
71 one found or created) and a inputhook.
72
73 Notes
74 -----
75 We use a custom input hook instead of PyQt4's default one, as it
76 interacts better with the readline packages (issue #481).
77
78 The inputhook function works in tandem with a 'pre_prompt_hook'
79 which automatically restores the hook as an inputhook in case the
80 latter has been temporarily disabled after having intercepted a
81 KeyboardInterrupt.
82 """
83
84 if app is None:
85 app = QtCore.QCoreApplication.instance()
86 if app is None:
87 app = QtGui.QApplication([" "])
88
89 # Re-use previously created inputhook if any
90 ip = InteractiveShell.instance()
91 if hasattr(ip, "_inputhook_qt4"):
92 return app, ip._inputhook_qt4
93
94 # Otherwise create the inputhook_qt4/preprompthook_qt4 pair of
95 # hooks (they both share the got_kbdint flag)
96
97 def inputhook_qt4():
98 """PyOS_InputHook python hook for Qt4.
99
100 Process pending Qt events and if there's no pending keyboard
101 input, spend a short slice of time (50ms) running the Qt event
102 loop.
103
104 As a Python ctypes callback can't raise an exception, we catch
105 the KeyboardInterrupt and temporarily deactivate the hook,
106 which will let a *second* CTRL+C be processed normally and go
107 back to a clean prompt line.
108 """
109 try:
110 allow_CTRL_C()
111 app = QtCore.QCoreApplication.instance()
112 if not app: # shouldn't happen, but safer if it happens anyway...
113 return 0
114 app.processEvents(QtCore.QEventLoop.AllEvents, 300)

Callers 1

enable_qt4Method · 0.90

Calls 2

instanceMethod · 0.45
set_hookMethod · 0.45

Tested by

no test coverage detected