[chronojump] PersonWin manages better units: metric/imperial (50% done)
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] PersonWin manages better units: metric/imperial (50% done)
- Date: Mon, 9 Mar 2020 17:36:41 +0000 (UTC)
commit 4a56492ca73417be57792a9011e5aa1f6131c351
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Mar 9 18:35:46 2020 +0100
PersonWin manages better units: metric/imperial (50% done)
glade/person_win.glade | 181 +++++++++++++++++++++++++++++++++++++++-----
src/gui/app1/chronojump.cs | 15 +++-
src/gui/person/addModify.cs | 113 +++++++++++++++++++--------
src/util.cs | 3 +
4 files changed, 260 insertions(+), 52 deletions(-)
---
diff --git a/glade/person_win.glade b/glade/person_win.glade
index 442ca3da..33e8e3ff 100644
--- a/glade/person_win.glade
+++ b/glade/person_win.glade
@@ -26,7 +26,7 @@
<widget class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="border_width">8</property>
+ <property name="border_width">12</property>
<property name="spacing">20</property>
<child>
<widget class="GtkTable" id="table2">
@@ -167,27 +167,58 @@
<property name="can_focus">False</property>
<property name="spacing">10</property>
<child>
- <widget class="GtkButton" id="button_weight_metric">
- <property name="label" translatable="yes">Use metric units</property>
+ <widget class="GtkHBox" id="hbox_weight_metric">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <signal name="clicked" handler="on_button_weight_metric_clicked" swapped="no"/>
+ <property name="can_focus">False</property>
+ <property name="spacing">10</property>
+ <child>
+ <widget class="GtkSpinButton" id="spinbutton_weight_metric">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ <property name="activates_default">True</property>
+ <property name="primary_icon_activatable">False</property>
+ <property name="secondary_icon_activatable">False</property>
+ <property name="primary_icon_sensitive">True</property>
+ <property name="secondary_icon_sensitive">True</property>
+ <property name="adjustment">0 0 300 0.10000000000000001 10 0</property>
+ <property name="climb_rate">1</property>
+ <property name="digits">1</property>
+ <property name="numeric">True</property>
+ <signal name="activate" handler="on_entries_required_changed" swapped="no"/>
+ <signal name="value_changed" handler="on_entries_required_changed"
swapped="no"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label6">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label">kg</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
- <widget class="GtkHBox" id="hbox4">
- <property name="visible">True</property>
+ <widget class="GtkHBox" id="hbox_weight_imperial">
<property name="can_focus">False</property>
<property name="spacing">10</property>
<child>
- <widget class="GtkSpinButton" id="spinbutton_weight">
+ <widget class="GtkSpinButton" id="spinbutton_weight_imperial">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
@@ -196,12 +227,10 @@
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
- <property name="adjustment">0 0 300 0.10000000000000001 10 0</property>
+ <property name="adjustment">0 0 700 0.10000000000000001 10 0</property>
<property name="climb_rate">1</property>
<property name="digits">1</property>
<property name="numeric">True</property>
- <signal name="activate" handler="on_entries_required_changed" swapped="no"/>
- <signal name="value_changed" handler="on_entries_required_changed"
swapped="no"/>
</widget>
<packing>
<property name="expand">False</property>
@@ -210,10 +239,10 @@
</packing>
</child>
<child>
- <widget class="GtkLabel" id="label6">
+ <widget class="GtkLabel" id="label27">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="label">kg</property>
+ <property name="label" translatable="yes">pounds </property>
</widget>
<packing>
<property name="expand">False</property>
@@ -554,7 +583,7 @@
<widget class="GtkVBox" id="vbox4">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="border_width">8</property>
+ <property name="border_width">12</property>
<property name="spacing">20</property>
<child>
<widget class="GtkFrame" id="frame5">
@@ -1365,6 +1394,122 @@
<property name="position">0</property>
</packing>
</child>
+ <child>
+ <widget class="GtkHBox" id="hbox4">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <widget class="GtkHBox" id="hbox13">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">14</property>
+ <child>
+ <widget class="GtkLabel" id="label29">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Units:</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkHBox" id="hbox17">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">8</property>
+ <child>
+ <widget class="GtkRadioButton" id="radio_metric">
+ <property name="label" translatable="yes">metric</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="on_radio_metric_imperial_toggled" swapped="no"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label17">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label">(kg, cm)</property>
+ </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">1</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkHBox" id="hbox18">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">8</property>
+ <child>
+ <widget class="GtkRadioButton" id="radio_imperial">
+ <property name="label" translatable="yes">imperial</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">radio_metric</property>
+ <signal name="toggled" handler="on_radio_metric_imperial_toggled" swapped="no"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label28">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">(pound, feet, inch)</property>
+ </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">2</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox_main">
<property name="visible">True</property>
@@ -1409,7 +1554,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
<child>
@@ -1516,7 +1661,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">2</property>
+ <property name="position">3</property>
</packing>
</child>
</widget>
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 341af342..207ce723 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -2650,7 +2650,7 @@ public partial class ChronoJumpWindow
//preferences.digitsNumber, checkbutton_video, configChronojump.UseVideo,
preferences.digitsNumber, checkbutton_video_contacts,
preferences.videoDevice, preferences.videoDevicePixelFormat,
preferences.videoDeviceResolution, preferences.videoDeviceFramerate,
- configChronojump.Compujump
+ configChronojump.Compujump, preferences.units == Preferences.UnitsEnum.METRIC
);
//-1 means we are adding a new person
//if we were modifying it will be it's uniqueID
@@ -2674,6 +2674,11 @@ public partial class ChronoJumpWindow
currentPerson = personAddModifyWin.CurrentPerson;
currentPersonSession = SqlitePersonSession.Select(currentPerson.UniqueID,
currentSession.UniqueID);
+ if(personAddModifyWin.Units != preferences.units) {
+ preferences.units = personAddModifyWin.Units;
+ SqlitePreferences.Update (SqlitePreferences.UnitsStr,
personAddModifyWin.Units.ToString(), false);
+ }
+
person_added();
}
}
@@ -2778,7 +2783,7 @@ public partial class ChronoJumpWindow
//preferences.digitsNumber, checkbutton_video, configChronojump.UseVideo,
preferences.digitsNumber, checkbutton_video_contacts,
preferences.videoDevice, preferences.videoDevicePixelFormat,
preferences.videoDeviceResolution, preferences.videoDeviceFramerate,
- configChronojump.Compujump
+ configChronojump.Compujump, preferences.units == Preferences.UnitsEnum.METRIC
);
personAddModifyWin.FakeButtonAccept.Clicked += new
EventHandler(on_edit_current_person_accepted);
}
@@ -2788,6 +2793,12 @@ public partial class ChronoJumpWindow
{
currentPerson = personAddModifyWin.CurrentPerson;
currentPersonSession = SqlitePersonSession.Select(currentPerson.UniqueID,
currentSession.UniqueID);
+
+ if(personAddModifyWin.Units != preferences.units) {
+ preferences.units = personAddModifyWin.Units;
+ SqlitePreferences.Update (SqlitePreferences.UnitsStr,
personAddModifyWin.Units.ToString(), false);
+ }
+
label_person_change();
treeview_persons_storeReset();
fillTreeView_persons();
diff --git a/src/gui/person/addModify.cs b/src/gui/person/addModify.cs
index 0e9fc265..b77aa3b7 100644
--- a/src/gui/person/addModify.cs
+++ b/src/gui/person/addModify.cs
@@ -29,6 +29,8 @@ public class PersonAddModifyWindow
{
[Widget] Gtk.Window person_win;
+ [Widget] Gtk.RadioButton radio_metric;
+ [Widget] Gtk.RadioButton radio_imperial;
[Widget] Gtk.Entry entry1;
[Widget] Gtk.RadioButton radiobutton_man;
[Widget] Gtk.RadioButton radiobutton_woman;
@@ -55,7 +57,10 @@ public class PersonAddModifyWindow
//[Widget] Gtk.Button button_change_date;
[Widget] Gtk.Image image_calendar;
- [Widget] Gtk.SpinButton spinbutton_weight;
+ [Widget] Gtk.HBox hbox_weight_metric;
+ [Widget] Gtk.HBox hbox_weight_imperial;
+ [Widget] Gtk.SpinButton spinbutton_weight_metric;
+ [Widget] Gtk.SpinButton spinbutton_weight_imperial;
[Widget] Gtk.SpinButton spinbutton_height;
[Widget] Gtk.SpinButton spinbutton_leg_length;
[Widget] Gtk.SpinButton spinbutton_trochanter_floor_on_flexion;
@@ -117,7 +122,7 @@ public class PersonAddModifyWindow
private string videoDeviceFramerate;
private PersonSession currentPersonSession;
private string sex = Constants.M;
- private double weightIni;
+ private double weightIniMetric;
int pDN;
Gtk.CheckButton app1_checkbutton_video_contacts;
@@ -208,7 +213,25 @@ public class PersonAddModifyWindow
person_win.Show();
}
-
+
+ private void on_radio_metric_imperial_toggled (object o, EventArgs args)
+ {
+ if(radio_metric.Active)
+ {
+ spinbutton_weight_metric.Value = Util.ConvertPoundsToKg
(spinbutton_weight_imperial.Value);
+
+ hbox_weight_metric.Visible = true;
+ hbox_weight_imperial.Visible = false;
+ }
+ else if(radio_imperial.Active)
+ {
+ spinbutton_weight_imperial.Value = Util.ConvertKgToPounds
(spinbutton_weight_metric.Value);
+
+ hbox_weight_metric.Visible = false;
+ hbox_weight_imperial.Visible = true;
+ }
+ }
+
void on_button_zoom_clicked (object o, EventArgs args) {
string tempFileName = Path.Combine(Path.GetTempPath(), Constants.PhotoTemp +
Util.GetMultimediaExtension(Constants.MultimediaItems.PHOTO));
@@ -412,7 +435,9 @@ public class PersonAddModifyWindow
image_name.Show();
}
- if((double) spinbutton_weight.Value > 0)
+ if(radio_metric.Active && (double) spinbutton_weight_metric.Value > 0)
+ image_weight.Hide();
+ else if(! radio_metric.Active && (double) spinbutton_weight_imperial.Value > 0)
image_weight.Hide();
else {
image_weight.Show();
@@ -460,7 +485,7 @@ public class PersonAddModifyWindow
//Gtk.CheckButton app1_checkbutton_video, bool showCapturePhoto,
Gtk.CheckButton app1_checkbutton_video_contacts,
string videoDevice, string videoDevicePixelFormat, string videoDeviceResolution,
string videoDeviceFramerate,
- bool compujump)
+ bool compujump, bool metric)
{
if (PersonAddModifyWindowBox == null) {
//PersonAddModifyWindowBox = new PersonAddModifyWindow (parent, mySession,
currentPerson, showCapturePhoto);
@@ -478,7 +503,7 @@ public class PersonAddModifyWindow
PersonAddModifyWindowBox.person_win.Show ();
- PersonAddModifyWindowBox.fillDialog ();
+ PersonAddModifyWindowBox.fillDialog (metric);
return PersonAddModifyWindowBox;
}
@@ -601,7 +626,7 @@ public class PersonAddModifyWindow
combo_countries.Sensitive = false;
}
- private void fillDialog ()
+ private void fillDialog (bool metric)
{
int mySportID;
int mySpeciallityID;
@@ -615,6 +640,17 @@ public class PersonAddModifyWindow
mySpeciallityID = currentSession.PersonsSpeciallityID;
myLevelID = currentSession.PersonsPractice;
} else {
+ if(metric) {
+ hbox_weight_metric.Visible = true;
+ hbox_weight_imperial.Visible = false;
+ radio_metric.Active = true;
+ }
+ else {
+ hbox_weight_metric.Visible = false;
+ hbox_weight_imperial.Visible = true;
+ radio_imperial.Active = true;
+ }
+
//PERSON STUFF
entry1.Text = currentPerson.Name;
entry_club_id.Text = currentPerson.Future2;
@@ -651,12 +687,16 @@ public class PersonAddModifyWindow
//PERSONSESSION STUFF
PersonSession myPS = SqlitePersonSession.Select(currentPerson.UniqueID,
currentSession.UniqueID);
- spinbutton_weight.Value = myPS.Weight;
+ if(metric)
+ spinbutton_weight_metric.Value = myPS.Weight;
+ else
+ spinbutton_weight_imperial.Value = Util.ConvertKgToPounds(myPS.Weight);
+
spinbutton_height.Value = myPS.Height;
spinbutton_leg_length.Value = myPS.TrochanterToe; //future1: altura trochanter -
punta del pie en extension
spinbutton_trochanter_floor_on_flexion.Value = myPS.TrochanterFloorOnFlexion;
//future2: altura trochanter - suelo en flexión
- weightIni = myPS.Weight; //store for tracking if changes
+ weightIniMetric = myPS.Weight; //store for tracking if changes
mySportID = myPS.SportID;
mySpeciallityID = myPS.SpeciallityID;
@@ -726,20 +766,6 @@ public class PersonAddModifyWindow
label_date.Text = dateTime.ToLongDateString();
on_entries_required_changed(new object(), new EventArgs());
}
-
- void on_button_weight_metric_clicked(object obj, EventArgs args)
- {
- genericWin = GenericWindow.Show(Catalog.GetString("Weight"),
- Catalog.GetString("Select your weight in pounds"),
- Constants.GenericWindowShow.SPINDOUBLE, true);
- genericWin.Button_accept.Clicked += new EventHandler(on_button_weight_metric_accepted);
- }
- void on_button_weight_metric_accepted (object obj, EventArgs args)
- {
- genericWin.Button_accept.Clicked -= new EventHandler(on_button_weight_metric_accepted);
-
- spinbutton_weight.Value = Util.ConvertPoundsToKg(genericWin.SpinDoubleSelected);
- }
void on_button_height_metric_clicked(object obj, EventArgs args)
{
@@ -978,8 +1004,12 @@ public class PersonAddModifyWindow
if(personName == "")
errorMessage += "\n" + Catalog.GetString("Please, write the name of the person.");
- if((double) spinbutton_weight.Value == 0)
+
+ if(radio_metric.Active && (double) spinbutton_weight_metric.Value == 0)
+ errorMessage += "\n" + Catalog.GetString("Please, complete the weight of the
person.");
+ if(! radio_metric.Active && (double) spinbutton_weight_imperial.Value == 0)
errorMessage += "\n" + Catalog.GetString("Please, complete the weight of the
person.");
+
if(errorMessage.Length > 0)
{
label_error.Text = errorMessage;
@@ -1015,7 +1045,10 @@ public class PersonAddModifyWindow
}
else {
//if weight has changed
- if(!adding && (double) spinbutton_weight.Value != weightIni) {
+ if(! adding && (
+ (radio_metric.Active && (double)
spinbutton_weight_metric.Value != weightIniMetric) ||
+ (! radio_metric.Active &&
Util.ConvertPoundsToKg(spinbutton_weight_imperial.Value) != weightIniMetric)
+ ) ) {
//see if this person has done jumps with weight
string [] myJumpsNormal = SqliteJump.SelectJumps(false,
currentSession.UniqueID, currentPerson.UniqueID, "withWeight", "",
Sqlite.Orders_by.DEFAULT, -1);
@@ -1023,9 +1056,14 @@ public class PersonAddModifyWindow
if(myJumpsNormal.Length > 0 || myJumpsReactive.Length > 0) {
//create the convertWeight Window
- convertWeightWin = ConvertWeightWindow.Show(
- weightIni, (double) spinbutton_weight.Value,
- myJumpsNormal, myJumpsReactive);
+ if(radio_metric.Active)
+ convertWeightWin = ConvertWeightWindow.Show(
+ weightIniMetric, (double)
spinbutton_weight_metric.Value,
+ myJumpsNormal, myJumpsReactive);
+ else
+ convertWeightWin = ConvertWeightWindow.Show(
+ weightIniMetric,
Util.ConvertPoundsToKg(spinbutton_weight_imperial.Value),
+ myJumpsNormal, myJumpsReactive);
convertWeightWin.Button_accept.Clicked += new
EventHandler(on_convertWeightWin_accepted);
convertWeightWin.Button_cancel.Clicked += new
EventHandler(on_convertWeightWin_cancelled);
} else
@@ -1094,7 +1132,11 @@ public class PersonAddModifyWindow
//string dateFull = dateTime.Day.ToString() + "/" + dateTime.Month.ToString() + "/" +
// dateTime.Year.ToString();
- double weight = (double) spinbutton_weight.Value;
+ double weight = 0;
+ if(radio_metric.Active)
+ weight = (double) spinbutton_weight_metric.Value;
+ else
+ weight = Util.ConvertPoundsToKg(spinbutton_weight_imperial.Value);
//convert margarias (it's power is calculated using weight and it's written on description)
string [] myMargarias = SqliteRun.SelectRuns(false, currentSession.UniqueID,
currentPerson.UniqueID, "Margaria",
@@ -1187,7 +1229,7 @@ public class PersonAddModifyWindow
PersonAddModifyWindowBox.person_win.Hide();
PersonAddModifyWindowBox = null;
-
+
fakeButtonAccept.Click();
}
@@ -1209,8 +1251,6 @@ public class PersonAddModifyWindow
PersonAddModifyWindowBox.person_win.Hide();
PersonAddModifyWindowBox = null;
}
-
-
public void Destroy() {
//PersonAddModifyWindowBox.person_win.Destroy();
@@ -1230,6 +1270,15 @@ public class PersonAddModifyWindow
public PersonSession CurrentPersonSession {
get { return currentPersonSession; }
}
+
+ public Preferences.UnitsEnum Units {
+ get {
+ if(radio_metric.Active)
+ return Preferences.UnitsEnum.METRIC;
+ else
+ return Preferences.UnitsEnum.IMPERIAL;
+ }
+ }
}
diff --git a/src/util.cs b/src/util.cs
index 25c73a8b..fa7e54f2 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -2222,6 +2222,9 @@ public class Util
public static double ConvertPoundsToKg(double pounds) {
return pounds * 0.45359237;
}
+ public static double ConvertKgToPounds(double kg) {
+ return kg / 0.45359237;
+ }
/*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]