public IronPythonHost(IConsoleHost host) { Console = host; output = new MemoryStream(); output.SetLength(0); pyRuntime = Python.CreateRuntime(); pyRuntime.IO.SetOutput(output, Encoding.ASCII); pyEngine = Python.GetEngine(pyRuntime); pyScope = pyEngine.CreateScope(); ExecutePythonCode("import clr"); ExecutePythonCode("import Microsoft"); ExecutePythonCode("clr.AddReference(\"Microsoft.Xna.Framework\")"); ExecutePythonCode("import Microsoft.Xna.Framework"); ExecutePythonCode("import Microsoft.Xna.Framework.Graphics"); ExecutePythonCode("from Microsoft.Xna.Framework import *"); ExecutePythonCode("from Microsoft.Xna.Framework.Graphics import *"); SetVariable("_runtime", this); Console.Echo("[HOST] Using IRONPYTHON v2.7.1"); }
/// <summary> /// 'tr' command execution. /// </summary> void CommandExecute(IConsoleHost host, string command, IList<string> arguments) { bool previousVisible = Visible; if (arguments.Count == 0) Visible = !Visible; char[] subArgSeparator = new[] { ':' }; foreach (string orgArg in arguments) { string arg = orgArg.ToLower(); string[] subargs = arg.Split(subArgSeparator); switch (subargs[0]) { case "on": Visible = true; break; case "off": Visible = false; break; case "reset": ResetLog(); break; case "log": if (subargs.Length > 1) { if (String.Compare(subargs[1], "on") == 0) ShowLog = true; if (String.Compare(subargs[1], "off") == 0) ShowLog = false; } else { ShowLog = !ShowLog; } break; case "frame": int a = Int32.Parse(subargs[1]); a = Math.Max(a, 1); a = Math.Min(a, MaxSampleFrames); TargetSampleFrames = a; break; case "/?": case "--help": host.Echo("tr [log|on|off|reset|frame]"); host.Echo("Options:"); host.Echo(" on Display TimeRuler."); host.Echo(" off Hide TimeRuler."); host.Echo(" log Show/Hide marker log."); host.Echo(" reset Reset marker log."); host.Echo(" frame:sampleFrames"); host.Echo(" Change target sample frame count"); break; default: break; } } // Reset update count when Visible state changed. if (Visible != previousVisible) { Interlocked.Exchange(ref updateCount, 0); } }