Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion ipykernel/_eventloop_macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
objc.objc_getClass.restype = void_p
objc.sel_registerName.restype = void_p
objc.objc_msgSend.restype = void_p
objc.objc_msgSend.argtypes = [void_p, void_p]

msg = objc.objc_msgSend

Expand Down Expand Up @@ -80,11 +79,25 @@ def C(classname):

def _NSApp():
"""Return the global NSApplication instance (NSApp)"""
objc.objc_msgSend.argtypes = [void_p, void_p]
return msg(C("NSApplication"), n("sharedApplication"))


def _wake(NSApp):
"""Wake the Application"""
objc.objc_msgSend.argtypes = [
void_p,
void_p,
void_p,
void_p,
void_p,
void_p,
void_p,
void_p,
void_p,
void_p,
void_p,
]
event = msg(
C("NSEvent"),
n(
Expand All @@ -101,6 +114,7 @@ def _wake(NSApp):
0, # data1
0, # data2
)
objc.objc_msgSend.argtypes = [void_p, void_p, void_p, void_p]
msg(NSApp, n("postEvent:atStart:"), void_p(event), True)


Expand All @@ -113,7 +127,9 @@ def stop(timer=None, loop=None):
NSApp = _NSApp()
# if NSApp is not running, stop CFRunLoop directly,
# otherwise stop and wake NSApp
objc.objc_msgSend.argtypes = [void_p, void_p]
if msg(NSApp, n("isRunning")):
objc.objc_msgSend.argtypes = [void_p, void_p, void_p]
msg(NSApp, n("stop:"), NSApp)
_wake(NSApp)
else:
Expand Down Expand Up @@ -148,6 +164,7 @@ def mainloop(duration=1):
_triggered.clear()
NSApp = _NSApp()
_stop_after(duration)
objc.objc_msgSend.argtypes = [void_p, void_p]
msg(NSApp, n("run"))
if not _triggered.is_set():
# app closed without firing callback,
Expand Down