From df326cf9920bdacbfc4fea19bd4e6c926abe9765 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 8 Sep 2016 14:45:27 +0200 Subject: [PATCH] Rename python core object, so renderdoc can be the module/namespace --- renderdocui/Windows/Dialogs/PythonShell.cs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/renderdocui/Windows/Dialogs/PythonShell.cs b/renderdocui/Windows/Dialogs/PythonShell.cs index 7273ff292..4414dfceb 100644 --- a/renderdocui/Windows/Dialogs/PythonShell.cs +++ b/renderdocui/Windows/Dialogs/PythonShell.cs @@ -119,9 +119,21 @@ namespace renderdocui.Windows.Dialogs private ScriptScope NewScope(ScriptEngine engine) { + engine.Runtime.LoadAssembly(typeof(PythonShell).Assembly); + var scope = engine.CreateScope(); - scope.SetVariable("renderdoc", m_Core); + scope.SetVariable("pyrenderdoc", m_Core); + + // try to import the RenderDoc namespace. + // This isn't equivalent to scope.ImportModule + try + { + engine.CreateScriptSourceFromString("import renderdoc").Execute(scope); + } + catch (Exception) + { + } return scope; } @@ -288,7 +300,9 @@ namespace renderdocui.Windows.Dialogs private void clearCmd_Click(object sender, EventArgs e) { interactiveOutput.Text = String.Format("RenderDoc Python console, powered by IronPython {0}{1}" + - "The 'renderdoc' object is the Core class instance.{1}", IronPython.CurrentVersion.AssemblyFileVersion, Environment.NewLine); + "The 'pyrenderdoc' object is the Core class instance.{1}" + + "The 'renderdoc' module is available, as the matching namespace in C#.{1}", + IronPython.CurrentVersion.AssemblyFileVersion, Environment.NewLine); shellscope = NewScope(pythonengine); } @@ -495,7 +509,9 @@ namespace renderdocui.Windows.Dialogs private void newScript_Click(object sender, EventArgs e) { scriptEditor.Text = String.Format("# RenderDoc Python scripts, powered by IronPython {0}\n" + - "# The 'renderdoc' object is the Core class instance.\n\n", IronPython.CurrentVersion.AssemblyFileVersion); + "# The 'pyrenderdoc' object is the Core class instance.\n" + + "# The 'renderdoc' module is available, as the matching namespace in C#\n\n", + IronPython.CurrentVersion.AssemblyFileVersion); scriptEditor.Text = scriptEditor.Text.Replace("\n", Environment.NewLine); }