Show More
@@ -2890,6 +2890,8 b' class InteractiveShell(SingletonConfigurable):' | |||||
2890 | # Things related to GUI support and pylab |
|
2890 | # Things related to GUI support and pylab | |
2891 | #------------------------------------------------------------------------- |
|
2891 | #------------------------------------------------------------------------- | |
2892 |
|
2892 | |||
|
2893 | active_eventloop = None | |||
|
2894 | ||||
2893 | def enable_gui(self, gui=None): |
|
2895 | def enable_gui(self, gui=None): | |
2894 | raise NotImplementedError('Implement enable_gui in a subclass') |
|
2896 | raise NotImplementedError('Implement enable_gui in a subclass') | |
2895 |
|
2897 |
@@ -57,16 +57,10 b" so you don't have to depend on IPython." | |||||
57 |
|
57 | |||
58 | """ |
|
58 | """ | |
59 |
|
59 | |||
60 | #----------------------------------------------------------------------------- |
|
60 | # Copyright (c) IPython Development Team. | |
61 | # Copyright (C) 2008-2011 The IPython Development Team |
|
61 | # Distributed under the terms of the Modified BSD License. | |
62 | # |
|
|||
63 | # Distributed under the terms of the BSD License. The full license is in |
|
|||
64 | # the file COPYING, distributed as part of this software. |
|
|||
65 | #----------------------------------------------------------------------------- |
|
|||
66 |
|
62 | |||
67 | #----------------------------------------------------------------------------- |
|
63 | from IPython.core.getipython import get_ipython | |
68 | # Imports |
|
|||
69 | #----------------------------------------------------------------------------- |
|
|||
70 |
|
64 | |||
71 | #----------------------------------------------------------------------------- |
|
65 | #----------------------------------------------------------------------------- | |
72 | # wx |
|
66 | # wx | |
@@ -84,6 +78,15 b' def get_app_wx(*args, **kwargs):' | |||||
84 |
|
78 | |||
85 | def is_event_loop_running_wx(app=None): |
|
79 | def is_event_loop_running_wx(app=None): | |
86 | """Is the wx event loop running.""" |
|
80 | """Is the wx event loop running.""" | |
|
81 | # New way: check attribute on shell instance | |||
|
82 | ip = get_ipython() | |||
|
83 | if ip is not None: | |||
|
84 | if ip.active_eventloop and ip.active_eventloop == 'wx': | |||
|
85 | return True | |||
|
86 | # Fall through to checking the application, because Wx has a native way | |||
|
87 | # to check if the event loop is running, unlike Qt. | |||
|
88 | ||||
|
89 | # Old way: check Wx application | |||
87 | if app is None: |
|
90 | if app is None: | |
88 | app = get_app_wx() |
|
91 | app = get_app_wx() | |
89 | if hasattr(app, '_in_event_loop'): |
|
92 | if hasattr(app, '_in_event_loop'): | |
@@ -118,6 +121,12 b' def get_app_qt4(*args, **kwargs):' | |||||
118 |
|
121 | |||
119 | def is_event_loop_running_qt4(app=None): |
|
122 | def is_event_loop_running_qt4(app=None): | |
120 | """Is the qt4 event loop running.""" |
|
123 | """Is the qt4 event loop running.""" | |
|
124 | # New way: check attribute on shell instance | |||
|
125 | ip = get_ipython() | |||
|
126 | if ip is not None: | |||
|
127 | return ip.active_eventloop and ip.active_eventloop.startswith('qt') | |||
|
128 | ||||
|
129 | # Old way: check attribute on QApplication singleton | |||
121 | if app is None: |
|
130 | if app is None: | |
122 | app = get_app_qt4(['']) |
|
131 | app = get_app_qt4(['']) | |
123 | if hasattr(app, '_in_event_loop'): |
|
132 | if hasattr(app, '_in_event_loop'): |
@@ -28,7 +28,7 b' from pygments.token import Token' | |||||
28 |
|
28 | |||
29 | from .debugger import TerminalPdb, Pdb |
|
29 | from .debugger import TerminalPdb, Pdb | |
30 | from .magics import TerminalMagics |
|
30 | from .magics import TerminalMagics | |
31 | from .pt_inputhooks import get_inputhook_func |
|
31 | from .pt_inputhooks import get_inputhook_name_and_func | |
32 | from .prompts import Prompts, ClassicPrompts, RichPromptDisplayHook |
|
32 | from .prompts import Prompts, ClassicPrompts, RichPromptDisplayHook | |
33 | from .ptutils import IPythonPTCompleter, IPythonPTLexer |
|
33 | from .ptutils import IPythonPTCompleter, IPythonPTLexer | |
34 | from .shortcuts import register_ipython_shortcuts |
|
34 | from .shortcuts import register_ipython_shortcuts | |
@@ -458,11 +458,13 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
458 | if self._inputhook is not None: |
|
458 | if self._inputhook is not None: | |
459 | self._inputhook(context) |
|
459 | self._inputhook(context) | |
460 |
|
460 | |||
|
461 | active_eventloop = None | |||
461 | def enable_gui(self, gui=None): |
|
462 | def enable_gui(self, gui=None): | |
462 | if gui: |
|
463 | if gui: | |
463 | self._inputhook = get_inputhook_func(gui) |
|
464 | self.active_eventloop, self._inputhook =\ | |
|
465 | get_inputhook_name_and_func(gui) | |||
464 | else: |
|
466 | else: | |
465 | self._inputhook = None |
|
467 | self.active_eventloop = self._inputhook = None | |
466 |
|
468 | |||
467 | # Run !system commands directly, not through pipes, so terminal programs |
|
469 | # Run !system commands directly, not through pipes, so terminal programs | |
468 | # work correctly. |
|
470 | # work correctly. |
@@ -30,19 +30,20 b' class UnknownBackend(KeyError):' | |||||
30 | "Supported event loops are: {}").format(self.name, |
|
30 | "Supported event loops are: {}").format(self.name, | |
31 | ', '.join(backends + sorted(registered))) |
|
31 | ', '.join(backends + sorted(registered))) | |
32 |
|
32 | |||
33 | def get_inputhook_func(gui): |
|
33 | def get_inputhook_name_and_func(gui): | |
34 | if gui in registered: |
|
34 | if gui in registered: | |
35 | return registered[gui] |
|
35 | return gui, registered[gui] | |
36 |
|
36 | |||
37 | if gui not in backends: |
|
37 | if gui not in backends: | |
38 | raise UnknownBackend(gui) |
|
38 | raise UnknownBackend(gui) | |
39 |
|
39 | |||
40 | if gui in aliases: |
|
40 | if gui in aliases: | |
41 | return get_inputhook_func(aliases[gui]) |
|
41 | return get_inputhook_name_and_func(aliases[gui]) | |
42 |
|
42 | |||
|
43 | gui_mod = gui | |||
43 | if gui == 'qt5': |
|
44 | if gui == 'qt5': | |
44 | os.environ['QT_API'] = 'pyqt5' |
|
45 | os.environ['QT_API'] = 'pyqt5' | |
45 | gui = 'qt' |
|
46 | gui_mod = 'qt' | |
46 |
|
47 | |||
47 | mod = importlib.import_module('IPython.terminal.pt_inputhooks.'+gui) |
|
48 | mod = importlib.import_module('IPython.terminal.pt_inputhooks.'+gui_mod) | |
48 | return mod.inputhook |
|
49 | return gui, mod.inputhook |
General Comments 0
You need to be logged in to leave comments.
Login now