Show More
@@ -51,6 +51,34 def _notify_stream_qt(kernel, stream): | |||||
51 | notifier = QtCore.QSocketNotifier(fd, QtCore.QSocketNotifier.Read, kernel.app) |
|
51 | notifier = QtCore.QSocketNotifier(fd, QtCore.QSocketNotifier.Read, kernel.app) | |
52 | notifier.activated.connect(process_stream_events) |
|
52 | notifier.activated.connect(process_stream_events) | |
53 |
|
53 | |||
|
54 | # mapping of keys to loop functions | |||
|
55 | loop_map = { | |||
|
56 | 'inline': None, | |||
|
57 | None : None, | |||
|
58 | } | |||
|
59 | ||||
|
60 | def register_integration(*toolkitnames): | |||
|
61 | """Decorator to register an event loop to integrate with the IPython kernel | |||
|
62 | ||||
|
63 | The decorator takes names to register the event loop as for the %gui magic. | |||
|
64 | You can provide alternative names for the same toolkit. | |||
|
65 | ||||
|
66 | The decorated function should take a single argument, the IPython kernel | |||
|
67 | instance, arrange for the event loop to call ``kernel.do_one_iteration()`` | |||
|
68 | at least every ``kernel._poll_interval`` seconds, and start the event loop. | |||
|
69 | ||||
|
70 | :mod:`IPython.kernel.zmq.eventloops` provides and registers such functions | |||
|
71 | for a few common event loops. | |||
|
72 | """ | |||
|
73 | def decorator(func): | |||
|
74 | for name in toolkitnames: | |||
|
75 | loop_map[name] = func | |||
|
76 | return func | |||
|
77 | ||||
|
78 | return decorator | |||
|
79 | ||||
|
80 | ||||
|
81 | @register_integration('qt', 'qt4') | |||
54 | def loop_qt4(kernel): |
|
82 | def loop_qt4(kernel): | |
55 | """Start a kernel with PyQt4 event loop integration.""" |
|
83 | """Start a kernel with PyQt4 event loop integration.""" | |
56 |
|
84 | |||
@@ -65,6 +93,7 def loop_qt4(kernel): | |||||
65 | start_event_loop_qt4(kernel.app) |
|
93 | start_event_loop_qt4(kernel.app) | |
66 |
|
94 | |||
67 |
|
95 | |||
|
96 | @register_integration('wx') | |||
68 | def loop_wx(kernel): |
|
97 | def loop_wx(kernel): | |
69 | """Start a kernel with wx event loop support.""" |
|
98 | """Start a kernel with wx event loop support.""" | |
70 |
|
99 | |||
@@ -117,6 +146,7 def loop_wx(kernel): | |||||
117 | start_event_loop_wx(kernel.app) |
|
146 | start_event_loop_wx(kernel.app) | |
118 |
|
147 | |||
119 |
|
148 | |||
|
149 | @register_integration('tk') | |||
120 | def loop_tk(kernel): |
|
150 | def loop_tk(kernel): | |
121 | """Start a kernel with the Tk event loop.""" |
|
151 | """Start a kernel with the Tk event loop.""" | |
122 |
|
152 | |||
@@ -146,6 +176,7 def loop_tk(kernel): | |||||
146 | kernel.timer.start() |
|
176 | kernel.timer.start() | |
147 |
|
177 | |||
148 |
|
178 | |||
|
179 | @register_integration('gtk') | |||
149 | def loop_gtk(kernel): |
|
180 | def loop_gtk(kernel): | |
150 | """Start the kernel, coordinating with the GTK event loop""" |
|
181 | """Start the kernel, coordinating with the GTK event loop""" | |
151 | from .gui.gtkembed import GTKEmbed |
|
182 | from .gui.gtkembed import GTKEmbed | |
@@ -154,6 +185,7 def loop_gtk(kernel): | |||||
154 | gtk_kernel.start() |
|
185 | gtk_kernel.start() | |
155 |
|
186 | |||
156 |
|
187 | |||
|
188 | @register_integration('gtk3') | |||
157 | def loop_gtk3(kernel): |
|
189 | def loop_gtk3(kernel): | |
158 | """Start the kernel, coordinating with the GTK event loop""" |
|
190 | """Start the kernel, coordinating with the GTK event loop""" | |
159 | from .gui.gtk3embed import GTKEmbed |
|
191 | from .gui.gtk3embed import GTKEmbed | |
@@ -162,6 +194,7 def loop_gtk3(kernel): | |||||
162 | gtk_kernel.start() |
|
194 | gtk_kernel.start() | |
163 |
|
195 | |||
164 |
|
196 | |||
|
197 | @register_integration('osx') | |||
165 | def loop_cocoa(kernel): |
|
198 | def loop_cocoa(kernel): | |
166 | """Start the kernel, coordinating with the Cocoa CFRunLoop event loop |
|
199 | """Start the kernel, coordinating with the Cocoa CFRunLoop event loop | |
167 | via the matplotlib MacOSX backend. |
|
200 | via the matplotlib MacOSX backend. | |
@@ -232,18 +265,6 def loop_cocoa(kernel): | |||||
232 | # ensure excepthook is restored |
|
265 | # ensure excepthook is restored | |
233 | sys.excepthook = real_excepthook |
|
266 | sys.excepthook = real_excepthook | |
234 |
|
267 | |||
235 | # mapping of keys to loop functions |
|
|||
236 | loop_map = { |
|
|||
237 | 'qt' : loop_qt4, |
|
|||
238 | 'qt4': loop_qt4, |
|
|||
239 | 'inline': None, |
|
|||
240 | 'osx': loop_cocoa, |
|
|||
241 | 'wx' : loop_wx, |
|
|||
242 | 'tk' : loop_tk, |
|
|||
243 | 'gtk': loop_gtk, |
|
|||
244 | 'gtk3': loop_gtk3, |
|
|||
245 | None : None, |
|
|||
246 | } |
|
|||
247 |
|
268 | |||
248 |
|
269 | |||
249 | def enable_gui(gui, kernel=None): |
|
270 | def enable_gui(gui, kernel=None): |
General Comments 0
You need to be logged in to leave comments.
Login now