[chronojump] gui for microDiscover with thread and pulsebars



commit 8c0f1d36ba843db6bfa555fefbe93f31881ed069
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed May 11 11:49:21 2022 +0200

    gui for microDiscover with thread and pulsebars

 glade/app1.glade           | 283 +++++++++++++++++++++++++++++++++++++++++++--
 src/gui/app1/chronojump.cs | 101 ++++++++++++----
 src/gui/app1/icons.cs      |   2 +
 3 files changed, 352 insertions(+), 34 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index e893c6056..466474b5c 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -26554,6 +26554,9 @@ Concentric</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -32962,18 +32965,6 @@ Concentric</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">6</property>
                                                             <child>
-                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
-                                                            <property name="can_focus">False</property>
-                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
-                                                            </widget>
-                                                            <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
-                                                            <property name="pack_type">end</property>
-                                                            <property name="position">0</property>
-                                                            </packing>
-                                                            </child>
-                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_capturing">
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">4</property>
@@ -33010,6 +33001,18 @@ Concentric</property>
                                                             </packing>
                                                             </child>
                                                             <child>
+                                                            <widget class="GtkLabel" 
id="label_video_encoder_tests_will_be_filmed">
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" translatable="yes">Tests 
will be filmed</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="pack_type">end</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
                                                             <widget class="GtkHBox" 
id="hbox_video_encoder_no_capturing">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
@@ -42323,6 +42326,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -50216,6 +50222,259 @@ Since Chronojump 2.1.3, backups contain the complete data.</property>
                                     <property name="type">tab</property>
                                   </packing>
                                 </child>
+                                <child>
+                                  <widget class="GtkVBox" id="vbox_micro_discover">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="spacing">4</property>
+                                    <child>
+                                      <widget class="GtkFrame" id="frame7">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="label_xalign">0</property>
+                                        <property name="shadow_type">none</property>
+                                        <child>
+                                          <widget class="GtkVBox" id="vbox268">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <child>
+                                              <widget class="GtkHBox" id="hbox222">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <child>
+                                                  <widget class="GtkVBox" id="vbox269">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <property name="spacing">25</property>
+                                                    <child>
+                                                      <widget class="GtkFrame" id="frame_micro_discover">
+                                                        <property name="width_request">300</property>
+                                                        <property name="height_request">250</property>
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="label_xalign">0</property>
+                                                        <property name="label_yalign">1</property>
+                                                        <property name="shadow_type">in</property>
+                                                        <child>
+                                                          <widget class="GtkViewport" id="viewport27">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="border_width">4</property>
+                                                            <child>
+                                                            <widget class="GtkVBox" id="vbox270">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="border_width">20</property>
+                                                            <property name="spacing">20</property>
+                                                            <child>
+                                                            <widget class="GtkLabel" 
id="label_micro_discover_ports">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="xalign">0</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkProgressBar" 
id="progressbar_micro_discover_ports">
+                                                            <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">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>
+                                                            <child>
+                                                            <widget class="GtkButton" 
id="button_menu_discover_ports_accept_selected_or_cancel">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">True</property>
+                                                            <child>
+                                                            <widget class="GtkHBox" id="hbox225">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="spacing">10</property>
+                                                            <child>
+                                                            <widget class="GtkImage" 
id="image_menu_help_about1">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property 
name="stock">gtk-missing-image</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkLabel" 
id="label_menu_help_about1">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" translatable="yes">accept 
selected or cancel</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">3</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            </child>
+                                                          </widget>
+                                                        </child>
+                                                        <child>
+                                                          <widget class="GtkLabel" id="label661">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" translatable="yes">Detect 
device</property>
+                                                          </widget>
+                                                          <packing>
+                                                            <property name="type">label_item</property>
+                                                          </packing>
+                                                        </child>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">True</property>
+                                                        <property name="fill">False</property>
+                                                        <property name="position">0</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <widget class="GtkHButtonBox" id="hbuttonbox26">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <child>
+                                                          <widget class="GtkButton" 
id="button_micro_discover_close">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="can_default">True</property>
+                                                            <property 
name="receives_default">False</property>
+                                                            <signal name="clicked" 
handler="on_button_micro_discover_close_clicked" swapped="no"/>
+                                                            <accelerator key="Escape" signal="clicked"/>
+                                                            <child>
+                                                            <widget class="GtkEventBox" 
id="eventbox_button_micro_discover_close">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <child>
+                                                            <widget class="GtkHBox" id="hbox226">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="spacing">4</property>
+                                                            <child>
+                                                            <widget class="GtkImage" 
id="image_button_micro_discover_close">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property 
name="stock">gtk-missing-image</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">0</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkLabel" 
id="label_button_micro_discover_close">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" 
translatable="yes">Close</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            </child>
+                                                          </widget>
+                                                          <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">0</property>
+                                                          </packing>
+                                                        </child>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">False</property>
+                                                        <property name="fill">False</property>
+                                                        <property name="position">1</property>
+                                                      </packing>
+                                                    </child>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">True</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">True</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">0</property>
+                                              </packing>
+                                            </child>
+                                          </widget>
+                                        </child>
+                                        <child>
+                                          <placeholder/>
+                                          <packing>
+                                            <property name="type">label_item</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                  </widget>
+                                  <packing>
+                                    <property name="position">7</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <widget class="GtkLabel" id="label660">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label">micro discover</property>
+                                  </widget>
+                                  <packing>
+                                    <property name="position">7</property>
+                                    <property name="tab_fill">False</property>
+                                    <property name="type">tab</property>
+                                  </packing>
+                                </child>
                               </widget>
                               <packing>
                                 <property name="resize">True</property>
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 8e6a743fc..dc5e00de9 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -293,11 +293,18 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Button button_repair_selected_pulse;
 
        [Widget] Gtk.Box vbox_execute_test;
-       [Widget] Gtk.Button button_contacts_detect;
        [Widget] Gtk.Button button_execute_test;
        [Widget] Gtk.Viewport viewport_chronopics;
        [Widget] Gtk.Viewport viewport_chronopic_encoder;
 
+       //detect devices
+       [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.EventBox eventbox_button_micro_discover_close;
+
        [Widget] Gtk.Label label_threshold;
 
        //force sensor
@@ -495,6 +502,8 @@ public partial class ChronoJumpWindow
        ExecuteAutoWindow executeAutoWin;
 
        static Thread pingThread;
+       static Thread discoverThread;
+       static MicroDiscover microDiscover;
 
        private bool createdStatsWin;
        
@@ -502,7 +511,7 @@ public partial class ChronoJumpWindow
        private string progVersion;
        private string progName;
        private enum notebook_start_pages { PROGRAM, SENDLOG, EXITCONFIRM, SOCIALNETWORKPOLL }
-       private enum notebook_sup_pages { START, CONTACTS, ENCODER, SESSION, NETWORKSPROBLEMS, HELP, NEWS }
+       private enum notebook_sup_pages { START, CONTACTS, ENCODER, SESSION, NETWORKSPROBLEMS, HELP, NEWS, 
MICRODISCOVER }
        private enum notebook_contacts_execute_or_pages { EXECUTE, INSTRUCTIONS, FORCESENSORADJUST, 
RACEINSPECTOR }
        private enum notebook_analyze_pages { STATISTICS, JUMPSPROFILE, JUMPSDJOPTIMALFALL, 
JUMPSWEIGHTFVPROFILE, JUMPSEVOLUTION, JUMPSRJFATIGUE,
                RUNSEVOLUTION, SPRINT, FORCESENSOR, RACEENCODER }
@@ -660,6 +669,7 @@ public partial class ChronoJumpWindow
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_open_chronojump, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_help_close, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_news_close, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
+               UtilGtk.EventBoxColorBackgroundActive (eventbox_button_micro_discover_close, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_exit_cancel, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                UtilGtk.EventBoxColorBackgroundActive (eventbox_button_exit_confirm, UtilGtk.YELLOW, 
UtilGtk.YELLOW_LIGHT);
                app1s_eventboxes_paint();
@@ -926,6 +936,7 @@ public partial class ChronoJumpWindow
                {
                        UtilGtk.ContrastLabelsNotebook (Config.ColorBackgroundIsDark, app1s_notebook);
                        UtilGtk.ContrastLabelsVBox (Config.ColorBackgroundIsDark, vbox_help);
+                       UtilGtk.ContrastLabelsVBox (Config.ColorBackgroundIsDark, vbox_micro_discover);
                }
 
                LogB.Information(string.Format("UseSystemColor: {0}, ColorBackgroundIsDark: {1}", 
Config.UseSystemColor, Config.ColorBackgroundIsDark));
@@ -4537,8 +4548,12 @@ public partial class ChronoJumpWindow
                dialogThreshold.DestroyDialog();
        }
 
+       /*
+          ----------------- discover / detect devices --------->
+          */
+
        //right now implemented only contacts
-       void on_button_contacts_detect_clicked (object o, EventArgs args)
+       private void on_button_contacts_detect_clicked (object o, EventArgs args)
        {
                if(
                                current_mode != Constants.Modes.RUNSSIMPLE &&
@@ -4547,39 +4562,81 @@ public partial class ChronoJumpWindow
                                current_mode != Constants.Modes.RUNSENCODER)
                        return;
 
-               ChronoDebug cDebug = new ChronoDebug("Discover " + current_mode.ToString());
-               cDebug.Start();
+               // 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();
 
                List<string> list_discover_ports = Util.StringArrayToListString (ChronopicPorts.GetPorts ());
-               if(list_discover_ports == null || list_discover_ports.Count == 0)
-               {
-                       new DialogMessage( Constants.MessageTypes.INFO,
-                                       string.Format(Catalog.GetPluralString(
-                                               "Found 1 device.",
-                                               "Found {0} devices.",
-                                               0),
-                                       0) );
-                       return;
+               label_micro_discover_ports.Text = string.Format(Catalog.GetPluralString(
+                                       "Found 1 device.",
+                                       "Found {0} devices.",
+                                       list_discover_ports.Count), list_discover_ports.Count);
+
+               app1s_notebook_sup_entered_from = notebook_sup.CurrentPage; //CONTACTS or ENCODER
+               notebook_sup.CurrentPage = Convert.ToInt32(notebook_sup_pages.MICRODISCOVER);
+               menus_and_mode_sensitive (false);
+
+               if(list_discover_ports != null && list_discover_ports.Count > 0)
+               {
+                       microDiscover = new MicroDiscover (list_discover_ports); //all ports
+                       discoverThread = new Thread (new ThreadStart (discoverDo));
+                       GLib.Idle.Add (new GLib.IdleHandler (pulseDiscoverGTK));
+                       discoverThread.Start();
                }
 
-               MicroDiscover md = new MicroDiscover (list_discover_ports); //all ports
-               List<string> discovered_l = md.DiscoverOneMode (current_mode);
+               //cDebug.StopAndPrint();
+       }
 
-               cDebug.StopAndPrint();
+       private void discoverDo ()
+       {
+               List<string> discovered_l = microDiscover.DiscoverOneMode (current_mode);
 
                string discoveredStr = "Discovered: ";
                foreach (string str in discovered_l)
                        discoveredStr += "\n- " + str;
 
-               new DialogMessage( Constants.MessageTypes.INFO, discoveredStr +
-                               string.Format("\n{0} ms", cDebug.StartToEndInMs()) );
+               //new DialogMessage( Constants.MessageTypes.INFO, discoveredStr +
+               //              string.Format("\n{0} ms", cDebug.StartToEndInMs()) );
+       }
+       private bool pulseDiscoverGTK ()
+       {
+               progressbar_micro_discover_ports.Fraction = microDiscover.ProgressBarCurrentMicroValue;
+               progressbar_micro_discover_ports.Text = microDiscover.ProgressBarCurrentMicroText;
+               //progressbar_micro_discover_status.Fraction = microDiscover.ProgressBarStatusValue;
+               progressbar_micro_discover_status.Text = microDiscover.ProgressBarStatusText;
 
+               if(! discoverThread.IsAlive)
+               {
+                       // 3) end this pulse
+                       LogB.Information("pulseDiscoverGTK ending here");
+                       LogB.ThreadEnded();
 
-               button_contacts_detect.Visible = false;
-               button_execute_test.Visible = true;
+                       progressbar_micro_discover_status.Fraction = 1;
+                       return false;
+               }
+
+               progressbar_micro_discover_status.Pulse ();
+               Thread.Sleep (200);
+               return true;
        }
 
-       void on_button_execute_test_clicked (object o, EventArgs args) 
+       private void on_button_micro_discover_close_clicked (object o, EventArgs args)
+       {
+               notebook_sup.CurrentPage = app1s_notebook_sup_entered_from; //CONTACTS or ENCODER
+               menus_and_mode_sensitive (true);
+       }
+
+
+       /*
+          <---------------- end of discover / detect devices --------
+          */
+
+
+
+       private void on_button_execute_test_clicked (object o, EventArgs args)
        {
                if(current_mode == Constants.Modes.FORCESENSOR)
                {
diff --git a/src/gui/app1/icons.cs b/src/gui/app1/icons.cs
index 4c3412796..049fd6212 100644
--- a/src/gui/app1/icons.cs
+++ b/src/gui/app1/icons.cs
@@ -113,6 +113,7 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Label label_start_selector_encoder;
 
        [Widget] Gtk.Image image_button_help_close;
+       [Widget] Gtk.Image image_button_micro_discover_close;
 
        [Widget] Gtk.Image image_edit_selected_jump;
        [Widget] Gtk.Image image_edit_selected_jump_rj;
@@ -793,6 +794,7 @@ public partial class ChronoJumpWindow
                image_app1s_button_view_data_folder_close.Pixbuf = pixbuf;
                image_app1s_button_cancel1.Pixbuf = pixbuf;
                image_button_help_close.Pixbuf = pixbuf;
+               image_button_micro_discover_close.Pixbuf = pixbuf;
 
                //accept
                pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "image_done_blue.png");


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