Show More
@@ -16,10 +16,10 b'' | |||||
16 |
|
16 | |||
17 | import sys |
|
17 | import sys | |
18 |
|
18 | |||
19 |
# System library imports |
|
19 | # System library imports | |
20 | import zmq |
|
20 | import zmq | |
21 |
|
21 | |||
22 |
# Local imports |
|
22 | # Local imports | |
23 | from IPython.config.application import Application |
|
23 | from IPython.config.application import Application | |
24 | from IPython.utils import io |
|
24 | from IPython.utils import io | |
25 |
|
25 | |||
@@ -28,18 +28,40 b' from IPython.utils import io' | |||||
28 | # Eventloops for integrating the Kernel into different GUIs |
|
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 | def loop_qt4(kernel): |
|
54 | def loop_qt4(kernel): | |
32 | """Start a kernel with PyQt4 event loop integration.""" |
|
55 | """Start a kernel with PyQt4 event loop integration.""" | |
33 |
|
56 | |||
34 | from IPython.external.qt_for_kernel import QtCore |
|
|||
35 | from IPython.lib.guisupport import get_app_qt4, start_event_loop_qt4 |
|
57 | from IPython.lib.guisupport import get_app_qt4, start_event_loop_qt4 | |
36 |
|
58 | |||
37 | kernel.app = get_app_qt4([" "]) |
|
59 | kernel.app = get_app_qt4([" "]) | |
38 | kernel.app.setQuitOnLastWindowClosed(False) |
|
60 | kernel.app.setQuitOnLastWindowClosed(False) | |
39 | kernel.timer = QtCore.QTimer() |
|
61 | ||
40 | kernel.timer.timeout.connect(kernel.do_one_iteration) |
|
62 | for s in kernel.shell_streams: | |
41 | # Units for the timer are in milliseconds |
|
63 | _notify_stream_qt(kernel, s) | |
42 | kernel.timer.start(1000*kernel._poll_interval) |
|
64 | ||
43 | start_event_loop_qt4(kernel.app) |
|
65 | start_event_loop_qt4(kernel.app) | |
44 |
|
66 | |||
45 |
|
67 | |||
@@ -49,6 +71,12 b' def loop_wx(kernel):' | |||||
49 | import wx |
|
71 | import wx | |
50 | from IPython.lib.guisupport import start_event_loop_wx |
|
72 | from IPython.lib.guisupport import start_event_loop_wx | |
51 |
|
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() | |||
|
79 | ||||
52 | doi = kernel.do_one_iteration |
|
80 | doi = kernel.do_one_iteration | |
53 | # Wx uses milliseconds |
|
81 | # Wx uses milliseconds | |
54 | poll_interval = int(1000*kernel._poll_interval) |
|
82 | poll_interval = int(1000*kernel._poll_interval) |
@@ -32,7 +32,7 b' from IPython.utils.py3compat import builtin_mod, unicode_type, string_types' | |||||
32 | from IPython.utils.jsonutil import json_clean |
|
32 | from IPython.utils.jsonutil import json_clean | |
33 | from IPython.utils.traitlets import ( |
|
33 | from IPython.utils.traitlets import ( | |
34 | Any, Instance, Float, Dict, List, Set, Integer, Unicode, |
|
34 | Any, Instance, Float, Dict, List, Set, Integer, Unicode, | |
35 | Type |
|
35 | Type, Bool, | |
36 | ) |
|
36 | ) | |
37 |
|
37 | |||
38 | from .serialize import serialize_object, unpack_apply_message |
|
38 | from .serialize import serialize_object, unpack_apply_message | |
@@ -91,9 +91,15 b' class Kernel(Configurable):' | |||||
91 | def _ident_default(self): |
|
91 | def _ident_default(self): | |
92 | return unicode_type(uuid.uuid4()) |
|
92 | return unicode_type(uuid.uuid4()) | |
93 |
|
93 | |||
94 |
|
||||
95 | # Private interface |
|
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 | # Time to sleep after flushing the stdout/err buffers in each execute |
|
103 | # Time to sleep after flushing the stdout/err buffers in each execute | |
98 | # cycle. While this introduces a hard limit on the minimal latency of the |
|
104 | # cycle. While this introduces a hard limit on the minimal latency of the | |
99 | # execute cycle, it helps prevent output synchronization problems for |
|
105 | # execute cycle, it helps prevent output synchronization problems for |
@@ -425,12 +425,6 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):' | |||||
425 | self.shell = self.kernel.shell |
|
425 | self.shell = self.kernel.shell | |
426 | self.shell.configurables.append(self) |
|
426 | self.shell.configurables.append(self) | |
427 |
|
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 |
|
||||
434 | @catch_config_error |
|
428 | @catch_config_error | |
435 | def initialize(self, argv=None): |
|
429 | def initialize(self, argv=None): | |
436 | super(IPKernelApp, self).initialize(argv) |
|
430 | super(IPKernelApp, self).initialize(argv) | |
@@ -445,7 +439,6 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):' | |||||
445 | self.write_connection_file() |
|
439 | self.write_connection_file() | |
446 | self.init_io() |
|
440 | self.init_io() | |
447 | self.init_signal() |
|
441 | self.init_signal() | |
448 | self.init_osx() |
|
|||
449 | self.init_kernel() |
|
442 | self.init_kernel() | |
450 | # shell init steps |
|
443 | # shell init steps | |
451 | self.init_path() |
|
444 | self.init_path() |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now