Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm working on a project in which I am creating a IronPython compiler depend on IronPython , But I have some problem on debugging the Script and can use breakpoint ? could you please give me some help ? thanks.

C#
public ScriptEngine GetEngine()
    {
        if (_engine != null)
            return _engine;
        _engine = Python.CreateEngine();
        _engine.Runtime.IO.SetOutput(_stream, Encoding.UTF8);
        _engine.Runtime.IO.SetErrorOutput(_stream, Encoding.UTF8);
        string path = Environment.CurrentDirectory;
        string ironPythonLibPath = string.Format(@"{0}\IronPythonLib.zip", path);
        var paths = _engine.GetSearchPaths() as List<string> ?? new List<string>();
        paths.Add(path);
        paths.Add(ironPythonLibPath);
        path = Environment.GetEnvironmentVariable("IRONPYTHONPATH");
        if (!string.IsNullOrEmpty(path))
        {
            var pathStrings = path.Split(';');
            paths.AddRange(pathStrings.Where(p => p.Length > 0));
        }
        _engine.SetSearchPaths(paths.ToArray());
        return _engine;
    }

    private void GetPythonVarsInfo(ScriptScope scope)
    {
        _varList.Clear();
        var items = scope.GetItems();
        foreach (var item in items)
        {
            _varList.Add(new VarValue
            {
                VarName = item.Key,
                Value = item.Value
            });
        }
        valueListView.ItemsSource = _varList;
    }

    private void OnExecuteButtonClick(object sender, ItemClickEventArgs e)
    {
        string outPutString = string.Empty;
        outPutString = "*************************************" +
            "Excute Date: " + DateTime.Now.ToLocalTime().ToString(CultureInfo.InvariantCulture);
        ExeceutePython(document, outPutString);
        TabControl.SelectedIndex = 2;
    }

    private void ExeceutePython(EditorDocument document, string outPutString)
    {
        ScriptEngine engine = GetEngine();
        string script = document.Text;
        ScriptSource source = engine.CreateScriptSourceFromString(script);
        ScriptScope scope = _engine.CreateScope();
        try
        {
            source.Compile();
            OutputTextBox.AppendText(outPutString + Environment.NewLine);
            var result = source.Execute(scope);
            if (result != null)
            {
                OutputTextBox.AppendText(engine.Operations.Format(result));
            }
            OutputTextBox.AppendText(Environment.NewLine);
            GetPythonVarsInfo(scope);
        }
        catch (Exception ex)
        {
            var eo = engine.GetService<ExceptionOperations>();
            var eoString = eo.FormatException(ex);
            OutputTextBox.AppendText(eoString);
            return;
        }
    }
Posted

1 solution

You would probably get an answer quicker at https://ironpython.codeplex.com/documentation[^].
 
Share this answer
 
Comments
EvgetH 9-Nov-15 21:32pm    
hi, I am sorry that maybe I have not explain my problem clearly. I want Crate a Python Script Debugger just using some Dlls Which provided by IronPython. I use the Control (Named SyntaxEditor) which provided by Actiprosoftware as my foreground,and use IronPython DLLS to Debuge the code which I have Inserted breakpoint. thanks all the same
Richard MacCutchan 10-Nov-15 3:42am    
And as I suggested, you will most likely get a quicker answer at the IronPython site.
EvgetH 10-Nov-15 20:23pm    
hi,I have Upload my Project there https://github.com/heyxEvget/IronPython-Debugger

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900