示例#1
0
 /// <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);//*/
 }
示例#2
0
        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);
            scope.SetVariable("Joystick", MainV2.joystick);

            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);
             * }
             */
        }
 /// <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); //*/
 }
示例#4
0
        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);

            var paths = engine.GetSearchPaths();
            paths.Add(Settings.GetRunningDirectory() + "Lib.zip");
            engine.SetSearchPaths(paths);

            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);
            scope.SetVariable("Joystick", MainV2.joystick);

            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);
            }
             */
        }
示例#5
0
        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);
            var paths = engine.GetSearchPaths();
            paths.Add(@"C:\Program Files (x86)\IronPython 2.7\Lib"); //Allows for additional libraries from IronPython. Requires download from https://ironpython.codeplex.com/releases/view/90087
            engine.SetSearchPaths(paths);
            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); //Unneeded testing
            //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);
            }
        }