[chronojump] Fixed threading problem, and numpy.ndarray problem



commit c9e2d876ba1e128c2036e7eb27b1fb3a618797f1
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Apr 5 03:03:34 2012 +0800

    Fixed threading problem, and numpy.ndarray problem

 encoder/pyserial_pyper.py |    3 +-
 src/constants.cs          |    3 +-
 src/gui/chronojump.cs     |    4 +--
 src/gui/encoder.cs        |   57 +++++++++++++++++++++++---------------------
 4 files changed, 34 insertions(+), 33 deletions(-)
---
diff --git a/encoder/pyserial_pyper.py b/encoder/pyserial_pyper.py
index 61fcd0a..26c5984 100644
--- a/encoder/pyserial_pyper.py
+++ b/encoder/pyserial_pyper.py
@@ -231,12 +231,11 @@ def calculate_all_in_r(temp, top_values, bottom_values, direction_now, smoothing
 
 		if eccon == "ec" or direction_now == -1:
 			if height >= minHeight:
-				#print phaseCol + "%6i," % phaseRange + "%10.2f," % meanSpeed + "%9.2f," % maxSpeed + colorize(meanPowerF,colorPower,colorPower!=BLACK) + colorize(peakPowerF,colorPeakPower,colorPeakPower!=BLACK) + "%11i" % peakPowerT
 				print phaseCol + colorize(heightF,colorHeight,colorHeight!=BLACK) + colorize(meanSpeedF,colorMeanSpeed,colorMeanSpeed!=BLACK) + colorize(maxSpeedF,colorMaxSpeed,colorMaxSpeed!=BLACK) + colorize(meanPowerF,colorMeanPower,colorMeanPower!=BLACK) + colorize(peakPowerF,colorPeakPower,colorPeakPower!=BLACK) + "%11i" % peakPowerT
 				if play:
 					playsound(soundFile)
 			else:
-				print chr(27) + "[0;37m" + phase + chr(27) + "[0;47m" + "%6i," % height + chr(27)+"[0m" + chr(27) + "[0;37m" + meanSpeedF + "%9.2f," % maxSpeed + meanPowerF + "%10.2f," % peakPower + "%11i" % peakPowerT + chr(27)+"[0m"
+				print chr(27) + "[0;47m" + phase + "%6i," % height + " " + "Discarded" + chr(27)+"[0m"
 
 
 def calculate_range(temp_cumsum, top_values, bottom_values, direction_now):
diff --git a/src/constants.cs b/src/constants.cs
index 2472e89..b97168b 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -38,7 +38,8 @@ public class Constants
 		"Onkar Nath Mishra (http://www.logicbrick.com)\n" + Catalog.GetString("OpenCV Detection of knee angle."),
 		"Andoni Morales Alastruey (http://ylatuya.es)\n" + Catalog.GetString("Installation support: Autotools, packaging, bundle."), 
 		"Carlos J. Gil Bellosta (http://www.datanalytics.com)\n" + Catalog.GetString("Statistics support."),
-		"Teng Wei Hua (wadedang gmail com)\n" + Catalog.GetString("Translation of Firmware to C, and new firmware features. Encoder hardware layer.") 
+		"Teng Wei Hua (wadedang gmail com)\n" + Catalog.GetString("Translation of Firmware to C.") + "\n" +
+			Catalog.GetString("New firmware features.") + " " + Catalog.GetString("Encoder hardware layer.") 
 	};
 	public static string [] Documenters = {
 		"Xavier de Blas Foix (xaviblas gmail com)\n\n",
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 63dc59b..86d227a 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -5056,9 +5056,7 @@ Console.WriteLine("X");
 	}
 		
 	private void on_repetitive_conditions_closed(object o, EventArgs args) {
-		encoderDoGraph = false;
-		EncoderUpdateThings();
-		//don't need thread here, because is fast (there's no need to call R and graph)
+		encoderUpdateTreeView();
 	}
 
 
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 1ad7eab..9b777a6 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -63,12 +63,14 @@ public partial class ChronoJumpWindow
 
 	Thread encoderThread;
 
+	int image_encoder_width;
+	int image_encoder_height;
+
 	private string encoderAnalysis="powerBars";
-	static bool encoderDoGraph;
 	enum encoderModes { CAPTURE, ANALYZE }
 	
 
-	//TODO: add encoder info of wade on about
+	//TODO: check all repetitive conditions areok on pyserial and on treeview
 	//TODO: improve message if chronopic is not connected
 
 	//TODO: store encoder data: auto save, and show on a treeview. Put button to delete current (or should be called "last")
@@ -147,22 +149,16 @@ public partial class ChronoJumpWindow
 
 		Util.RunPythonEncoder(Constants.EncoderScriptCapture, es, true);
 
-		encoderDoGraph = true;
 		encoderThreadStart(encoderModes.CAPTURE);
 	}
 		
 	void on_button_encoder_recalculate_clicked (object o, EventArgs args) 
 	{
-		encoderDoGraph = true;
 		encoderThreadStart(encoderModes.CAPTURE);
 	}
 	
-	//private void EncoderUpdateThings(bool graph) 
-	private void EncoderUpdateThings() 
+	private void encoderUpdateTreeView()
 	{
-		if(encoderDoGraph)
-			makeCurvesGraph();
-		
 		string contents = Util.ReadFile(Util.GetEncoderCurvesTempFileName());
 		if (contents == null) {
 			//TODO: no data: make some of the gui unsensitive ??
@@ -182,12 +178,9 @@ public partial class ChronoJumpWindow
 	}
 
 
-	private void makeCurvesGraph() 
+	//this is called by non gtk thread. Don't do gtk stuff here
+	private void encoderCreateCurvesGraphR() 
 	{
-	      	//show curves graph
-		int w = UtilGtk.WidgetWidth(viewport_image_encoder_capture)-3; //image is inside (is smaller than) viewport
-		int h = UtilGtk.WidgetHeight(viewport_image_encoder_capture)-3;
-
 		EncoderParams ep = new EncoderParams(
 				(int) spin_encoder_capture_min_height.Value, 
 				!radiobutton_encoder_capture_bar.Active,
@@ -195,7 +188,7 @@ public partial class ChronoJumpWindow
 				findEccon(), "curves",
 				Util.ConvertToPoint((double) spin_encoder_smooth.Value), //R decimal: '.'
 			       	0, 			//curve is not used here
-				w, h); 
+				image_encoder_width, image_encoder_height); 
 
 		EncoderStruct es = new EncoderStruct(
 				Util.GetEncoderDataTempFileName(), 
@@ -204,10 +197,8 @@ public partial class ChronoJumpWindow
 				"NULL", ep);
 		
 		Util.RunPythonEncoder(Constants.EncoderScriptGraphCall, es,false);
-
-		Pixbuf pixbuf = new Pixbuf (Util.GetEncoderGraphTempFileName()); //from a file
-		image_encoder_capture.Pixbuf = pixbuf;
 	}
+		
 
 	void on_button_encoder_save_clicked (object o, EventArgs args) 
 	{
@@ -223,18 +214,17 @@ public partial class ChronoJumpWindow
 		encoderThreadStart(encoderModes.ANALYZE);
 	}
 	
+	//this is called by non gtk thread. Don't do gtk stuff here
 	private void analyze () 
 	{
-		int w = UtilGtk.WidgetWidth(viewport_image_encoder_analyze)-3; //image is inside (is smaller than) viewport
-		int h = UtilGtk.WidgetHeight(viewport_image_encoder_analyze)-3;
-
 		EncoderParams ep = new EncoderParams(
 				(int) spin_encoder_capture_min_height.Value, 
 				!radiobutton_encoder_capture_bar.Active,
 				findMass(),
 				findEccon(), encoderAnalysis,
 				Util.ConvertToPoint((double) spin_encoder_smooth.Value), //R decimal: '.'
-				(int) spin_encoder_analyze_curve_num.Value, w, h);
+				(int) spin_encoder_analyze_curve_num.Value, 
+				image_encoder_width, image_encoder_height); 
 
 		EncoderStruct es = new EncoderStruct(
 				Util.GetEncoderDataTempFileName(), 
@@ -242,10 +232,6 @@ public partial class ChronoJumpWindow
 				"NULL", "NULL", ep);		//no data ouptut
 
 		Util.RunPythonEncoder(Constants.EncoderScriptGraphCall, es, false);
-
-		//TODO pensar en si s'ha de fer 1er amb mida petita i despres amb gran (en el zoom), o si es una sola i fa alguna edicio
-		Pixbuf pixbuf = new Pixbuf (Util.GetEncoderGraphTempFileName()); //from a file
-		image_encoder_analyze.Pixbuf = pixbuf;
 	}
 
 //TODO: auto close capturing window
@@ -505,11 +491,19 @@ public partial class ChronoJumpWindow
 
 	private void encoderThreadStart(encoderModes mode) {
 		if(mode == encoderModes.CAPTURE) {
+			//image is inside (is smaller than) viewport
+			image_encoder_width = UtilGtk.WidgetWidth(viewport_image_encoder_capture)-3; 
+			image_encoder_height = UtilGtk.WidgetHeight(viewport_image_encoder_capture)-3;
+
 			encoder_pulsebar_capture.Text = "Please, wait.";
 			treeview_encoder_curves.Sensitive = false;
-			encoderThread = new Thread(new ThreadStart(EncoderUpdateThings));
+			encoderThread = new Thread(new ThreadStart(encoderCreateCurvesGraphR));
 			GLib.Idle.Add (new GLib.IdleHandler (pulseGTKEncoderCapture));
 		} else {
+			//the -3 is because image is inside (is smaller than) viewport
+			image_encoder_width = UtilGtk.WidgetWidth(viewport_image_encoder_analyze)-3; 
+			image_encoder_height = UtilGtk.WidgetHeight(viewport_image_encoder_analyze)-3;
+
 			encoder_pulsebar_analyze.Text = "Please, wait.";
 			encoderThread = new Thread(new ThreadStart(analyze));
 			GLib.Idle.Add (new GLib.IdleHandler (pulseGTKEncoderAnalyze));
@@ -555,9 +549,18 @@ public partial class ChronoJumpWindow
 			encoder_pulsebar_capture.Fraction = 1;
 			encoder_pulsebar_capture.Text = "";
 			treeview_encoder_curves.Sensitive = true;
+			
+			Pixbuf pixbuf = new Pixbuf (Util.GetEncoderGraphTempFileName()); //from a file
+			image_encoder_capture.Pixbuf = pixbuf;
+
+			encoderUpdateTreeView();
 		} else {
 			encoder_pulsebar_analyze.Fraction = 1;
 			encoder_pulsebar_analyze.Text = "";
+			
+			//TODO pensar en si s'ha de fer 1er amb mida petita i despres amb gran (en el zoom), o si es una sola i fa alguna edicio
+			Pixbuf pixbuf = new Pixbuf (Util.GetEncoderGraphTempFileName()); //from a file
+			image_encoder_analyze.Pixbuf = pixbuf;
 		}
 	}
 	



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