public static PythonConsoleHost OpenPythonConsole(System.Windows.Forms.Form mainForm) { // ipy -D -X:TabCompletion -X:ColorfulConsole if (m_pythonConsoleHost == null) { m_pythonConsoleHost = new PythonConsoleHost(); //System.Threading.ManualResetEvent eve = new System.Threading.ManualResetEvent(false); dispatcher = mainForm; System.Threading.AutoResetEvent are = new System.Threading.AutoResetEvent(false); System.Threading.Thread _debugThread = new System.Threading.Thread(() => { int r = AllocConsole(); if (r == 0) { throw new InvalidOperationException("Can't AllocConsole!"); } StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput()); standardOutput.AutoFlush = true; Console.SetOut(standardOutput); //host.Options.RunAction = Microsoft.Scripting.Hosting.Shell.ConsoleHostOptions.Action.RunConsole; m_pythonConsoleHost.Run(new string[] { "-X:ColorfulConsole", "-X:Debug", "-X:TabCompletion", "-X:ExceptionDetail", "-X:ShowClrExceptions" }); // //are.Set(); m_pythonConsoleHost.Runtime.IO.RedirectToConsole(); IronPython.Runtime.ClrModule.SetCommandDispatcher(IronPython.Runtime.DefaultContext.Default, null); r = FreeConsole(); if (r == 0) { throw new InvalidOperationException("Can't FreeConsole!"); } m_pythonConsoleHost = null; }); _debugThread.IsBackground = true; _debugThread.SetApartmentState(System.Threading.ApartmentState.STA); _debugThread.Start(); // Don't establish the alternative input execution behavior until the other thread is ready. Note, 'are' starts out unsignalled. //are.WaitOne(); while (m_pythonConsoleHost.ScriptScope == null) { System.Threading.Thread.Sleep(1000); } IronPython.Runtime.ClrModule.SetCommandDispatcher(IronPython.Runtime.DefaultContext.Default, DispatchConsoleCommand); } return m_pythonConsoleHost; }
public static PythonConsoleHost OpenPythonConsole(System.Windows.Forms.Form mainForm) { // ipy -D -X:TabCompletion -X:ColorfulConsole if (m_pythonConsoleHost == null) { m_pythonConsoleHost = new PythonConsoleHost(); //System.Threading.ManualResetEvent eve = new System.Threading.ManualResetEvent(false); dispatcher = mainForm; System.Threading.AutoResetEvent are = new System.Threading.AutoResetEvent(false); System.Threading.Thread _debugThread = new System.Threading.Thread(() => { int r = AllocConsole(); if (r == 0) { throw new InvalidOperationException("Can't AllocConsole!"); } StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput()); standardOutput.AutoFlush = true; Console.SetOut(standardOutput); //host.Options.RunAction = Microsoft.Scripting.Hosting.Shell.ConsoleHostOptions.Action.RunConsole; m_pythonConsoleHost.Run(new string[] { "-X:ColorfulConsole", "-X:Debug", "-X:TabCompletion", "-X:ExceptionDetail", "-X:ShowClrExceptions" }); // //are.Set(); m_pythonConsoleHost.Runtime.IO.RedirectToConsole(); IronPython.Runtime.ClrModule.SetCommandDispatcher(IronPython.Runtime.DefaultContext.Default, null); r = FreeConsole(); if (r == 0) { throw new InvalidOperationException("Can't FreeConsole!"); } m_pythonConsoleHost = null; }); _debugThread.IsBackground = true; _debugThread.SetApartmentState(System.Threading.ApartmentState.STA); _debugThread.Start(); // Don't establish the alternative input execution behavior until the other thread is ready. Note, 'are' starts out unsignalled. //are.WaitOne(); while (m_pythonConsoleHost.ScriptScope == null) { System.Threading.Thread.Sleep(1000); } IronPython.Runtime.ClrModule.SetCommandDispatcher(IronPython.Runtime.DefaultContext.Default, DispatchConsoleCommand); } return(m_pythonConsoleHost); }