Esempio n. 1
0
        //interface


        //constructor
        public Console(IConsoleTarget target)
        {
            if (target == null)
            {
                throw new ArgumentException("target cannot be null");
            }
            title       = target.ConsoleTitle;
            this.target = target;
            var targetScope = target.GetScope();
            var locals      = new IronPython.Runtime.PythonDictionary();

            foreach (var name in targetScope.GetVariableNames())
            {
                locals[name] = targetScope.GetVariable(name);
            }
            scope = Py.CreateScope();
            scope.SetVariable("_locals", locals);
            var    ops         = scope.Engine.Operations;
            string init_script = System.IO.File.ReadAllText(Util.ResourcePath("PythonScripts/initialize_new_console.py"));

            Py.Engine.Execute(init_script, scope);
            python_output_buffer    = scope.GetVariable <IronPython.Modules.PythonIOModule.StringIO>("output_buffer");
            python_compile_command  = scope.GetVariable <IronPython.Runtime.PythonFunction>("compile_command");
            python_console_run_code = scope.GetVariable <IronPython.Runtime.PythonFunction>("console_run_code");

            output             = new LineBuffer(new string[] { ">>> " });
            input              = new LineBuffer(new string[] { "" });
            editor             = new StringBuilder(500);
            multilineEditor    = new StringBuilder(500);
            _currentInputIndex = 0;
            _editorCursor      = 0;
        }
        private void cmbFunction_SelectedIndexChanged(object sender, EventArgs e)
        {
            IronPython.Runtime.PythonFunction pf =
                (IronPython.Runtime.PythonFunction)AppGlobals.PyGetVar(cmbFunction.SelectedItem.ToString());
            lstInputs.Items.Clear();
            if (pf.__doc__ != null)
            {
                lblDesc.Text = "Description: \n" + pf.__doc__.ToString();
            }
            else
            {
                lblDesc.Text = "Description: N/A";
            }
            int var_count = 0;

            foreach (var item in pf.func_code.co_varnames)
            {
                lstInputs.Items.Add(item.ToString());
                var_count++;
                if (var_count >= pf.func_code.co_argcount)
                {
                    break;
                }
            }
        }
Esempio n. 3
0
 public static void unregister_event(IronPython.Runtime.PythonFunction pyFunc)
 {
     foreach (var eventObjects in PythonEventObjects)
     {
         if (eventObjects.PythonFunction == pyFunc)
         {
             eventObjects.EventInfo.RemoveEventHandler(eventObjects, eventObjects.Delegate);
         }
     }
 }
Esempio n. 4
0
 public override void Execute(Blocks.EventDescription e)
 {
     IronPython.Runtime.PythonFunction fun = (IronPython.Runtime.PythonFunction)AppGlobals.PyVarGetFunc(pf);
     if (fun != null)
     {
         object[] args = new object[InputNodes.Count];
         for (int i = 0; i < InputNodes.Count; i++)
         {
             args[i] = InputNodes[i].Object;
         }
         object result = AppGlobals.InvokeFunction(fun, args);
         OutputNodes[0].Object = result;
     }
 }
Esempio n. 5
0
        public static void register_event(string name, IronPython.Runtime.PythonFunction pyFunc)
        {
            foreach (var eventInfo in typeof(mp).GetEvents())
            {
                if (eventInfo.Name.ToLower() == name.Replace("-", ""))
                {
                    PythonEventObject eventObject = new PythonEventObject();
                    PythonEventObjects.Add(eventObject);
                    eventObject.PythonFunction = pyFunc;
                    MethodInfo mi;

                    if (eventInfo.EventHandlerType == typeof(Action))
                    {
                        mi = eventObject.GetType().GetMethod(nameof(PythonEventObject.Invoke));
                    }
                    else if (eventInfo.EventHandlerType == typeof(Action <EndFileEventMode>))
                    {
                        mi = eventObject.GetType().GetMethod(nameof(PythonEventObject.InvokeEndFileEventMode));
                    }
                    else if (eventInfo.EventHandlerType == typeof(Action <string[]>))
                    {
                        mi = eventObject.GetType().GetMethod(nameof(PythonEventObject.InvokeStrings));
                    }
                    else
                    {
                        throw new Exception();
                    }

                    eventObject.EventInfo = eventInfo;
                    Delegate handler = Delegate.CreateDelegate(eventInfo.EventHandlerType, eventObject, mi);
                    eventObject.Delegate = handler;
                    eventInfo.AddEventHandler(eventObject, handler);
                    break;
                }
            }
        }
Esempio n. 6
0
 public void RegisterEvent(string name, IronPython.Runtime.PythonFunction derp)
 {
     ScriptEngine.RegisterFunction(name, derp);
 }