[chronojump] MicroDiscover progressBars widgets on a list (unlimited)



commit eb23fb4d3c3d93b58550194e491063f3e0610560
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu May 12 16:19:08 2022 +0200

    MicroDiscover progressBars widgets on a list (unlimited)

 glade/app1.glade              | 28 ++++++++--------
 src/execute/arduinoCapture.cs | 40 ++++++-----------------
 src/gui/app1/chronojump.cs    | 74 +++++++++++++++++++++++++++++++------------
 3 files changed, 77 insertions(+), 65 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 9f82a5756..eebe14180 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -26560,6 +26560,12 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -42335,6 +42341,12 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -50285,10 +50297,10 @@ Since Chronojump 2.1.3, backups contain the complete data.</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkProgressBar" 
id="progressbar_micro_discover_ports">
-                                                            <property name="width_request">200</property>
+                                                            <widget class="GtkVBox" 
id="vbox_progressbar_micro_discover_l">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
+                                                            <property name="spacing">12</property>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -50296,18 +50308,6 @@ Since Chronojump 2.1.3, backups contain the complete data.</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
-                                                            <child>
-                                                            <widget class="GtkProgressBar" 
id="progressbar_micro_discover_status">
-                                                            <property name="width_request">200</property>
-                                                            <property name="visible">True</property>
-                                                            <property name="can_focus">False</property>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
-                                                            <property name="position">2</property>
-                                                            </packing>
-                                                            </child>
                                                             </widget>
                                                             </child>
                                                           </widget>
diff --git a/src/execute/arduinoCapture.cs b/src/execute/arduinoCapture.cs
index 71655db74..649c1b0e5 100644
--- a/src/execute/arduinoCapture.cs
+++ b/src/execute/arduinoCapture.cs
@@ -548,11 +548,8 @@ public class MicroDiscover : MicroComms
        private string wichroStr = "Wifi-Controller-"; //Will be used for Wichro and Quick, then user will 
decide. "local:get_channel;" to know the channel
        //private string encoderStr = "J"; //for encoder send a J and receive a J
 
-       public enum Status { CONNECTING, DETECTING, DONE };
-       private double progressBarCurrentMicroValue;
-       private string progressBarCurrentMicroText;
-       private double progressBarStatusValue;
-       private Status progressBarStatus;
+       public enum Status { NOTSTARTED, CONNECTING, DETECTING, DONE };
+       private List<Status> progressBar_l; //progressBars status
 
        //9600
        //private string rfidStr = "YES Chronojump RFID";
@@ -563,12 +560,15 @@ public class MicroDiscover : MicroComms
        {
                micro_l = new List<Micro> ();
                microDiscoverManage_l = new List<MicroDiscoverManage> ();
+               progressBar_l = new List<Status> ();
+
                cancel = false;
 
                foreach (string portName in portName_l)
                {
                        micro_l.Add(new Micro (portName, 115200));
                        microDiscoverManage_l.Add(new MicroDiscoverManage (portName));
+                       progressBar_l.Add(Status.NOTSTARTED);
                }
        }
 
@@ -580,17 +580,12 @@ public class MicroDiscover : MicroComms
                {
                        micro = micro_l[i]; //micro is the protected variable
 
-                       progressBarCurrentMicroValue = UtilAll.DivideSafe (i, micro_l.Count);
-                       progressBarCurrentMicroText = string.Format("{0}: {1}",
-                                       i + 1, micro.PortName);
-                       progressBarStatusValue = 0;
-                       progressBarStatus = Status.CONNECTING;
+                       progressBar_l[i] = Status.CONNECTING;
 
                        LogB.Information("Discover loop, port: " + micro.PortName);
                        if(connectAndSleep ())
                        {
-                               progressBarStatusValue = 0.5;
-                               progressBarStatus = Status.DETECTING;
+                               progressBar_l[i] = Status.DETECTING;
 
                                flush(); //after connect
                                if(mode == Constants.Modes.RUNSSIMPLE || mode == 
Constants.Modes.RUNSINTERVALLIC)
@@ -604,15 +599,11 @@ public class MicroDiscover : MicroComms
 
                        micro.ClosePort (); //close even connect failed?
                        discovered_l.Add(string.Format("{0} {1}", micro.PortName, micro.Discovered));
-
-                       progressBarStatusValue = 1;
-                       progressBarStatus = Status.DONE;
+                       progressBar_l[i] = Status.DONE;
 
                        if(cancel)
                                break;
                }
-               progressBarCurrentMicroValue = 1;
-               progressBarCurrentMicroText = "DONE";
 
                return discovered_l;
        }
@@ -897,20 +888,9 @@ public class MicroDiscover : MicroComms
        }
        */
 
-       public double ProgressBarCurrentMicroValue {
-               get { return progressBarCurrentMicroValue; }
+       public List<Status> ProgressBar_l {
+               get { return progressBar_l; }
        }
-       public string ProgressBarCurrentMicroText {
-               get { return progressBarCurrentMicroText; }
-       }
-
-       public double ProgressBarStatusValue {
-               get { return progressBarStatusValue; }
-       }
-       public string ProgressBarStatusText {
-               get { return progressBarStatus.ToString(); }
-       }
-
 }
 
 /*
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 60e66a9b0..60b2a0bf5 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -301,8 +301,7 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.VBox vbox_micro_discover;
        [Widget] Gtk.Button button_contacts_detect;
        [Widget] Gtk.Label label_micro_discover_ports;
-       [Widget] Gtk.ProgressBar progressbar_micro_discover_ports;
-       [Widget] Gtk.ProgressBar progressbar_micro_discover_status;
+       [Widget] Gtk.VBox vbox_progressbar_micro_discover_l;
        [Widget] Gtk.EventBox eventbox_button_micro_discover_cancel_close;
        [Widget] Gtk.Image image_button_micro_discover_cancel_close;
        [Widget] Gtk.Label label_button_micro_discover_cancel_close;
@@ -4554,6 +4553,26 @@ public partial class ChronoJumpWindow
           ----------------- discover / detect devices --------->
           */
 
+       List<Gtk.ProgressBar> progressbar_micro_discover_l;
+       private void setup_progressbar_micro_discover_l ()
+       {
+               // 1) delete old progressbars
+               if(progressbar_micro_discover_l != null)
+                       foreach (Gtk.ProgressBar pb in progressbar_micro_discover_l)
+                               vbox_progressbar_micro_discover_l.Remove (pb); //or RemoveAt
+
+               // 2) add new progressbars on the list
+               progressbar_micro_discover_l = new List<Gtk.ProgressBar> ();
+               for (int i = 0; i < microDiscover.ProgressBar_l.Count; i ++)
+               {
+                       Gtk.ProgressBar pb = new Gtk.ProgressBar();
+                       pb.Text = "----"; //to have height
+                       vbox_progressbar_micro_discover_l.Add (pb);
+                       progressbar_micro_discover_l.Add (pb);
+               }
+               vbox_progressbar_micro_discover_l.ShowAll();
+       }
+
        //right now implemented only contacts
        private void on_button_contacts_detect_clicked (object o, EventArgs args)
        {
@@ -4565,8 +4584,6 @@ public partial class ChronoJumpWindow
                        return;
 
                // 1) set up gui
-               progressbar_micro_discover_ports.Fraction = 0;
-               progressbar_micro_discover_status.Fraction = 0;
 
                //ChronoDebug cDebug = new ChronoDebug("Discover " + current_mode.ToString());
                //cDebug.Start();
@@ -4588,6 +4605,7 @@ public partial class ChronoJumpWindow
                if(list_discover_ports != null && list_discover_ports.Count > 0)
                {
                        microDiscover = new MicroDiscover (list_discover_ports); //all ports
+                       setup_progressbar_micro_discover_l ();
                        discoverThread = new Thread (new ThreadStart (discoverDo));
                        GLib.Idle.Add (new GLib.IdleHandler (pulseDiscoverGTK));
                        discoverThread.Start();
@@ -4609,18 +4627,32 @@ public partial class ChronoJumpWindow
        }
        private bool pulseDiscoverGTK ()
        {
-               progressbar_micro_discover_ports.Fraction = microDiscover.ProgressBarCurrentMicroValue;
-
-               if(microDiscover != null && microDiscover.Cancel)
-                       progressbar_micro_discover_ports.Text = Catalog.GetString("Cancelling");
-               else
-                       progressbar_micro_discover_ports.Text = microDiscover.ProgressBarCurrentMicroText;
+               if(microDiscover == null)
+               {
+                       Thread.Sleep (200);
+                       return true;
+               }
 
-               //progressbar_micro_discover_status.Fraction = microDiscover.ProgressBarStatusValue;
-               if(microDiscover != null && microDiscover.Cancel)
-                       progressbar_micro_discover_status.Text = Catalog.GetString("Cancelling");
-               else
-                       progressbar_micro_discover_status.Text = microDiscover.ProgressBarStatusText;
+               //update progressbar message
+               for (int i = 0; i < progressbar_micro_discover_l.Count; i ++)
+               {
+                       Gtk.ProgressBar pb = progressbar_micro_discover_l[i];
+                       if (microDiscover.ProgressBar_l[i] == MicroDiscover.Status.NOTSTARTED)
+                       {
+                               pb.Text = "----"; //to have height
+                               pb.Fraction = 0;
+                       } else if (microDiscover.ProgressBar_l[i] == MicroDiscover.Status.DONE)
+                       {
+                               pb.Text = microDiscover.ProgressBar_l[i].ToString();
+                               pb.Fraction = 1;
+                       } else {
+                               if (microDiscover.Cancel)
+                                       pb.Text = Catalog.GetString("Cancelling");
+                               else
+                                       pb.Text = microDiscover.ProgressBar_l[i].ToString();
+                               pb.Pulse ();
+                       }
+               }
 
                if(! discoverThread.IsAlive)
                {
@@ -4628,12 +4660,13 @@ public partial class ChronoJumpWindow
                        LogB.Information("pulseDiscoverGTK ending here");
                        LogB.ThreadEnded();
 
-                       progressbar_micro_discover_status.Fraction = 1;
-
-                       if(microDiscover != null && microDiscover.Cancel)
+                       for (int i = 0; i < progressbar_micro_discover_l.Count; i ++)
                        {
-                               progressbar_micro_discover_ports.Text = Catalog.GetString("Cancelled");
-                               progressbar_micro_discover_status.Text = Catalog.GetString("Cancelled");
+                               if (microDiscover.Cancel &&
+                                                microDiscover.ProgressBar_l[i] != MicroDiscover.Status.DONE)
+                                       (progressbar_micro_discover_l[i]).Text = 
Catalog.GetString("Cancelled");
+
+                               (progressbar_micro_discover_l[i]).Fraction = 1;
                        }
 
                        image_button_micro_discover_cancel_close.Pixbuf =
@@ -4643,7 +4676,6 @@ public partial class ChronoJumpWindow
                        return false;
                }
 
-               progressbar_micro_discover_status.Pulse ();
                Thread.Sleep (200);
                return true;
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]