/// <summary> /// Constructor /// </summary> public Gh_CPythonComponent() : base("GH_CPython", "GH_CPython", "a python IDE interface", "Maths", "Script") { initfunc = new InitFunctions(); //1- Look for default GH_CPython path i.e.'C:\GH_CPython\' path = initfunc.isPythonFloderExists(@"C:\GH_CPython\"); //2- Look for and set Python.exe interpreter if not set StartFileName = initfunc.getPythonInterpretere(@"C:\GH_CPython\interpreter.dat"); //3- Add latest version of required python modules if not existed initfunc.addGrasshopperPyModule(@"C:\GH_CPython\Grasshopper.py", pythonVersion); // initiate python IDE instance PythonIDE = new PythonShell(); PythonIDE.TopMost = true; PreviewExpired += Gh_CPythonComponent_PreviewExpired; thisIndex = Globals.index; name = "PythonFileWritten_" + thisIndex.ToString(); Globals.fileName.Add(thisIndex, "_PythonExecutionOrder_" + thisIndex.ToString()); Globals.index += 1; Globals.OpenThisShell.Add(thisIndex, false); ///Initiate Python process options. ///Don't show Shell - Redirect Standard output - Redirect Standard error - Hide Shell RunningPythonProcess.StartInfo.UseShellExecute = false; RunningPythonProcess.StartInfo.RedirectStandardOutput = true; RunningPythonProcess.StartInfo.RedirectStandardError = true; RunningPythonProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; RunningPythonProcess.StartInfo.UseShellExecute = false; RunningPythonProcess.StartInfo.CreateNoWindow = true; /// Initiate Python IDE Editor text, it should be like so: - Change if you wish- //# -*- coding: utf-8 -*- //""" //Python Script //Created on Tuesday August 2017 12:22:25 //@author: UserName //""" at = DateTime.Now.ToString("dddd MMMM yyyy hh:mm:ss"); string Name = System.Environment.UserName; InitialPythonText = Resources.SavedPythonFile.Shellinit.Replace("##CreatedBy##", Name); InitialPythonText = InitialPythonText.Replace("##at##", at); try { /// Initiate Console data as follows /// "Hi UserName, How are you ?" PythonIDE.console.Text = "Hi " + Name + ", How are you ?"; /// retrievedData are the data that are saved just after closing the Form (either by clicking x or close) /// They are saved here and then retrieved just after reopening the form again. if (writtenText != "") { PythonIDE.PythonCanvas.Text = writtenText; retrievedData = writtenText; } else if (retrievedData != "") { PythonIDE.PythonCanvas.Text = retrievedData; writtenText = retrievedData; } else { PythonIDE.PythonCanvas.Text = InitialPythonText; retrievedData = InitialPythonText; writtenText = InitialPythonText; } /// This function reads all the input data, then initiates it in python syntax /// this refrers to the present winForm i.e. the python IDE. /// writeReaadPythonFile function needs a lot of work to handle different inputs in a proper way /// EventHandler of the Form Closing PythonIDE.FormClosing += Ps_FormClosing; PythonIDE.manageDataItem.Click += manageDataItem_Click; /// Handleing Test button click. PythonIDE.Test.Click += (se, ev) => { AddNamesAndDescriptions(); //writeReadPythonFile(this); ExpireSolution(true); }; PythonIDE.PythonCanvas.KeyDown += PythonCanvas_KeyDown; PythonIDE.close.Click += (se, ev) => { InitialPythonText = PythonIDE.PythonCanvas.Text; shellOpened = false; PythonIDE.Hide(); AddNamesAndDescriptions(); Globals.OpenThisShell[thisIndex] = false; Grasshopper.Instances.RedrawCanvas(); }; Grasshopper.Instances.RedrawCanvas(); } catch { } AddNamesAndDescriptions(); }
/// <summary> /// Constructor /// </summary> public Gh_CPythonComponent() : base("GH_CPython", "GH_CPython", "a python IDE interface", "Maths", "Script") { PythonIDE = new PythonShell(); PythonIDE.TopMost = true; PreviewExpired += Gh_CPythonComponent_PreviewExpired; thisIndex = Globals.index; name = "PythonFileWritten_" + thisIndex.ToString(); Globals.fileName.Add(thisIndex, "_PythonExecutionOrder_" + thisIndex.ToString()); Globals.index += 1; Globals.OpenThisShell.Add(thisIndex, false); // Verify that Python is installed on the machine properly. if (File.Exists(@"C:\Python27\python.exe")) { StartFileName = @"C:\Python27\python.exe"; } else if (File.Exists(@"C:\Anaconda\python.exe")) { StartFileName = @"C:\Anaconda\python.exe"; } else if (File.Exists(@"C:\Python34\python.exe")) { StartFileName = @"C:\Python34\python.exe"; } else if (File.Exists(@"C:\Python35\python.exe")) { StartFileName = @"C:\Python35\python.exe"; } else if (File.Exists(@"C:\Python36\python.exe")) { StartFileName = @"C:\Python36\python.exe"; } else if (File.Exists(@"C:\Program Files (x86)\Python27\python.exe")) { StartFileName = @"C:\Program Files (x86)\Python27\python.exe"; } else if (File.Exists(@"C:\Program Files (x86)\Python34\python.exe")) { StartFileName = @"C:\Program Files (x86)\Python34\python.exe"; } else if (File.Exists(@"C:\Program Files (x86)\Python35\python.exe")) { StartFileName = @"C:\Program Files (x86)\Python35\python.exe"; } else if (File.Exists(@"C:\Program Files (x86)\Python36\python.exe")) { StartFileName = @"C:\Program Files (x86)\Python36\python.exe"; } else if (File.Exists(@"C:\Program Files\Python27\python.exe")) { StartFileName = @"C:\Program Files\Python27\python.exe"; } else if (File.Exists(@"C:\Program Files\Python34\python.exe")) { StartFileName = @"C:\Program Files\Python34\python.exe"; } else if (File.Exists(@"C:\Program Files\Python35\python.exe")) { StartFileName = @"C:\Program Files\Python35\python.exe"; } else if (File.Exists(@"C:\Program Files\Python36\python.exe")) { StartFileName = @"C:\Program Files\Python36\python.exe"; } else { MessageBox.Show("Sorry, We can't find Python installed on your machine, If you have already installed it, would you contact Mahmoud Abdlerahman via this e-mail \n [email protected]\n Thanks."); } ///Initiate Python process options. ///Don't show Shell - Redirect Standard output - Redirect Standard error - Hide Shell RunningPythonProcess.StartInfo.UseShellExecute = false; RunningPythonProcess.StartInfo.RedirectStandardOutput = true; RunningPythonProcess.StartInfo.RedirectStandardError = true; RunningPythonProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; RunningPythonProcess.StartInfo.UseShellExecute = false; RunningPythonProcess.StartInfo.CreateNoWindow = true; /// Initiate Python IDE Editor text, it should be like so: - Change if you wish- //# -*- coding: utf-8 -*- //""" //Python Script //Created on Tuesday August 2017 12:22:25 //@author: UserName //""" at = DateTime.Now.ToString("dddd MMMM yyyy hh:mm:ss"); string Name = System.Environment.UserName; InitialPythonText = Resources.SavedPythonFile.Shellinit.Replace("##CreatedBy##", Name); InitialPythonText = InitialPythonText.Replace("##at##", at); try { /// Initiate Console data as follows /// "Hi UserName, How are you ? Are you ready to Change the world ?" PythonIDE.console.Text = "Hi " + Name + ", How are you ? Are you ready to Change the world ?"; /// retrievedData are the data that are saved just after closing the Form (either by clicking x or close) /// They are saved here and then retrieved just after reopening the form again. if (writtenText != "") { PythonIDE.PythonCanvas.Text = writtenText; retrievedData = writtenText; } else if (retrievedData != "") { PythonIDE.PythonCanvas.Text = retrievedData; writtenText = retrievedData; } else { PythonIDE.PythonCanvas.Text = InitialPythonText; retrievedData = InitialPythonText; writtenText = InitialPythonText; } /// This function reads all the input data, then initiates it in python syntax /// this refrers to the present winForm i.e. the python IDE. /// writeReaadPythonFile function needs a lot of work to handle different inputs in a proper way writeReadPythonFile(this); /// EventHandler of the Form Closing PythonIDE.FormClosing += Ps_FormClosing; /// Handleing Test button click. PythonIDE.Test.Click += (se, ev) => { AddNamesAndDescriptions(); //writeReadPythonFile(this); ExpireSolution(true); }; PythonIDE.close.Click += (se, ev) => { InitialPythonText = PythonIDE.PythonCanvas.Text; shellOpened = false; PythonIDE.Hide(); AddNamesAndDescriptions(); Globals.OpenThisShell[thisIndex] = false; Grasshopper.Instances.RedrawCanvas(); }; Grasshopper.Instances.RedrawCanvas(); } catch (Exception erx) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, erx.ToString()); //MessageBox.Show(erx.ToString()); } AddNamesAndDescriptions(); }
/// <summary> /// Constructor /// </summary> public PythonInterfaceComponent() : base("GH_CPython", "GH_CPython", "a python IDE interface", "Maths", "Script") { PythonIDE = new PythonShell(); PythonIDE.TopMost = true; thisIndex = Globals.index; name = "PythonFileWritten_" + thisIndex.ToString(); Globals.fileName.Add(thisIndex, "_PythonExecutionOrder_" + thisIndex.ToString()); Globals.index += 1; Globals.OpenThisShell.Add(thisIndex, false); ///Initiate Python process options. ///Don't show Shell - Redirect Standard output - Redirect Standard error - Hide Shell RunningPythonProcess.StartInfo.UseShellExecute = false; RunningPythonProcess.StartInfo.RedirectStandardOutput = true; RunningPythonProcess.StartInfo.RedirectStandardError = true; RunningPythonProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; RunningPythonProcess.StartInfo.UseShellExecute = false; //RunningPythonProcess.StartInfo.CreateNoWindow = true; /// This adds Python folder to Windows Environment Paths variables. /// if it exists, set python as the process file name , else, set python folders and then set python as the process filename if (ExistsOnPath("python.exe")) { RunningPythonProcess.StartInfo.FileName = "python.exe"; } else { string pp = System.Environment.GetEnvironmentVariable("PATH"); string path_ = pp + @";C:\Python27;C:\Python27\DLLs;C:\Python27\Scripts"; System.Environment.SetEnvironmentVariable("PATH", path_); RunningPythonProcess.StartInfo.FileName = "python.exe"; } /// Initiate Python IDE Editor text, it should be like so: - Change if you wish- /* # -*- coding: utf-8 -*- * """ * Python Script * Created on Tuesday August 2017 12:22:25 * @author: UserName * """ */ at = DateTime.Now.ToString("dddd MMMM yyyy hh:mm:ss"); string Name = System.Environment.UserName; InitialPythonText = Resources.SavedPythonFile.Shellinit.Replace("##CreatedBy##", Name); InitialPythonText = InitialPythonText.Replace("##at##", at); try { /// Initiate Console data as follows /// "Hi UserName, How are you ? Are you ready to Change the world ?" PythonIDE.console.Text = "Hi " + Name + ", How are you ? Are you ready to Change the world ?"; /// retrievedData are the data that are saved just after closing the Form (either by clicking x or close) /// They are saved here and then retrieved just after reopening the form again. if (writtenText != "") { PythonIDE.PythonCanvas.Text = writtenText; retrievedData = writtenText; } else if (retrievedData != "") { PythonIDE.PythonCanvas.Text = retrievedData; writtenText = retrievedData; } else { PythonIDE.PythonCanvas.Text = InitialPythonText; retrievedData = InitialPythonText; writtenText = InitialPythonText; } /// This function reads all the input data, then initiates it in python syntax /// this refrers to the present winForm i.e. the python IDE. /// writeReaadPythonFile function needs a lot of work to handle different inputs in a proper way writeReadPythonFile(this); /// EventHandler of the Form Closing PythonIDE.FormClosing += Ps_FormClosing; /// Handleing Test button click. PythonIDE.Test.Click += (se, ev) => { //writeReadPythonFile(this); ExpireSolution(true); }; PythonIDE.close.Click += (se, ev) => { InitialPythonText = PythonIDE.PythonCanvas.Text; shellOpened = false; PythonIDE.Hide(); Globals.OpenThisShell[thisIndex] = false; Grasshopper.Instances.RedrawCanvas(); }; Grasshopper.Instances.RedrawCanvas(); } catch (Exception erx) { MessageBox.Show(erx.ToString()); } }