##// END OF EJS Templates
use CFRunLoop directly in `ipython kernel --pylab osx`...
MinRK -
Show More
@@ -586,6 +586,73 b' class GTKKernel(Kernel):'
586 586 gtk_kernel.start()
587 587
588 588
589 class OSXKernel(TkKernel):
590 """A Kernel subclass with Cocoa support via the matplotlib OSX backend."""
591
592 def start(self):
593 """Start the kernel, coordinating with the Cocoa CFRunLoop event loop
594 via the matplotlib MacOSX backend.
595 """
596 import matplotlib
597 if matplotlib.__version__ < '1.1.0':
598 self.log.warn(
599 "MacOSX backend in matplotlib %s doesn't have a Timer, "
600 "falling back on Tk for CFRunLoop integration. Note that "
601 "even this won't work if Tk is linked against X11 instead of "
602 "Cocoa (e.g. EPD). To use the MacOSX backend in the kernel, "
603 "you must use matplotlib >= 1.1.0, or a native libtk."
604 )
605 return TkKernel.start(self)
606
607 from matplotlib.backends.backend_macosx import TimerMac, show
608
609 # scale interval for sec->ms
610 poll_interval = int(1000*self._poll_interval)
611
612 real_excepthook = sys.excepthook
613 def handle_int(etype, value, tb):
614 """don't let KeyboardInterrupts look like crashes"""
615 if etype is KeyboardInterrupt:
616 io.raw_print("KeyboardInterrupt caught in CFRunLoop")
617 else:
618 real_excepthook(etype, value, tb)
619
620 # add doi() as a Timer to the CFRunLoop
621 def doi():
622 # restore excepthook during IPython code
623 sys.excepthook = real_excepthook
624 self.do_one_iteration()
625 # and back:
626 sys.excepthook = handle_int
627 t = TimerMac(poll_interval)
628 t.add_callback(doi)
629 t.start()
630
631 # but still need a Poller for when there are no active windows,
632 # during which time mainloop() returns immediately
633 poller = zmq.Poller()
634 poller.register(self.shell_socket, zmq.POLLIN)
635
636 while True:
637 try:
638 # double nested try/except, to properly catch KeyboardInterrupt
639 # due to pyzmq Issue #130
640 try:
641 # don't let interrupts during mainloop invoke crash_handler:
642 sys.excepthook = handle_int
643 show.mainloop()
644 sys.excepthook = real_excepthook
645 # use poller if mainloop returned (no windows)
646 # scale by extra factor of 10, since it's a real poll
647 poller.poll(10*poll_interval)
648 self.do_one_iteration()
649 except:
650 raise
651 except KeyboardInterrupt:
652 # Ctrl-C shouldn't crash the kernel
653 io.raw_print("KeyboardInterrupt caught in kernel")
654
655
589 656 #-----------------------------------------------------------------------------
590 657 # Aliases and Flags for the IPKernelApp
591 658 #-----------------------------------------------------------------------------
@@ -639,7 +706,7 b' class IPKernelApp(KernelApp, InteractiveShellApp):'
639 706 'qt' : QtKernel,
640 707 'qt4': QtKernel,
641 708 'inline': Kernel,
642 'osx': TkKernel,
709 'osx': OSXKernel,
643 710 'wx' : WxKernel,
644 711 'tk' : TkKernel,
645 712 'gtk': GTKKernel,
@@ -61,7 +61,7 b' Pylab'
61 61 =====
62 62
63 63 One of the most exciting features of the new console is embedded matplotlib
64 figures. You can use any standard matplotlib GUI backend (Except native MacOSX)
64 figures. You can use any standard matplotlib GUI backend
65 65 to draw the figures, and since there is now a two-process model, there is no
66 66 longer a conflict between user input and the drawing eventloop.
67 67
General Comments 0
You need to be logged in to leave comments. Login now