[chronojump] Fixed multiple calls on menuitem_modes and stats. Safer change_multitest_firmware



commit 2c858f2f21282e7b1f8c8d91c9ce9e0c9cc63d87
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Jan 8 13:18:43 2015 +0100

    Fixed multiple calls on menuitem_modes and stats. Safer change_multitest_firmware

 glade/chronojump.glade |   65 +++++++++++++++++++++++++++++++--
 src/gui/chronojump.cs  |   95 +++++++++++++++++++++++++++++++++++-------------
 src/gui/stats.cs       |   27 ++++++++++++--
 3 files changed, 154 insertions(+), 33 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index be8e9c4..2a07059 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -241,7 +241,7 @@
                         <property name="label" translatable="yes">Jumps</property>
                         <property name="use_underline">True</property>
                         <property name="draw_as_radio">True</property>
-                        <signal name="toggled" handler="on_radio_menuitem_mode_toggled" swapped="no"/>
+                        <signal name="activate" handler="on_radio_menuitem_mode_activate" swapped="no"/>
                       </widget>
                     </child>
                     <child>
@@ -252,7 +252,7 @@
                         <property name="use_underline">True</property>
                         <property name="draw_as_radio">True</property>
                         <property name="group">radio_menuitem_mode_jumps</property>
-                        <signal name="toggled" handler="on_radio_menuitem_mode_toggled" swapped="no"/>
+                        <signal name="activate" handler="on_radio_menuitem_mode_activate" swapped="no"/>
                       </widget>
                     </child>
                     <child>
@@ -263,7 +263,7 @@
                         <property name="use_underline">True</property>
                         <property name="draw_as_radio">True</property>
                         <property name="group">radio_menuitem_mode_jumps</property>
-                        <signal name="toggled" handler="on_radio_menuitem_mode_toggled" swapped="no"/>
+                        <signal name="activate" handler="on_radio_menuitem_mode_activate" swapped="no"/>
                       </widget>
                     </child>
                     <child>
@@ -274,7 +274,7 @@
                         <property name="use_underline">True</property>
                         <property name="draw_as_radio">True</property>
                         <property name="group">radio_menuitem_mode_jumps</property>
-                        <signal name="toggled" handler="on_radio_menuitem_mode_toggled" swapped="no"/>
+                        <signal name="activate" handler="on_radio_menuitem_mode_activate" swapped="no"/>
                       </widget>
                     </child>
                     <child>
@@ -6381,6 +6381,9 @@ Second Chronopic to platforms.</property>
                                                         <child>
                                                           <placeholder/>
                                                         </child>
+                                                        <child>
+                                                          <placeholder/>
+                                                        </child>
                                                       </widget>
                                                       <packing>
                                                         <property name="expand">True</property>
@@ -7138,6 +7141,9 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             </child>
                                                             <child>
@@ -8147,6 +8153,9 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">2</property>
@@ -8797,6 +8806,9 @@ Second Chronopic to platforms.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">4</property>
@@ -18977,6 +18989,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -19535,6 +19550,9 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -20585,6 +20603,9 @@ by you</property>
               <placeholder/>
             </child>
             <child>
+              <placeholder/>
+            </child>
+            <child>
               <widget class="GtkButton" id="button_video_url">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -20692,6 +20713,9 @@ by you</property>
             <child>
               <placeholder/>
             </child>
+            <child>
+              <placeholder/>
+            </child>
           </widget>
           <packing>
             <property name="expand">True</property>
@@ -29728,6 +29752,24 @@ options</property>
                             <child>
                               <placeholder/>
                             </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
                           </widget>
                         </child>
                       </widget>
@@ -31666,6 +31708,9 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                                 <child>
                                   <placeholder/>
                                 </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
                               </widget>
                             </child>
                           </widget>
@@ -32262,6 +32307,9 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -34824,6 +34872,9 @@ show elevation as:</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                       <packing>
                         <property name="left_attach">2</property>
@@ -35046,6 +35097,9 @@ show elevation as:</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -35283,6 +35337,9 @@ show elevation as:</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index a07cec9..93dbc66 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -32,6 +32,7 @@ using LongoMatch.Gui;
 using LongoMatch.Video.Capturer;
 using LongoMatch.Video.Common;
 using LongoMatch.Video.Utils;
+//using System.Diagnostics;
 
 public partial class ChronoJumpWindow 
 {
@@ -2841,6 +2842,8 @@ public partial class ChronoJumpWindow
                menuitem_mode_selected_runs.Visible = false;
                menuitem_mode_selected_power.Visible = false;
                menuitem_mode_selected_other.Visible = false;
+                       
+               LogB.Information("MODE", m.ToString());
 
                if(m == menuitem_modes.JUMPS) {
                        notebook_sup.CurrentPage = 0;
@@ -2873,7 +2876,9 @@ public partial class ChronoJumpWindow
        }
 
        //change debounce time automatically on change menuitem mode (if multitest firmware)
-       private void change_multitest_firmware(menuitem_modes m) {
+       private void change_multitest_firmware(menuitem_modes m) 
+       {
+               LogB.Information("change_multitest_firmware");
                label_chronopics_multitest.Text = "";
                
                if(! chronopicWin.Connected)
@@ -2922,8 +2927,24 @@ public partial class ChronoJumpWindow
                                ca.Write(chronopicWin.SP, debounceChange);
                                
                                //read if ok
-                               ca = new ChronopicAutoCheckDebounce();
-                               string ms = ca.Read(chronopicWin.SP);
+                               string ms = "";
+                               bool success = false;
+                               int tryNum = 7; //try to connect seven times
+                               do {
+                                       ca = new ChronopicAutoCheckDebounce();
+                                       ms = ca.Read(chronopicWin.SP);
+
+                                       if(ms.Length == 0)
+                                               LogB.Error("multitest firmware. ms is null");
+                                       else if(ms[0] == '-') //is negative
+                                               LogB.Error("multitest firmware. ms = " + ms);
+                                       else
+                                               success = true;
+                                       tryNum --;
+                               } while (! success && tryNum > 0);
+                                       
+                               LogB.Debug("multitest firmware. ms = " + ms);
+
                                if(ms == "50 ms")
                                        label_chronopics_multitest.Text = "[" + Catalog.GetString("Jumps") + 
"]";
                                else if(ms == "10 ms")
@@ -2934,37 +2955,57 @@ public partial class ChronoJumpWindow
                }
        }
 
-       private void on_radio_menuitem_mode_toggled(object o, EventArgs args) 
+       private menuitem_modes getMenuItemMode() 
        {
-               menuitem_modes m;
                if(radio_menuitem_mode_jumps.Active)
-                       m = menuitem_modes.JUMPS;
+                       return menuitem_modes.JUMPS;
                else if(radio_menuitem_mode_runs.Active)
-                       m = menuitem_modes.RUNS;
+                       return menuitem_modes.RUNS;
                else if(radio_menuitem_mode_power.Active)
-                       m = menuitem_modes.POWER;
+                       return menuitem_modes.POWER;
                else // if(radio_menuitem_mode_other.Active)
-                       m = menuitem_modes.OTHER;
-
-               select_menuitem_mode_toggled(m);
+                       return menuitem_modes.OTHER;
        }
-       private void on_button_selector_start_jumps_clicked(object o, EventArgs args) {
-               radio_menuitem_mode_jumps.Active = true;
+
+       private void on_radio_menuitem_mode_activate(object o, EventArgs args) 
+       {
+               //togglebutton sends signal two times (deactivate/activate), just get the good signal
+               //http://stackoverflow.com/questions/10755541/mono-gtk-radiobutton-clicked-event-firing-twice
+               if( ! (o as Gtk.RadioMenuItem).Active )
+                       return;
                
-               //needed if people select again the same option
-               on_radio_menuitem_mode_toggled(o, args); 
+               select_menuitem_mode_toggled(getMenuItemMode());
+       }
+
+       private void on_button_selector_start_jumps_clicked(object o, EventArgs args) 
+       {
+               if(radio_menuitem_mode_jumps.Active) {
+                       //needed if people select again the same option
+                       select_menuitem_mode_toggled(menuitem_modes.JUMPS); 
+               }
+               else
+                       radio_menuitem_mode_jumps.Active = true;
        }
-       private void on_button_selector_start_runs_clicked(object o, EventArgs args) {
-               radio_menuitem_mode_runs.Active = true;
-               on_radio_menuitem_mode_toggled(o, args); 
+       private void on_button_selector_start_runs_clicked(object o, EventArgs args) 
+       {
+               if(radio_menuitem_mode_runs.Active)
+                       select_menuitem_mode_toggled(menuitem_modes.RUNS);
+               else
+                       radio_menuitem_mode_runs.Active = true;
        }
-       private void on_button_selector_start_power_clicked(object o, EventArgs args) {
-               radio_menuitem_mode_power.Active = true;
-               on_radio_menuitem_mode_toggled(o, args); 
+       private void on_button_selector_start_power_clicked(object o, EventArgs args) 
+       {
+               if(radio_menuitem_mode_power.Active)
+                       select_menuitem_mode_toggled(menuitem_modes.POWER);
+               else
+                       radio_menuitem_mode_power.Active = true;
        }
-       private void on_button_selector_start_other_clicked(object o, EventArgs args) {
-               radio_menuitem_mode_other.Active = true;
-               on_radio_menuitem_mode_toggled(o, args); 
+       private void on_button_selector_start_other_clicked(object o, EventArgs args) 
+       {
+               if(radio_menuitem_mode_other.Active)
+                       select_menuitem_mode_toggled(menuitem_modes.OTHER);
+               else
+                       radio_menuitem_mode_other.Active = true;
        }
        
        /*
@@ -4430,9 +4471,8 @@ public partial class ChronoJumpWindow
                if(radio_mode_multi_chronopic_small.Active)     
                        on_extra_window_multichronopic_test_changed(new object(), new EventArgs());
                
-               //this performs a: change_multitest_firmware(m);
                if(cps > 0)
-                       on_radio_menuitem_mode_toggled(new object(), new EventArgs ());
+                       change_multitest_firmware(getMenuItemMode());
                else 
                        label_chronopics_multitest.Text = "";
                
@@ -5740,6 +5780,9 @@ LogB.Debug("X");
        
        //changed by chronojump when it's needed
        private void notebooks_change(int desiredPage) {
+               LogB.Information("notebooks_change");
+               //LogB.Debug(new StackFrame(1).GetMethod().Name);
+
                while(notebook_execute.CurrentPage < desiredPage) 
                        notebook_execute.NextPage();
                while(notebook_execute.CurrentPage > desiredPage) 
diff --git a/src/gui/stats.cs b/src/gui/stats.cs
index 1d5a1fb..d510a59 100644
--- a/src/gui/stats.cs
+++ b/src/gui/stats.cs
@@ -15,7 +15,7 @@
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
- * Copyright (C) 2004-2014   Xavier de Blas <xaviblas gmail com> 
+ * Copyright (C) 2004-2015   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -148,6 +148,8 @@ public partial class ChronoJumpWindow {
                else {
                        notebook_stats_sup.CurrentPage = 0;
 
+                       combo_stats_stat_type.Changed -= new EventHandler (on_combo_stats_stat_type_changed);
+
                        bool sensitive = false;
                        bool showType = false;
                        if(testPage == 0) {
@@ -165,6 +167,8 @@ public partial class ChronoJumpWindow {
                                UtilGtk.ComboUpdate(combo_stats_stat_type, comboStatsTypeOptions[3]);
                        else if(testPage == 3)
                                UtilGtk.ComboUpdate(combo_stats_stat_type, comboStatsTypeOptions[4]);
+                       
+                       combo_stats_stat_type.Changed += new EventHandler (on_combo_stats_stat_type_changed);
 
                        combo_stats_stat_type.Active = 0;
                        combo_stats_stat_type.Sensitive = sensitive;
@@ -558,6 +562,7 @@ public partial class ChronoJumpWindow {
        
        private void updateComboStats() {
                string [] nullOptions = { "-" };
+               
                if(UtilGtk.ComboGetActive(combo_stats_stat_type) == Constants.TypeSessionSummary ) 
                {
                        UtilGtk.ComboUpdate(combo_stats_stat_subtype, nullOptions, "");
@@ -583,7 +588,10 @@ public partial class ChronoJumpWindow {
                } 
                else if (UtilGtk.ComboGetActive(combo_stats_stat_type) == Constants.TypeJumpsSimple ) 
                {
+                       combo_stats_stat_subtype.Changed -= new EventHandler 
(on_combo_stats_stat_subtype_changed);
                        UtilGtk.ComboUpdate(combo_stats_stat_subtype, comboStatsSubTypeSimpleOptions, "");
+                       combo_stats_stat_subtype.Changed += new EventHandler 
(on_combo_stats_stat_subtype_changed);
+
                        combo_stats_stat_subtype.Sensitive = true;
                        combo_stats_stat_subtype.Active = 0;
                        
@@ -596,7 +604,10 @@ public partial class ChronoJumpWindow {
                } 
                else if (UtilGtk.ComboGetActive(combo_stats_stat_type) == Constants.TypeJumpsSimpleWithTC ) 
                {
+                       combo_stats_stat_subtype.Changed -= new EventHandler 
(on_combo_stats_stat_subtype_changed);
                        UtilGtk.ComboUpdate(combo_stats_stat_subtype, comboStatsSubTypeWithTCOptions, "");
+                       combo_stats_stat_subtype.Changed += new EventHandler 
(on_combo_stats_stat_subtype_changed);
+
                        combo_stats_stat_subtype.Sensitive = true;
                        combo_stats_stat_subtype.Active = 0;
                        
@@ -607,7 +618,10 @@ public partial class ChronoJumpWindow {
                } 
                else if (UtilGtk.ComboGetActive(combo_stats_stat_type) == Constants.TypeJumpsReactive ) 
                {
+                       combo_stats_stat_subtype.Changed -= new EventHandler 
(on_combo_stats_stat_subtype_changed);
                        UtilGtk.ComboUpdate(combo_stats_stat_subtype, comboStatsSubTypeReactiveOptions, "");
+                       combo_stats_stat_subtype.Changed += new EventHandler 
(on_combo_stats_stat_subtype_changed);
+                       
                        combo_stats_stat_subtype.Sensitive = true;
                        combo_stats_stat_subtype.Active = 0;
                        
@@ -618,7 +632,10 @@ public partial class ChronoJumpWindow {
                }
                else if (UtilGtk.ComboGetActive(combo_stats_stat_type) == Constants.TypeRunsSimple ) 
                {
+                       combo_stats_stat_subtype.Changed -= new EventHandler 
(on_combo_stats_stat_subtype_changed);
                        UtilGtk.ComboUpdate(combo_stats_stat_subtype, comboStatsSubTypeSimpleOptions, "");
+                       combo_stats_stat_subtype.Changed += new EventHandler 
(on_combo_stats_stat_subtype_changed);
+                       
                        combo_stats_stat_subtype.Sensitive = false;
                        combo_stats_stat_subtype.Active = 0;
                        
@@ -629,7 +646,10 @@ public partial class ChronoJumpWindow {
                } 
                else if (UtilGtk.ComboGetActive(combo_stats_stat_type) == Constants.TypeRunsIntervallic ) 
                {
+                       combo_stats_stat_subtype.Changed -= new EventHandler 
(on_combo_stats_stat_subtype_changed);
                        UtilGtk.ComboUpdate(combo_stats_stat_subtype, comboStatsSubTypeSimpleOptions, "");
+                       combo_stats_stat_subtype.Changed += new EventHandler 
(on_combo_stats_stat_subtype_changed);
+                       
                        combo_stats_stat_subtype.Sensitive = false;
                        combo_stats_stat_subtype.Active = 0;
                        
@@ -716,7 +736,8 @@ public partial class ChronoJumpWindow {
                                                        "CMJ"); //default value
                                combo_stats_stat_apply_to.Sensitive = false;
                        }
-               }  else if (UtilGtk.ComboGetActive(combo_stats_stat_type) == Constants.TypeJumpsSimpleWithTC 
) 
+               }  
+               else if (UtilGtk.ComboGetActive(combo_stats_stat_type) == Constants.TypeJumpsSimpleWithTC ) 
                {
                        UtilGtk.ComboUpdate(combo_stats_stat_apply_to, 
                                SqliteJumpType.SelectJumpTypes(false, Constants.AllJumpsName, "TC", true), 
""); //only select name
@@ -1130,7 +1151,7 @@ public partial class ChronoJumpWindow {
 
        private void on_combo_stats_stat_type_changed(object o, EventArgs args) {
                //update combo stats_subtype, there change the treeviewstats (with the combostats_subtype 
values changed)
-               
+       
                updateComboStats();
                
                update_stats_widgets_sensitiveness();


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