##// END OF EJS Templates
Merge pull request #809 from minrk/osxkernel...
Min RK -
r4884:321d643f merge
parent child Browse files
Show More
@@ -586,6 +586,77 b' class GTKKernel(Kernel):'
586 gtk_kernel.start()
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
628 t = TimerMac(poll_interval)
629 t.add_callback(doi)
630 t.start()
631
632 # but still need a Poller for when there are no active windows,
633 # during which time mainloop() returns immediately
634 poller = zmq.Poller()
635 poller.register(self.shell_socket, zmq.POLLIN)
636
637 while True:
638 try:
639 # double nested try/except, to properly catch KeyboardInterrupt
640 # due to pyzmq Issue #130
641 try:
642 # don't let interrupts during mainloop invoke crash_handler:
643 sys.excepthook = handle_int
644 show.mainloop()
645 sys.excepthook = real_excepthook
646 # use poller if mainloop returned (no windows)
647 # scale by extra factor of 10, since it's a real poll
648 poller.poll(10*poll_interval)
649 self.do_one_iteration()
650 except:
651 raise
652 except KeyboardInterrupt:
653 # Ctrl-C shouldn't crash the kernel
654 io.raw_print("KeyboardInterrupt caught in kernel")
655 finally:
656 # ensure excepthook is restored
657 sys.excepthook = real_excepthook
658
659
589 #-----------------------------------------------------------------------------
660 #-----------------------------------------------------------------------------
590 # Aliases and Flags for the IPKernelApp
661 # Aliases and Flags for the IPKernelApp
591 #-----------------------------------------------------------------------------
662 #-----------------------------------------------------------------------------
@@ -639,7 +710,7 b' class IPKernelApp(KernelApp, InteractiveShellApp):'
639 'qt' : QtKernel,
710 'qt' : QtKernel,
640 'qt4': QtKernel,
711 'qt4': QtKernel,
641 'inline': Kernel,
712 'inline': Kernel,
642 'osx': TkKernel,
713 'osx': OSXKernel,
643 'wx' : WxKernel,
714 'wx' : WxKernel,
644 'tk' : TkKernel,
715 'tk' : TkKernel,
645 'gtk': GTKKernel,
716 'gtk': GTKKernel,
@@ -61,7 +61,7 b' Pylab'
61 =====
61 =====
62
62
63 One of the most exciting features of the new console is embedded matplotlib
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 to draw the figures, and since there is now a two-process model, there is no
65 to draw the figures, and since there is now a two-process model, there is no
66 longer a conflict between user input and the drawing eventloop.
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