##// END OF EJS Templates
Let IPython.lib.guisupport detect terminal-integrated event loops...
Thomas Kluyver -
Show More
@@ -2891,6 +2891,8 b' class InteractiveShell(SingletonConfigurable):'
2891 2891 # Things related to GUI support and pylab
2892 2892 #-------------------------------------------------------------------------
2893 2893
2894 active_eventloop = None
2895
2894 2896 def enable_gui(self, gui=None):
2895 2897 raise NotImplementedError('Implement enable_gui in a subclass')
2896 2898
@@ -57,16 +57,10 b" so you don't have to depend on IPython."
57 57
58 58 """
59 59
60 #-----------------------------------------------------------------------------
61 # Copyright (C) 2008-2011 The IPython Development Team
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 #-----------------------------------------------------------------------------
60 # Copyright (c) IPython Development Team.
61 # Distributed under the terms of the Modified BSD License.
66 62
67 #-----------------------------------------------------------------------------
68 # Imports
69 #-----------------------------------------------------------------------------
63 from IPython.core.getipython import get_ipython
70 64
71 65 #-----------------------------------------------------------------------------
72 66 # wx
@@ -84,6 +78,15 b' def get_app_wx(*args, **kwargs):'
84 78
85 79 def is_event_loop_running_wx(app=None):
86 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 90 if app is None:
88 91 app = get_app_wx()
89 92 if hasattr(app, '_in_event_loop'):
@@ -118,6 +121,12 b' def get_app_qt4(*args, **kwargs):'
118 121
119 122 def is_event_loop_running_qt4(app=None):
120 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 130 if app is None:
122 131 app = get_app_qt4([''])
123 132 if hasattr(app, '_in_event_loop'):
@@ -28,7 +28,7 b' from pygments.token import Token'
28 28
29 29 from .debugger import TerminalPdb, Pdb
30 30 from .magics import TerminalMagics
31 from .pt_inputhooks import get_inputhook_func
31 from .pt_inputhooks import get_inputhook_name_and_func
32 32 from .prompts import Prompts, ClassicPrompts, RichPromptDisplayHook
33 33 from .ptutils import IPythonPTCompleter, IPythonPTLexer
34 34 from .shortcuts import register_ipython_shortcuts
@@ -458,11 +458,13 b' class TerminalInteractiveShell(InteractiveShell):'
458 458 if self._inputhook is not None:
459 459 self._inputhook(context)
460 460
461 active_eventloop = None
461 462 def enable_gui(self, gui=None):
462 463 if gui:
463 self._inputhook = get_inputhook_func(gui)
464 self.active_eventloop, self._inputhook =\
465 get_inputhook_name_and_func(gui)
464 466 else:
465 self._inputhook = None
467 self.active_eventloop = self._inputhook = None
466 468
467 469 # Run !system commands directly, not through pipes, so terminal programs
468 470 # work correctly.
@@ -30,19 +30,20 b' class UnknownBackend(KeyError):'
30 30 "Supported event loops are: {}").format(self.name,
31 31 ', '.join(backends + sorted(registered)))
32 32
33 def get_inputhook_func(gui):
33 def get_inputhook_name_and_func(gui):
34 34 if gui in registered:
35 return registered[gui]
35 return gui, registered[gui]
36 36
37 37 if gui not in backends:
38 38 raise UnknownBackend(gui)
39 39
40 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 44 if gui == 'qt5':
44 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 return mod.inputhook
48 mod = importlib.import_module('IPython.terminal.pt_inputhooks.'+gui_mod)
49 return gui, mod.inputhook
General Comments 0
You need to be logged in to leave comments. Login now