Show More
@@ -16,10 +16,10 b'' | |||
|
16 | 16 | |
|
17 | 17 | import sys |
|
18 | 18 | |
|
19 |
# System library imports |
|
|
19 | # System library imports | |
|
20 | 20 | import zmq |
|
21 | 21 | |
|
22 |
# Local imports |
|
|
22 | # Local imports | |
|
23 | 23 | from IPython.config.application import Application |
|
24 | 24 | from IPython.utils import io |
|
25 | 25 | |
@@ -28,18 +28,40 b' from IPython.utils import io' | |||
|
28 | 28 | # Eventloops for integrating the Kernel into different GUIs |
|
29 | 29 | #------------------------------------------------------------------------------ |
|
30 | 30 | |
|
31 | def _on_os_x_10_9(): | |
|
32 | import platform | |
|
33 | from distutils.version import LooseVersion as V | |
|
34 | return sys.platform == 'darwin' and V(platform.mac_ver()[0]) >= V('10.9') | |
|
35 | ||
|
36 | def _notify_stream_qt(kernel, stream): | |
|
37 | ||
|
38 | from IPython.external.qt_for_kernel import QtCore | |
|
39 | ||
|
40 | if _on_os_x_10_9() and kernel._darwin_app_nap: | |
|
41 | from IPython.external.appnope import nope_scope as context | |
|
42 | else: | |
|
43 | from IPython.core.interactiveshell import no_op_context as context | |
|
44 | ||
|
45 | def process_stream_events(): | |
|
46 | while stream.getsockopt(zmq.EVENTS) & zmq.POLLIN: | |
|
47 | with context(): | |
|
48 | kernel.do_one_iteration() | |
|
49 | ||
|
50 | fd = stream.getsockopt(zmq.FD) | |
|
51 | notifier = QtCore.QSocketNotifier(fd, QtCore.QSocketNotifier.Read, kernel.app) | |
|
52 | notifier.activated.connect(process_stream_events) | |
|
53 | ||
|
31 | 54 | def loop_qt4(kernel): |
|
32 | 55 | """Start a kernel with PyQt4 event loop integration.""" |
|
33 | 56 | |
|
34 | from IPython.external.qt_for_kernel import QtCore | |
|
35 | 57 | from IPython.lib.guisupport import get_app_qt4, start_event_loop_qt4 |
|
36 | 58 | |
|
37 | 59 | kernel.app = get_app_qt4([" "]) |
|
38 | 60 | kernel.app.setQuitOnLastWindowClosed(False) |
|
39 | kernel.timer = QtCore.QTimer() | |
|
40 | kernel.timer.timeout.connect(kernel.do_one_iteration) | |
|
41 | # Units for the timer are in milliseconds | |
|
42 | kernel.timer.start(1000*kernel._poll_interval) | |
|
61 | ||
|
62 | for s in kernel.shell_streams: | |
|
63 | _notify_stream_qt(kernel, s) | |
|
64 | ||
|
43 | 65 | start_event_loop_qt4(kernel.app) |
|
44 | 66 | |
|
45 | 67 | |
@@ -48,6 +70,12 b' def loop_wx(kernel):' | |||
|
48 | 70 | |
|
49 | 71 | import wx |
|
50 | 72 | from IPython.lib.guisupport import start_event_loop_wx |
|
73 | ||
|
74 | if _on_os_x_10_9() and kernel._darwin_app_nap: | |
|
75 | # we don't hook up App Nap contexts for Wx, | |
|
76 | # just disable it outright. | |
|
77 | from IPython.external.appnope import nope | |
|
78 | nope() | |
|
51 | 79 | |
|
52 | 80 | doi = kernel.do_one_iteration |
|
53 | 81 | # Wx uses milliseconds |
@@ -32,7 +32,7 b' from IPython.utils.py3compat import builtin_mod, unicode_type, string_types' | |||
|
32 | 32 | from IPython.utils.jsonutil import json_clean |
|
33 | 33 | from IPython.utils.traitlets import ( |
|
34 | 34 | Any, Instance, Float, Dict, List, Set, Integer, Unicode, |
|
35 | Type | |
|
35 | Type, Bool, | |
|
36 | 36 | ) |
|
37 | 37 | |
|
38 | 38 | from .serialize import serialize_object, unpack_apply_message |
@@ -91,9 +91,15 b' class Kernel(Configurable):' | |||
|
91 | 91 | def _ident_default(self): |
|
92 | 92 | return unicode_type(uuid.uuid4()) |
|
93 | 93 | |
|
94 | ||
|
95 | 94 | # Private interface |
|
96 | 95 | |
|
96 | _darwin_app_nap = Bool(True, config=True, | |
|
97 | help="""Whether to use appnope for compatiblity with OS X App Nap. | |
|
98 | ||
|
99 | Only affects OS X >= 10.9. | |
|
100 | """ | |
|
101 | ) | |
|
102 | ||
|
97 | 103 | # Time to sleep after flushing the stdout/err buffers in each execute |
|
98 | 104 | # cycle. While this introduces a hard limit on the minimal latency of the |
|
99 | 105 | # execute cycle, it helps prevent output synchronization problems for |
@@ -424,13 +424,7 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):' | |||
|
424 | 424 | def init_shell(self): |
|
425 | 425 | self.shell = self.kernel.shell |
|
426 | 426 | self.shell.configurables.append(self) |
|
427 | ||
|
428 | def init_osx(self): | |
|
429 | if sys.platform != 'darwin': | |
|
430 | return | |
|
431 | from IPython.utils.darwin import disable_app_nap | |
|
432 | self._activity = disable_app_nap(self.log.warn) | |
|
433 | ||
|
427 | ||
|
434 | 428 | @catch_config_error |
|
435 | 429 | def initialize(self, argv=None): |
|
436 | 430 | super(IPKernelApp, self).initialize(argv) |
@@ -445,7 +439,6 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):' | |||
|
445 | 439 | self.write_connection_file() |
|
446 | 440 | self.init_io() |
|
447 | 441 | self.init_signal() |
|
448 | self.init_osx() | |
|
449 | 442 | self.init_kernel() |
|
450 | 443 | # shell init steps |
|
451 | 444 | self.init_path() |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now