예제 #1
0
        public void DoFile(string filename)
        {
            if (backgroundThread != null && backgroundThread.IsAlive)
            {
                DisplayError("Cannot run script; I'm processing...");
                return;
            }
            if (pyjamaModule == null)
            {
                pyjamaModule = new PyjamaModule(this, true);
                environment.Globals.SetVariable("pyjama", pyjamaModule);
            }
            // FIXME: uses cached version; how to force reload?
            // look through sys.modules, if module.__file__ matches, then delete it, and reload it
            // from this file with same name as before

            //ScriptScope sys = engine.GetSysModule(); // sys
            //sys.GetVariable("__file__");
            //? Microsoft.Scripting.SourceLocation;
            /*
            IronPython.Runtime.PythonDictionary dict = (IronPython.Runtime.PythonDictionary)sys.GetVariable("modules");
            List list = dict.items();
            foreach (PythonTuple name_module in list)
            {
                string name = (string)name_module[0];
                System.Console.WriteLine(name);
                Microsoft.Scripting.Runtime.Scope modScope = (Microsoft.Scripting.Runtime.Scope) name_module[1];
                System.Console.WriteLine("   File: {0}",  modScope.ContainsName(Symbol("__file__")));
            }
            */
            //foreach (KeyValuePair<string, object> pair in sys.GetItems()) {
            //    System.Console.WriteLine(pair);
            //}
            if (pyjamaModule.Threaded)
            {
                ThreadStart starter = delegate
                {
                    Execute(filename, SourceCodeKind.File);
                };
                backgroundThread = new Thread(new ThreadStart(starter));
                backgroundThread.IsBackground = true;
                // FIXME: set cursor to stay this way till done
                this.TopLevelControl.Cursor = Cursors.WaitCursor;
                backgroundThread.Start();
            }
            else
            {
                Execute(filename, SourceCodeKind.File);
            }
        }
예제 #2
0
 public void DoCommand(string command)
 {
     if (backgroundThread != null && backgroundThread.IsAlive)
     {
         DisplayError("Cannot evaluate script; I'm processing...");
         return;
     }
     if (pyjamaModule == null)
     {
         pyjamaModule = new PyjamaModule(this, true);
         environment.Globals.SetVariable("pyjama", pyjamaModule);
     }
     command = command.Trim();
     if (command != "")
     {
         bool first = true;
         foreach (string line in command.Split('\n'))
         {
             if (first)
                 this.consoleTextBox.AddText(line + "\n");
             else
                 this.consoleTextBox.printTextOnNewline("... " + line + "\n");
             first = false;
         }
         this.consoleTextBox.AddcommandHistory(command);
         // Interactive Meta Commands
         if (command == "#clear")
         {
             this.Clear();
         }
         else if (command == "#help")
         {
             this.WriteText(GetHelpText());
         }
         else if (command == "#python")
         {
             engine = environment.GetEngine("py");
             Prompt = "---- Python Mode ----";
             WriteText(Prompt + "\n");
         }
         else if (command == "#ruby")
         {
             engine = environment.GetEngine("rb");
             Prompt = "---- Ruby Mode ----";
             WriteText(Prompt + "\n");
         }
         else // Command
         {
             if (pyjamaModule.Threaded)
             {
                 ThreadStart starter = delegate { Execute(command, SourceCodeKind.InteractiveCode); };
                 backgroundThread = new Thread(new ThreadStart(starter));
                 backgroundThread.IsBackground = true;
                 // FIXME: set cursor to stay this way till done
                 this.TopLevelControl.Cursor = Cursors.WaitCursor;
                 backgroundThread.Start();
             }
             else
             {
                 Execute(command, SourceCodeKind.InteractiveCode);
             }
         }
     }
 }