diff options
author | Tor Norbye <tnorbye@google.com> | 2014-09-04 20:44:00 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-09-04 20:44:01 +0000 |
commit | fb5a02906f644d044eb0286bf27d413ba0e05216 (patch) | |
tree | bca7d49005d81d10c70bc3f547df041c636b4300 /python/helpers/pydev/pydev_ipython_console_011.py | |
parent | 9cde0e3c015174898df8b8f3672185941fad4786 (diff) | |
parent | d245f58efbfc26b13b9b9d5e52e6a83a0d76216c (diff) | |
download | idea-fb5a02906f644d044eb0286bf27d413ba0e05216.tar.gz |
Merge "Merge remote-tracking branch 'aosp/upstream-master' into merge"
Diffstat (limited to 'python/helpers/pydev/pydev_ipython_console_011.py')
-rw-r--r-- | python/helpers/pydev/pydev_ipython_console_011.py | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/python/helpers/pydev/pydev_ipython_console_011.py b/python/helpers/pydev/pydev_ipython_console_011.py index 54458e7c4af5..717aaccbc26e 100644 --- a/python/helpers/pydev/pydev_ipython_console_011.py +++ b/python/helpers/pydev/pydev_ipython_console_011.py @@ -19,7 +19,6 @@ import os import codeop from IPython.core.error import UsageError -from IPython.core.inputsplitter import IPythonInputSplitter from IPython.core.completer import IPCompleter from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC from IPython.core.usage import default_banner_parts @@ -53,7 +52,8 @@ def show_in_pager(self, strng): print(strng) def create_editor_hook(pydev_host, pydev_client_port): - def call_editor(self, filename, line=0, wait=True): + + def call_editor(filename, line=0, wait=True): """ Open an editor in PyDev """ if line is None: line = 0 @@ -62,6 +62,9 @@ def create_editor_hook(pydev_host, pydev_client_port): # we don't launch a process. This is more like what happens in the zmqshell filename = os.path.abspath(filename) + # import sys + # sys.__stderr__.write('Calling editor at: %s:%s\n' % (pydev_host, pydev_client_port)) + # Tell PyDev to open the editor server = xmlrpclib.Server('http://%s:%s' % (pydev_host, pydev_client_port)) server.IPythonEditor(filename, str(line)) @@ -291,22 +294,17 @@ class PyDevTerminalInteractiveShell(TerminalInteractiveShell): InteractiveShellABC.register(PyDevTerminalInteractiveShell) # @UndefinedVariable #======================================================================================================================= -# PyDevFrontEnd +# _PyDevFrontEnd #======================================================================================================================= -class PyDevFrontEnd: +class _PyDevFrontEnd: version = release.__version__ - def __init__(self, pydev_host, pydev_client_port, *args, **kwarg): + def __init__(self, *args, **kwarg): # Create and initialize our IPython instance. self.ipython = PyDevTerminalInteractiveShell.instance() - # Back channel to PyDev to open editors (in the future other - # info may go back this way. This is the same channel that is - # used to get stdin, see StdIn in pydev_console_utils) - self.ipython.set_hook('editor', create_editor_hook(pydev_host, pydev_client_port)) - # Display the IPython banner, this has version info and # help info self.ipython.show_banner() @@ -412,6 +410,9 @@ class PyDevFrontEnd: def getNamespace(self): return self.ipython.user_ns + + def clearBuffer(self): + del self._curr_exec_lines[:] def addExec(self, line): if self._curr_exec_lines: @@ -463,3 +464,28 @@ IPython.lib.inputhook.enable_gui = pydev_ipython.inputhook.enable_gui # rely on using the inputhooks directly. for name in pydev_ipython.inputhook.__all__: setattr(IPython.lib.inputhook, name, getattr(pydev_ipython.inputhook, name)) + + +class _PyDevFrontEndContainer: + _instance = None + _last_host_port = None + +def get_pydev_frontend(pydev_host, pydev_client_port): + if _PyDevFrontEndContainer._instance is None: + _PyDevFrontEndContainer._instance = _PyDevFrontEnd() + + if _PyDevFrontEndContainer._last_host_port != (pydev_host, pydev_client_port): + _PyDevFrontEndContainer._last_host_port = pydev_host, pydev_client_port + + # Back channel to PyDev to open editors (in the future other + # info may go back this way. This is the same channel that is + # used to get stdin, see StdIn in pydev_console_utils) + _PyDevFrontEndContainer._instance.ipython.hooks['editor'] = create_editor_hook(pydev_host, pydev_client_port) + + # Note: setting the callback directly because setting it with set_hook would actually create a chain instead + # of ovewriting at each new call). + # _PyDevFrontEndContainer._instance.ipython.set_hook('editor', create_editor_hook(pydev_host, pydev_client_port)) + + return _PyDevFrontEndContainer._instance + +
\ No newline at end of file |