Skip to content

Commit

Permalink
Fix use of "%matplotlib osx" (#1237)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 authored Jun 14, 2024
1 parent 4dc77d7 commit 22d4e58
Showing 1 changed file with 18 additions and 1 deletion.
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

0 comments on commit 22d4e58

Please sign in to comment.