[chronojump] ForceSensorThread can be cancelled
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] ForceSensorThread can be cancelled
- Date: Thu, 4 Feb 2021 16:40:21 +0000 (UTC)
commit 43110d0b4d797d3a885343f27cf9087361a1f57e
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Feb 4 17:39:33 2021 +0100
ForceSensorThread can be cancelled
glade/app1.glade | 31 +++++++++++++++++++++++++++++++
src/forceSensor.cs | 31 ++++++++++++++++++++++++++-----
src/gui/app1/forceSensorAnalyze.cs | 10 ++++++++--
src/gui/app1/icons.cs | 2 ++
4 files changed, 67 insertions(+), 7 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index aea44098..aa0698f4 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -21826,12 +21826,43 @@ Concentric</property>
</packing>
</child>
<child>
+ <widget class="GtkHBox" id="hbox456">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
<widget class="GtkProgressBar"
id="progressbar_force_sensor_export">
<property name="width_request">50</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
</widget>
<packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkButton"
id="button_force_sensor_export_cancel">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked"
handler="on_button_force_sensor_export_cancel_clicked" swapped="no"/>
+ <child>
+ <widget class="GtkImage"
id="image_force_sensor_export_cancel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property
name="stock">gtk-missing-image</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
<property name="position">1</property>
</packing>
</child>
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index ba1d978e..ced426f6 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -2144,6 +2144,7 @@ public class ForceSensorExport
public string CSVExportDecimalSeparator;
private static Thread thread;
+ private static bool cancel;
private static double pulseFraction;
List<ForceSensor> fs_l;
@@ -2188,6 +2189,7 @@ public class ForceSensorExport
///public method
public void Start()
{
+ cancel = false;
pulseFraction= 0;
progressbar.Fraction = 0;
notebook.CurrentPage = 1;
@@ -2197,10 +2199,18 @@ public class ForceSensorExport
thread.Start();
}
+ public void Cancel()
+ {
+ cancel = true;
+ }
+
private bool pulseForceSensorExportGTK ()
{
- if(! thread.IsAlive)// || cancel)
+ if(! thread.IsAlive || cancel)
{
+ if(cancel)
+ LogB.Information("pulseForceSensorExportGTK cancelled");
+
LogB.Information("pulseForceSensorExportGTK ending here");
LogB.ThreadEnded();
@@ -2209,7 +2219,11 @@ public class ForceSensorExport
return false;
}
- progressbar.Fraction = pulseFraction;
+ if(pulseFraction == 0)
+ progressbar.Pulse();
+ else
+ progressbar.Fraction = pulseFraction;
+
Thread.Sleep (100);
//Log.Write(" (pulseForceSensorExportGTK:" + thread.ThreadState.ToString() + ") ");
return true;
@@ -2218,8 +2232,8 @@ public class ForceSensorExport
private void forceSensorExportDo()
{
getData();
- processForceSensorSets();
- writeFile();
+ if(processForceSensorSets()) //false if cancelled
+ writeFile();
}
private void getData ()
@@ -2230,7 +2244,7 @@ public class ForceSensorExport
exportedRFDs = new List<string>();
}
- private void processForceSensorSets ()
+ private bool processForceSensorSets ()
{
Person p = new Person();
PersonSession ps = new PersonSession();
@@ -2238,6 +2252,9 @@ public class ForceSensorExport
int count = 0;
foreach(ForceSensor fs in fs_l)
{
+ if(cancel)
+ return false;
+
// 1) checks
//check fs is ok
if(fs == null || ! Util.FileExists(fs.FullURL))
@@ -2316,6 +2333,9 @@ public class ForceSensorExport
foreach(ForceSensorRepetition rep in fsAI.ForceSensorRepetition_l)
{
+ if(cancel)
+ return false;
+
ForceSensorGraph fsg = new ForceSensorGraph(fs.CaptureOption, rfdList,
impulse,
duration, durationPercent,
title, exercise, fs.DateTimePublic, new TriggerList(),
@@ -2356,6 +2376,7 @@ public class ForceSensorExport
pulseFraction = UtilAll.DivideSafeFraction (count ++, fs_l.Count);
}
pulseFraction = 1;
+ return true;
}
private bool writeFile()
diff --git a/src/gui/app1/forceSensorAnalyze.cs b/src/gui/app1/forceSensorAnalyze.cs
index 748639eb..c81618ce 100644
--- a/src/gui/app1/forceSensorAnalyze.cs
+++ b/src/gui/app1/forceSensorAnalyze.cs
@@ -698,13 +698,14 @@ public partial class ChronoJumpWindow
button_force_sensor_export_session (-1);
}
+ ForceSensorExport forceSensorExport;
private void button_force_sensor_export_session (int personID)
{
int duration = -1;
if(radio_force_duration_seconds.Active)
duration = Convert.ToInt32(spin_force_duration_seconds.Value);
- ForceSensorExport fse = new ForceSensorExport (
+ forceSensorExport = new ForceSensorExport (
notebook_force_sensor_export,
progressbar_force_sensor_export,
UtilAll.IsWindows(), personID, currentSession.UniqueID,
@@ -717,7 +718,12 @@ public partial class ChronoJumpWindow
preferences.forceSensorStartEndOptimized,
preferences.CSVExportDecimalSeparator);
- fse.Start();
+ forceSensorExport.Start();
+ }
+
+ private void on_button_force_sensor_export_cancel_clicked (object o, EventArgs args)
+ {
+ forceSensorExport.Cancel();
}
private void forceSensorDoGraphAI(bool windowResizedAndZoom)
diff --git a/src/gui/app1/icons.cs b/src/gui/app1/icons.cs
index 8750fad5..1c3cce6e 100644
--- a/src/gui/app1/icons.cs
+++ b/src/gui/app1/icons.cs
@@ -182,6 +182,7 @@ public partial class ChronoJumpWindow
[Widget] Gtk.Image image_force_sensor_laterality_l;
[Widget] Gtk.Image image_force_sensor_export_currentperson_in_session;
[Widget] Gtk.Image image_force_sensor_export_all_persons_in_session;
+ [Widget] Gtk.Image image_force_sensor_export_cancel;
//race encoder
[Widget] Gtk.Image image_run_encoder_exercise_edit;
@@ -683,6 +684,7 @@ public partial class ChronoJumpWindow
pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "image_cancel.png");
image_encoder_analyze_cancel.Pixbuf = pixbuf;
+ image_force_sensor_export_cancel.Pixbuf = pixbuf;
//zoom icons, done like this because there's one zoom icon created ad-hoc,
//and is not nice that the other are different for an user theme change
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]