Example #1
0
    static void Init()
    {
        // Get existing open window or if none, make a new one:
        PythonTools window = (PythonTools)EditorWindow.GetWindow(typeof(PythonTools));

        window.Show();
    }
Example #2
0
    // initialization logic (it's Unity, so we don't do this in the constructor!
    public void OnEnable()
    {
        PythonTools window = (PythonTools)EditorWindow.GetWindow(typeof(PythonTools));

        window.titleContent = new GUIContent("Python Console", "Execute Unity functions via IronPython");

        // pure gui stuff
        consoleStyle.normal.textColor = Color.cyan;
        consoleStyle.margin           = new RectOffset(20, 10, 10, 10);
        historyStyle.normal.textColor = Color.white;
        historyStyle.margin           = new RectOffset(20, 10, 10, 10);

        // load up the hosting environment
        _ScriptEngine = IronPython.Hosting.Python.CreateEngine();
        _ScriptScope  = _ScriptEngine.CreateScope();

        // load the assemblies for unity, using types
        // to resolve assemblies so we don't need to hard code paths
        _ScriptEngine.Runtime.LoadAssembly(typeof(PythonFileIOModule).Assembly);
        _ScriptEngine.Runtime.LoadAssembly(typeof(GameObject).Assembly);
        _ScriptEngine.Runtime.LoadAssembly(typeof(Editor).Assembly);
        string dllpath = System.IO.Path.GetDirectoryName(
            (typeof(ScriptEngine)).Assembly.Location).Replace(
            "\\", "/");
        // load needed modules and paths
        StringBuilder init = new StringBuilder();

        init.AppendLine("import sys");
        init.AppendFormat("sys.path.append(\"{0}\")\n", dllpath + "/Lib");
        init.AppendFormat("sys.path.append(\"{0}\")\n", dllpath + "/DLLs");
        init.AppendLine("import UnityEngine as unity");
        init.AppendLine("import UnityEditor as editor");
        init.AppendLine("from cStringIO import StringIO");
        init.AppendLine("unity.Debug.Log(\"Python console initialized\")");
        init.AppendLine("__print_buffer = sys.stdout = StringIO()");
        var ScriptSource = _ScriptEngine.CreateScriptSourceFromString(init.ToString());

        ScriptSource.Execute(_ScriptScope);
    }
Example #3
0
 private static void RegisterExtension(PythonTools.Intellisense.VsProjectAnalyzer newAnalyzer)
 {
     newAnalyzer.RegisterExtension(typeof(DjangoAnalyzer).Assembly.CodeBase);
 }
Example #4
0
        public override IDictionary<string, IAnalysisSet> GetAllMembers(PythonTools.Interpreter.IModuleContext moduleContext) {
            Dictionary<string, IAnalysisSet> res = new Dictionary<string, IAnalysisSet>();
            foreach (var member in _members) {
                foreach (var keyValue in member.GetAllMembers(moduleContext)) {
                    IAnalysisSet existing;
                    if (res.TryGetValue(keyValue.Key, out existing)) {
                        MultipleMemberInfo existingMultiMember = existing as MultipleMemberInfo;
                        if (existingMultiMember != null) {
                            res[keyValue.Key] = MultipleMemberInfo.Create(existingMultiMember._members, keyValue.Value);
                        } else {
                            res[keyValue.Key] = MultipleMemberInfo.Create(existing, keyValue.Value);
                        }
                    } else {
                        res[keyValue.Key] = keyValue.Value;
                    }
                }
            }

            return res;
        }