/// <summary> /// Set the script this console should display the output /// to. The script must have been set to "redirect" /// </summary> /// <param name="script">the python script instance</param> public void SetScript(Script script) { readingScript = script; writer = readingScript.OutputWriter; //Only enable if writer is not null updateoutput.Enabled = (writer != null);//*/ }
/// <summary> /// Set the script this console should display the output /// to. The script must have been set to "redirect" /// </summary> /// <param name="script">the python script instance</param> public void SetScript(Script script) { readingScript = script; writer = readingScript.OutputWriter; //Only enable if writer is not null updateoutput.Enabled = (writer != null);//*/ }
public Script(bool redirectOutput = false) { Dictionary <string, object> options = new Dictionary <string, object>(); options["Debug"] = true; if (engine != null) { engine.Runtime.Shutdown(); } engine = Python.CreateEngine(options); scope = engine.CreateScope(); var all = System.Reflection.Assembly.GetExecutingAssembly(); engine.Runtime.LoadAssembly(all); scope.SetVariable("MAV", MainV2.comPort); scope.SetVariable("cs", MainV2.comPort.MAV.cs); scope.SetVariable("Script", this); scope.SetVariable("mavutil", this); engine.CreateScriptSourceFromString("print 'hello world from python'").Execute(scope); engine.CreateScriptSourceFromString("print cs.roll").Execute(scope); if (redirectOutput) { //Redirect output through this writer //this writer will not actually write to the memorystreams OutputWriter = new Utilities.StringRedirectWriter(); engine.Runtime.IO.SetErrorOutput(new MemoryStream(), OutputWriter); engine.Runtime.IO.SetOutput(new MemoryStream(), OutputWriter); } else { OutputWriter = null; } object thisBoxed = MainV2.comPort.MAV.cs; Type test = thisBoxed.GetType(); foreach (var field in test.GetProperties()) { // field.Name has the field's name. object fieldValue; try { fieldValue = field.GetValue(thisBoxed, null); // Get value } catch { continue; } // Get the TypeCode enumeration. Multiple types get mapped to a common typecode. TypeCode typeCode = Type.GetTypeCode(fieldValue.GetType()); items.Add(field.Name); } }
public Script(bool redirectOutput = false) { Dictionary<string, object> options = new Dictionary<string, object>(); options["Debug"] = true; if (engine != null) engine.Runtime.Shutdown(); engine = Python.CreateEngine(options); scope = engine.CreateScope(); var all = System.Reflection.Assembly.GetExecutingAssembly(); engine.Runtime.LoadAssembly(all); scope.SetVariable("MAV", MainV2.comPort); scope.SetVariable("cs", MainV2.comPort.MAV.cs); scope.SetVariable("Script", this); scope.SetVariable("mavutil", this); engine.CreateScriptSourceFromString("print 'hello world from python'").Execute(scope); engine.CreateScriptSourceFromString("print cs.roll").Execute(scope); if (redirectOutput) { //Redirect output through this writer //this writer will not actually write to the memorystreams OutputWriter = new Utilities.StringRedirectWriter(); engine.Runtime.IO.SetErrorOutput(new MemoryStream(), OutputWriter); engine.Runtime.IO.SetOutput(new MemoryStream(), OutputWriter); } else OutputWriter = null; object thisBoxed = MainV2.comPort.MAV.cs; Type test = thisBoxed.GetType(); foreach (var field in test.GetProperties()) { // field.Name has the field's name. object fieldValue; try { fieldValue = field.GetValue(thisBoxed, null); // Get value } catch { continue; } // Get the TypeCode enumeration. Multiple types get mapped to a common typecode. TypeCode typeCode = Type.GetTypeCode(fieldValue.GetType()); items.Add(field.Name); } }