[chronojump] safer showUpdateStatsAndHideData with new method: CanTouchGTK()



commit a0606233a00ae44b63aa8e0c9005ed44bfd9de11
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Jan 4 07:42:52 2017 +0100

    safer showUpdateStatsAndHideData with new method: CanTouchGTK()

 src/gui/stats.cs |   15 ++++++++++-----
 src/utilGtk.cs   |    5 +++++
 2 files changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/src/gui/stats.cs b/src/gui/stats.cs
index 9109698..a9ef8d3 100644
--- a/src/gui/stats.cs
+++ b/src/gui/stats.cs
@@ -546,11 +546,16 @@ public partial class ChronoJumpWindow {
                return Util.AddArrayString(comboCheckboxesOptionsWithoutPersons, 
Util.ArrayListToString(myStatType.PersonsWithData));
        }
 
-       private void showUpdateStatsAndHideData(bool show) {
-               button_stats.Sensitive = show;
-               treeview_stats.Sensitive = ! show;
-               hbox_mark_and_enunciate.Sensitive = ! show;
-               frame_graph_and_report.Sensitive = ! show;
+       private void showUpdateStatsAndHideData(bool show)
+       {
+               //as this is called by cancel and finish, check that we are on first thread to not have GTK 
problems
+               if(UtilGtk.CanTouchGTK())
+               {
+                       button_stats.Sensitive = show;
+                       treeview_stats.Sensitive = ! show;
+                       hbox_mark_and_enunciate.Sensitive = ! show;
+                       frame_graph_and_report.Sensitive = ! show;
+               }
        }
        
        private void updateComboStats() {
diff --git a/src/utilGtk.cs b/src/utilGtk.cs
index c61a4e6..8bb7d86 100644
--- a/src/utilGtk.cs
+++ b/src/utilGtk.cs
@@ -30,6 +30,11 @@ using Gdk;
 //only Gtk related methods (not used bu the server) this is the differnece with Util
 public class UtilGtk
 {
+       public static bool CanTouchGTK()
+       {
+               //Only first thread can touch GTK
+               return (System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() == "1");
+       }
 
        /*
         *


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