Esempio n. 1
0
        private void chooseInterpreterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(sorry);
            locatePython locPy = new locatePython();

            locPy.ShowDialog();
        }
Esempio n. 2
0
 public override GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e)
 {
     if (e.Button == System.Windows.Forms.MouseButtons.Left)
     {
         System.Drawing.Rectangle rec = ButtonBounds;
         if (rec.Contains((int)e.CanvasLocation.X, (int)e.CanvasLocation.Y))
         {
             //MessageBox.Show("Still under Development", "Refresh", MessageBoxButton.OK);
             locatePython gg = new locatePython();
             gg.ShowDialog();
             System.Drawing.Graphics g = null;
             button.Render(g, Color.Blue);
             return(GH_ObjectResponse.Handled);
         }
     }
     return(base.RespondToMouseDown(sender, e));
 }
Esempio n. 3
0
        public string getPythonInterpretere(string datfile)
        {
            if (!File.Exists(@datfile))
            {
                string defaultFileName = "Python.exe";
                //MessageBox.Show("Not exists");
                if (File.Exists(@"C:\Python27\python.exe"))
                {
                    defaultFileName = @"C:\Python27\python.exe";
                }
                else if (File.Exists(@"C:\Anaconda\python.exe"))
                {
                    defaultFileName = @"C:\Anaconda\python.exe";
                }
                else if (File.Exists(@"C:\Python34\python.exe"))
                {
                    defaultFileName = @"C:\Python34\python.exe";
                }
                else if (File.Exists(@"C:\Python35\python.exe"))
                {
                    defaultFileName = @"C:\Python35\python.exe";
                }
                else if (File.Exists(@"C:\Python36\python.exe"))
                {
                    defaultFileName = @"C:\Python36\python.exe";
                }

                else if (File.Exists(@"C:\Program Files (x86)\Python27\python.exe"))
                {
                    defaultFileName = @"C:\Program Files (x86)\Python27\python.exe";
                }
                else if (File.Exists(@"C:\Program Files (x86)\Python34\python.exe"))
                {
                    defaultFileName = @"C:\Program Files (x86)\Python34\python.exe";
                }
                else if (File.Exists(@"C:\Program Files (x86)\Python35\python.exe"))
                {
                    defaultFileName = @"C:\Program Files (x86)\Python35\python.exe";
                }
                else if (File.Exists(@"C:\Program Files (x86)\Python36\python.exe"))
                {
                    defaultFileName = @"C:\Program Files (x86)\Python36\python.exe";
                }

                else if (File.Exists(@"C:\Program Files\Python27\python.exe"))
                {
                    defaultFileName = @"C:\Program Files\Python27\python.exe";
                }
                else if (File.Exists(@"C:\Program Files\Python34\python.exe"))
                {
                    defaultFileName = @"C:\Program Files\Python34\python.exe";
                }
                else if (File.Exists(@"C:\Program Files\Python35\python.exe"))
                {
                    defaultFileName = @"C:\Program Files\Python35\python.exe";
                }
                else if (File.Exists(@"C:\Program Files\Python36\python.exe"))
                {
                    defaultFileName = @"C:\Program Files\Python36\python.exe";
                }
                File.WriteAllText(@datfile, defaultFileName);

                return(@defaultFileName);
            }
            else
            {
                if (File.ReadAllText(@datfile).Trim() != String.Empty)
                {
                    string StartFileName = File.ReadAllText(@datfile);
                    //MessageBox.Show("Exists at\n"+StartFileName);
                    return(@StartFileName);
                }
                else
                {
                    locatePython locPy = new locatePython();
                    locPy.ShowDialog();
                    try
                    {
                        string StartFileName = File.ReadAllText(@datfile);
                        return(@StartFileName);
                    }catch
                    {
                        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.");
                        return(@"Python.exe");
                    }
                }
            }
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public Gh_CPythonComponent()
            : base("GH_CPython", "GH_CPython",
                   "a python IDE interface",
                   "Maths", "Script")
        {
            if (!Directory.Exists(@"C:\GH_CPython\"))
            {
                Directory.CreateDirectory(@"C:\GH_CPython\");
                path = @"C:\GH_CPython\";
            }
            else
            {
                path = @"C:\GH_CPython\";
            }
            if (!File.Exists(@"C:\GH_CPython\interpreter.dat"))
            {
                if (File.Exists(@"C:\Python27\python.exe"))
                {
                    defaultFileName = @"C:\Python27\python.exe";
                }
                else if (File.Exists(@"C:\Anaconda\python.exe"))
                {
                    defaultFileName = @"C:\Anaconda\python.exe";
                }
                else if (File.Exists(@"C:\Python34\python.exe"))
                {
                    defaultFileName = @"C:\Python34\python.exe";
                }
                else if (File.Exists(@"C:\Python35\python.exe"))
                {
                    defaultFileName = @"C:\Python35\python.exe";
                }
                else if (File.Exists(@"C:\Python36\python.exe"))
                {
                    defaultFileName = @"C:\Python36\python.exe";
                }

                else if (File.Exists(@"C:\Program Files (x86)\Python27\python.exe"))
                {
                    defaultFileName = @"C:\Program Files (x86)\Python27\python.exe";
                }
                else if (File.Exists(@"C:\Program Files (x86)\Python34\python.exe"))
                {
                    defaultFileName = @"C:\Program Files (x86)\Python34\python.exe";
                }
                else if (File.Exists(@"C:\Program Files (x86)\Python35\python.exe"))
                {
                    defaultFileName = @"C:\Program Files (x86)\Python35\python.exe";
                }
                else if (File.Exists(@"C:\Program Files (x86)\Python36\python.exe"))
                {
                    defaultFileName = @"C:\Program Files (x86)\Python36\python.exe";
                }

                else if (File.Exists(@"C:\Program Files\Python27\python.exe"))
                {
                    defaultFileName = @"C:\Program Files\Python27\python.exe";
                }
                else if (File.Exists(@"C:\Program Files\Python34\python.exe"))
                {
                    defaultFileName = @"C:\Program Files\Python34\python.exe";
                }
                else if (File.Exists(@"C:\Program Files\Python35\python.exe"))
                {
                    defaultFileName = @"C:\Program Files\Python35\python.exe";
                }
                else if (File.Exists(@"C:\Program Files\Python36\python.exe"))
                {
                    defaultFileName = @"C:\Program Files\Python36\python.exe";
                }
                File.WriteAllText(@"C:\GH_CPython\interpreter.dat", defaultFileName);
                locatePython locPy = new locatePython();
                locPy.ShowDialog();
            }
            else
            {
                if (File.ReadAllText(@"C:\GH_CPython\interpreter.dat").Trim() != String.Empty)
                {
                    StartFileName = File.ReadAllText(@"C:\GH_CPython\interpreter.dat");
                }
                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.");
                }
            }

            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 ? 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();
        }