Fix errors and fully support matplotlib interactive mode in run and debug with the...
authorElizaveta Shashkova <Elizaveta.Shashkova@jetbrains.com>
Wed, 9 Nov 2016 17:35:18 +0000 (20:35 +0300)
committerElizaveta Shashkova <Elizaveta.Shashkova@jetbrains.com>
Wed, 9 Nov 2016 17:42:31 +0000 (20:42 +0300)
python/helpers/pydev/pydev_run_in_console.py
python/helpers/pydev/pydevconsole.py
python/helpers/pydev/pydevd.py

index 39e0143b9f4e1df11bc67ad4c28e57bb07342a33..82def87817857859c4215ffac84e96335edd9727 100644 (file)
@@ -3,8 +3,7 @@ Entry point module to run a file in the interactive console.
 '''
 import os
 import sys
-from pydevconsole import do_exit, InterpreterInterface, process_exec_queue, start_console_server
-from _pydev_bundle.pydev_console_utils import BaseStdIn
+from pydevconsole import do_exit, InterpreterInterface, process_exec_queue, start_console_server, init_mpl_in_console
 from _pydev_imps._pydev_saved_modules import threading
 
 from _pydev_bundle import pydev_imports
@@ -74,6 +73,8 @@ if __name__ == '__main__':
 
     sys.stdin = StdIn(interpreter, host, client_port, sys.stdin)
 
+    init_mpl_in_console(interpreter)
+
     globals = run_file(file, None, None)
 
     interpreter.get_namespace().update(globals)
index ff85bb212187e6109aee1e6a96449b455d38bdd0..3b98a0e626dcd20d111e1e1b4c555299a6297f0c 100644 (file)
@@ -155,9 +155,8 @@ def set_debug_hook(debug_hook):
     _ProcessExecQueueHelper._debug_hook = debug_hook
 
 
-def process_exec_queue(interpreter):
-
-    from pydev_ipython.inputhook import get_inputhook, set_return_control_callback
+def init_mpl_in_console(interpreter):
+    from pydev_ipython.inputhook import set_return_control_callback
 
     def return_control():
         ''' A function that the inputhooks can call (via inputhook.stdin_ready()) to find
@@ -187,6 +186,11 @@ def process_exec_queue(interpreter):
     import_hook_manager.add_module_name("pylab", activate_pylab)
     import_hook_manager.add_module_name("pyplot", activate_pyplot)
 
+
+def process_exec_queue(interpreter):
+    init_mpl_in_console(interpreter)
+    from pydev_ipython.inputhook import get_inputhook
+
     while 1:
         # Running the request may have changed the inputhook in use
         inputhook = get_inputhook()
index e7b11abdcd391937f61123988640f8517828a1df..6a40c9fcb8bafdd782891ef9ef95314bf8466554 100644 (file)
@@ -400,6 +400,23 @@ class PyDB:
                                          "matplotlib.pyplot": activate_pyplot,
                                          "pylab": activate_pylab }
 
+    def _activate_mpl_if_needed(self):
+        if len(self.mpl_modules_for_patching) > 0:
+            for module in dict_keys(self.mpl_modules_for_patching):
+                if module in sys.modules:
+                    activate_function = dict_pop(self.mpl_modules_for_patching, module)
+                    activate_function()
+                    self.mpl_in_use = True
+
+    def _call_mpl_hook(self):
+        try:
+            from pydev_ipython.inputhook import get_inputhook
+            inputhook = get_inputhook()
+            if inputhook:
+                inputhook()
+        except:
+            pass
+
     def suspend_all_other_threads(self, thread_suspended_at_bp):
         all_threads = threadingEnumerate()
         for t in all_threads:
@@ -716,30 +733,16 @@ class PyDB:
         finally:
             CustomFramesContainer.custom_frames_lock.release()  # @UndefinedVariable
 
-        imported = False
         info = thread.additional_info
 
         if info.pydev_state == STATE_SUSPEND and not self._finish_debugging_session:
             # before every stop check if matplotlib modules were imported inside script code
-            if len(self.mpl_modules_for_patching) > 0:
-                for module in dict_keys(self.mpl_modules_for_patching):
-                    if module in sys.modules:
-                        activate_function = dict_pop(self.mpl_modules_for_patching, module)
-                        activate_function()
-                        self.mpl_in_use = True
+            self._activate_mpl_if_needed()
 
         while info.pydev_state == STATE_SUSPEND and not self._finish_debugging_session:
             if self.mpl_in_use:
                 # call input hooks if only matplotlib is in use
-                try:
-                    if not imported:
-                        from pydev_ipython.inputhook import get_inputhook
-                        imported = True
-                    inputhook = get_inputhook()
-                    if inputhook:
-                        inputhook()
-                except:
-                    pass
+                self._call_mpl_hook()
 
             self.process_internal_commands()
             time.sleep(0.01)
@@ -979,6 +982,8 @@ class PyDB:
         self.writer.add_command(cmd)
 
     def wait_for_commands(self, globals):
+        self._activate_mpl_if_needed()
+
         thread = threading.currentThread()
         from _pydevd_bundle import pydevd_frame_utils
         frame = pydevd_frame_utils.Frame(None, -1, pydevd_frame_utils.FCode("Console",
@@ -991,6 +996,9 @@ class PyDB:
         self.writer.add_command(cmd)
 
         while True:
+            if self.mpl_in_use:
+                # call input hooks if only matplotlib is in use
+                self._call_mpl_hook()
             self.process_internal_commands()
             time.sleep(0.01)