Ejemplo n.º 1
0
        //Computes sections
        private void button_start_Click(object sender, EventArgs e)
        {
            if (toggleButton())
            {
                int numThreads = Int32.Parse(numeric_threads.Value.ToString());


                List <Section> sections = new List <Section>();
                sections.Add(new Section(0, 0, prevScreen.Bounds.Width, 100, checkbox_UseAudio.Checked, false, Int32.Parse(numeric_horizontalLEDs.Value.ToString())));          //Top
                sections.Add(new Section(0, prevScreen.Bounds.Height - 100, prevScreen.Bounds.Width, 100, false, false, Int32.Parse(numeric_horizontalLEDs.Value.ToString()))); //Bottom
                sections.Add(new Section(0, 0, 100, prevScreen.Bounds.Height, false, true, Int32.Parse(numeric_verticalLEDs.Value.ToString())));                                //Left
                sections.Add(new Section(prevScreen.Bounds.Width - 100, 0, 100, prevScreen.Bounds.Height, false, true, Int32.Parse(numeric_verticalLEDs.Value.ToString())));    //  Right
                dial = new LEDSimulate(pathScript, pathPython, formInst, sections, combo_monitor.SelectedIndex, numThreads);
                dial.Show();
            }
            else
            {
                button_flag = true;
                //Kill all the threads by closing
                dial.Close();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates form for simulating LEDs async
        /// </summary>
        /// <param name="pathScript">Path to python script</param>
        /// <param name="pathPython">Path to python.exe</param>
        /// <param name="formInst">Instance of the main form</param>
        /// <param name="sections">Number of parent sections</param>
        /// <param name="mon">Monitor index number</param>
        /// <param name="numThreads">Number of threads to use (dep)</param>
        public LEDSimulate(string pathScript, string pathPython, Form1 formInst, List <Section> sections, int mon, int numThreads)
        {
            InitializeComponent();
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.UserPaint, true);
            DoubleBuffered = true;
            instance       = this;

            this.TransparencyKey = (BackColor);
            this.sections        = sections;
            this.procs           = new List <Process>();
            this.formInst        = formInst;

            //Initialize timer to tick every 30 seconds to update UI
            timer_updatePaint.Interval = 33;

            //Load with dummy data to update later
            Pen dummy_pen = new Pen(Color.FromArgb(0, 0, 0, 0));

            foreach (Section s in sections)
            {
                for (int i = 0; i < s.subSections; i++)
                {
                    paintList.Add(new PaintForm(dummy_pen, 0, 0, 0, 0));
                }
            }

            //initialize for all sections
            var t = new Task(() =>
            {
                Section s    = sections[0];
                var psi      = new ProcessStartInfo();
                psi.FileName = pathPython;

                var script = pathScript;
                int startX = s.x, startY = s.y, width = s.width, height = s.height;

                int monitor   = mon + 1;
                psi.Arguments = $"\"{script}\" \"{((s.useAudio) ? "1" : "-2")}\" \"{monitor}\" \"{startX}\" \"{startY}\" \"{width}\" \"{height}\" \"{0}\"  \"{s.subSections}\"";

                psi.UseShellExecute        = false;
                psi.CreateNoWindow         = true;
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardError  = true;

                Process p             = new Process();
                p.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
                p.ErrorDataReceived  += new DataReceivedEventHandler(proc_ErrorDataReceived);
                p.StartInfo           = psi;
                p.Start();

                procs.Add(p);
                Console.WriteLine("Added process");
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();
            });

            t.Start();
            var t2 = new Task(() =>
            {
                Section s    = sections[1];
                var psi      = new ProcessStartInfo();
                psi.FileName = pathPython;

                var script = pathScript;
                int startX = s.x, startY = s.y, width = s.width, height = s.height;

                int monitor   = mon + 1;
                psi.Arguments = $"\"{script}\" \"{((s.useAudio) ? "1" : "-2")}\" \"{monitor}\" \"{startX}\" \"{startY}\" \"{width}\" \"{height}\" \"{1}\"  \"{s.subSections}\"";

                psi.UseShellExecute        = false;
                psi.CreateNoWindow         = true;
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardError  = true;

                Process p             = new Process();
                p.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
                p.ErrorDataReceived  += new DataReceivedEventHandler(proc_ErrorDataReceived);
                p.StartInfo           = psi;
                p.Start();

                procs.Add(p);
                Console.WriteLine("Added process");
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();
            });

            t2.Start();

            var t3 = new Task(() =>
            {
                Section s    = sections[2];
                var psi      = new ProcessStartInfo();
                psi.FileName = pathPython;

                var script = pathScript;
                int startX = s.x, startY = s.y, width = s.width, height = s.height;

                int monitor   = mon + 1;
                psi.Arguments = $"\"{script}\" \"{((s.useAudio) ? "1" : "-2")}\" \"{monitor}\" \"{startX}\" \"{startY}\" \"{width}\" \"{height}\" \"{2}\"  \"{s.subSections}\"";

                psi.UseShellExecute        = false;
                psi.CreateNoWindow         = true;
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardError  = true;

                Process p             = new Process();
                p.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
                p.ErrorDataReceived  += new DataReceivedEventHandler(proc_ErrorDataReceived);
                p.StartInfo           = psi;
                p.Start();

                procs.Add(p);
                Console.WriteLine("Added process");
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();
            });

            t3.Start();

            var t4 = new Task(() =>
            {
                Section s    = sections[3];
                var psi      = new ProcessStartInfo();
                psi.FileName = pathPython;

                var script  = pathScript;
                int startX  = s.x, startY = s.y, width = s.width, height = s.height;
                int monitor = mon + 1;

                Console.WriteLine($"\"{script}\" \"{((s.useAudio) ? "1" : "-2")}\" \"{monitor}\" \"{startX}\" \"{startY}\" \"{width}\" \"{height}\" \"{3}\"  \"{s.subSections}\"");

                psi.Arguments = $"\"{script}\" \"{((s.useAudio) ? "1" : "-2")}\" \"{monitor}\" \"{startX}\" \"{startY}\" \"{width}\" \"{height}\" \"{3}\"  \"{s.subSections}\"";

                psi.UseShellExecute        = false;
                psi.CreateNoWindow         = true;
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardError  = true;

                Process p             = new Process();
                p.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
                p.ErrorDataReceived  += new DataReceivedEventHandler(proc_ErrorDataReceived);
                p.StartInfo           = psi;
                p.Start();

                procs.Add(p);
                Console.WriteLine("Added process");
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();
            });

            t4.Start();
            Console.WriteLine("Finished adding and starting");
            timer_updatePaint.Start();
        }