[chronojump] Encoder threads done
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Encoder threads done
- Date: Wed, 4 Apr 2012 19:04:49 +0000 (UTC)
commit dfcb69ba0a68a292528ad66612219dde1a017552
Author: Xavier de Blas <xaviblas gmail com>
Date: Wed Apr 4 22:35:07 2012 +0800
Encoder threads done
glade/chronojump.glade | 166 +++++++++++++++++++++++++++++++++++-------------
src/gui/chronojump.cs | 9 ++-
src/gui/encoder.cs | 107 +++++++++++++++++++++++++++----
3 files changed, 222 insertions(+), 60 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index e9897d3..3e1c346 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -23674,44 +23674,103 @@ on current Chronojump version.</property>
</packing>
</child>
<child>
- <widget class="GtkHButtonBox" id="hbuttonbox9">
+ <widget class="GtkHBox" id="hbox73">
<property name="visible">True</property>
- <property name="layout_style">spread</property>
+ <property name="spacing">10</property>
<child>
- <widget class="GtkButton" id="button_encoder_capture">
- <property name="label" translatable="yes">Capture from encoder</property>
+ <widget class="GtkHButtonBox" id="hbuttonbox9">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="receives_default">True</property>
- <property name="use_underline">True</property>
- <signal name="clicked" handler="on_button_encoder_capture_clicked"/>
+ <property name="layout_style">spread</property>
+ <child>
+ <widget class="GtkButton" id="button_encoder_capture">
+ <property name="label" translatable="yes">Capture from encoder</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="on_button_encoder_capture_clicked"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkButton" id="button_encoder_recalculate">
+ <property name="label" translatable="yes">Recalculate</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="on_button_encoder_recalculate_clicked"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</widget>
<packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
- <widget class="GtkButton" id="button_encoder_recalculate">
- <property name="label" translatable="yes">Recalculate</property>
+ <widget class="GtkProgressBar" id="encoder_pulsebar_capture">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="receives_default">True</property>
- <property name="use_underline">True</property>
- <signal name="clicked" handler="on_button_encoder_recalculate_clicked"/>
+ <property name="activity_mode">True</property>
+ <property name="show_text">True</property>
+ <property name="pulse_step">0.10000000149</property>
</widget>
<packing>
- <property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <widget class="GtkHButtonBox" id="hbuttonbox10">
+ <property name="visible">True</property>
+ <property name="layout_style">spread</property>
+ <child>
+ <widget class="GtkButton" id="button_encoder_save">
+ <property name="label">gtk-save</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ <signal name="clicked" handler="on_button_encoder_save_clicked"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkButton" id="button_encoder_load">
+ <property name="label">gtk-open</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ <signal name="clicked" handler="on_button_encoder_load_clicked"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">2</property>
+ </packing>
+ </child>
</widget>
<packing>
- <property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
@@ -23992,31 +24051,6 @@ on current Chronojump version.</property>
<property name="position">2</property>
</packing>
</child>
- <child>
- <widget class="GtkHBox" id="hbox80">
- <property name="visible">True</property>
- <child>
- <widget class="GtkButton" id="button_encoder_analyze">
- <property name="label" translatable="yes">Analyze</property>
- <property name="visible">True</property>
- <property name="sensitive">False</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="receives_default">True</property>
- <property name="use_underline">True</property>
- <signal name="clicked" handler="on_button_encoder_analyze_clicked"/>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="padding">12</property>
- <property name="position">0</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="position">3</property>
- </packing>
- </child>
</widget>
</child>
</widget>
@@ -24038,6 +24072,48 @@ on current Chronojump version.</property>
<property name="position">0</property>
</packing>
</child>
+ <child>
+ <widget class="GtkHBox" id="hbox75">
+ <property name="visible">True</property>
+ <property name="homogeneous">True</property>
+ <child>
+ <widget class="GtkButton" id="button_encoder_analyze">
+ <property name="label" translatable="yes">Analyze</property>
+ <property name="width_request">150</property>
+ <property name="visible">True</property>
+ <property name="sensitive">False</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="on_button_encoder_analyze_clicked"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">12</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkProgressBar" id="encoder_pulsebar_analyze">
+ <property name="width_request">150</property>
+ <property name="visible">True</property>
+ <property name="activity_mode">True</property>
+ <property name="show_text">True</property>
+ <property name="pulse_step">0.10000000149</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index f8992e9..63dc59b 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -497,6 +497,11 @@ public partial class ChronoJumpWindow
stats_win_create();
createdStatsWin = true;
//stats_win_initializeSession();
+
+ encoder_pulsebar_capture.Fraction = 1;
+ encoder_pulsebar_capture.Text = "";
+ encoder_pulsebar_analyze.Fraction = 1;
+ encoder_pulsebar_analyze.Text = "";
}
@@ -5051,7 +5056,9 @@ Console.WriteLine("X");
}
private void on_repetitive_conditions_closed(object o, EventArgs args) {
- EncoderUpdateThings(false);
+ encoderDoGraph = false;
+ EncoderUpdateThings();
+ //don't need thread here, because is fast (there's no need to call R and graph)
}
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 04e9c9d..8fdae14 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -24,6 +24,7 @@ using Gtk;
using Gdk;
using Glade;
using System.Collections;
+using System.Threading;
public partial class ChronoJumpWindow
@@ -42,6 +43,7 @@ public partial class ChronoJumpWindow
[Widget] Gtk.SpinButton spin_encoder_capture_min_height;
[Widget] Gtk.Image image_encoder_capture;
[Widget] Gtk.TreeView treeview_encoder_curves;
+ [Widget] Gtk.ProgressBar encoder_pulsebar_capture;
[Widget] Gtk.Button button_encoder_analyze;
[Widget] Gtk.RadioButton radiobutton_encoder_analyze_powerbars;
@@ -52,18 +54,22 @@ public partial class ChronoJumpWindow
[Widget] Gtk.SpinButton spin_encoder_analyze_curve_num;
[Widget] Gtk.Viewport viewport_image_encoder_analyze;
[Widget] Gtk.Image image_encoder_analyze;
+ [Widget] Gtk.ProgressBar encoder_pulsebar_analyze;
TreeStore encoderStore;
ArrayList encoderCurves;
Gtk.ListStore encoderListStore;
+ Thread encoderThread;
private string encoderAnalysis="powerBars";
+ static bool encoderDoGraph;
+ enum encoderModes { CAPTURE, ANALYZE }
+
//TODO: add encoder info of wade on about
//TODO: improve message if chronopic is not connected
- //TODO: campanes a l'encoder pq mostri colors i sons en funcio del que passa. Falten els sons des de python
//TODO: store encoder data: auto save, and show on a treeview. Put button to delete current (or should be called "last")
@@ -72,11 +78,11 @@ public partial class ChronoJumpWindow
//TODO: in ec, curves and powerBars have to be different on ec than on c
- public void on_radiobutton_encoder_capture_bar_toggled (object obj, EventArgs args) {
+ private void on_radiobutton_encoder_capture_bar_toggled (object obj, EventArgs args) {
spin_encoder_bar_limit.Sensitive = true;
spin_encoder_jump_limit.Sensitive = false;
}
- public void on_radiobutton_encoder_capture_jump_toggled (object obj, EventArgs args) {
+ private void on_radiobutton_encoder_capture_jump_toggled (object obj, EventArgs args) {
spin_encoder_bar_limit.Sensitive = false;
spin_encoder_jump_limit.Sensitive = true;
}
@@ -120,17 +126,20 @@ public partial class ChronoJumpWindow
Util.RunPythonEncoder(Constants.EncoderScriptCapture, es, true);
- EncoderUpdateThings(true);
+ encoderDoGraph = true;
+ encoderThreadStart(encoderModes.CAPTURE);
}
void on_button_encoder_recalculate_clicked (object o, EventArgs args)
{
- EncoderUpdateThings(true);
+ encoderDoGraph = true;
+ encoderThreadStart(encoderModes.CAPTURE);
}
- private void EncoderUpdateThings(bool graph)
+ //private void EncoderUpdateThings(bool graph)
+ private void EncoderUpdateThings()
{
- if(graph)
+ if(encoderDoGraph)
makeCurvesGraph();
string contents = Util.ReadFile(Util.GetEncoderCurvesTempFileName());
@@ -179,10 +188,22 @@ public partial class ChronoJumpWindow
image_encoder_capture.Pixbuf = pixbuf;
}
+ void on_button_encoder_save_clicked (object o, EventArgs args)
+ {
+ }
+ void on_button_encoder_load_clicked (object o, EventArgs args)
+ {
+ }
+
//TODO: garantir path windows
private void on_button_encoder_analyze_clicked (object o, EventArgs args)
{
+ encoderThreadStart(encoderModes.ANALYZE);
+ }
+
+ 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;
@@ -209,23 +230,23 @@ public partial class ChronoJumpWindow
//TODO: auto close capturing window
//show curve_num only on simple and superpose
- public void on_radiobutton_encoder_analyze_single_toggled (object obj, EventArgs args) {
+ private void on_radiobutton_encoder_analyze_single_toggled (object obj, EventArgs args) {
label_encoder_analyze_curve_num.Sensitive=true;
spin_encoder_analyze_curve_num.Sensitive=true;
encoderAnalysis="single";
}
- public void on_radiobutton_encoder_analyze_superpose_toggled (object obj, EventArgs args) {
+ private void on_radiobutton_encoder_analyze_superpose_toggled (object obj, EventArgs args) {
label_encoder_analyze_curve_num.Sensitive=true;
spin_encoder_analyze_curve_num.Sensitive=true;
encoderAnalysis="superpose";
}
- public void on_radiobutton_encoder_analyze_side_toggled (object obj, EventArgs args) {
+ private void on_radiobutton_encoder_analyze_side_toggled (object obj, EventArgs args) {
label_encoder_analyze_curve_num.Sensitive=false;
spin_encoder_analyze_curve_num.Sensitive=false;
encoderAnalysis="side";
}
- public void on_radiobutton_encoder_analyze_powerbars_toggled (object obj, EventArgs args) {
+ private void on_radiobutton_encoder_analyze_powerbars_toggled (object obj, EventArgs args) {
label_encoder_analyze_curve_num.Sensitive=false;
spin_encoder_analyze_curve_num.Sensitive=false;
encoderAnalysis="powerBars";
@@ -424,8 +445,6 @@ public partial class ChronoJumpWindow
}
/* end of rendering cols */
-
-
private string [] fixDecimals(string [] cells) {
@@ -436,9 +455,69 @@ public partial class ChronoJumpWindow
return cells;
}
-
/* end of TreeView stuff */
+ /* thread stuff */
+
+ private void encoderThreadStart(encoderModes mode) {
+ if(mode == encoderModes.CAPTURE) {
+ encoder_pulsebar_capture.Text = "Please, wait.";
+ treeview_encoder_curves.Sensitive = false;
+ encoderThread = new Thread(new ThreadStart(EncoderUpdateThings));
+ GLib.Idle.Add (new GLib.IdleHandler (pulseGTKEncoderCapture));
+ } else {
+ encoder_pulsebar_analyze.Text = "Please, wait.";
+ encoderThread = new Thread(new ThreadStart(analyze));
+ GLib.Idle.Add (new GLib.IdleHandler (pulseGTKEncoderAnalyze));
+ }
+ encoderThread.Start();
+ }
+
+ private bool pulseGTKEncoderCapture ()
+ {
+ if(! encoderThread.IsAlive) {
+ finishPulsebar(encoderModes.CAPTURE);
+ Log.Write("dying");
+ return false;
+ }
+ updatePulsebar(encoderModes.CAPTURE); //activity on pulsebar
+ Thread.Sleep (50);
+ Log.Write(encoderThread.ThreadState.ToString());
+ return true;
+ }
+
+ private bool pulseGTKEncoderAnalyze ()
+ {
+ if(! encoderThread.IsAlive) {
+ finishPulsebar(encoderModes.ANALYZE);
+ Log.Write("dying");
+ return false;
+ }
+ updatePulsebar(encoderModes.ANALYZE); //activity on pulsebar
+ Thread.Sleep (50);
+ Log.Write(encoderThread.ThreadState.ToString());
+ return true;
+ }
+
+ private void updatePulsebar (encoderModes mode) {
+ if(mode == encoderModes.CAPTURE)
+ encoder_pulsebar_capture.Pulse();
+ else
+ encoder_pulsebar_analyze.Pulse();
+ }
+
+ private void finishPulsebar(encoderModes mode) {
+ if(mode == encoderModes.CAPTURE) {
+ encoder_pulsebar_capture.Fraction = 1;
+ encoder_pulsebar_capture.Text = "";
+ treeview_encoder_curves.Sensitive = true;
+ } else {
+ encoder_pulsebar_analyze.Fraction = 1;
+ encoder_pulsebar_analyze.Text = "";
+ }
+ }
+
+ /* end of thread stuff */
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]