PATH = "/apps/pedometerhomewidget"
MODE = PATH + "/mode"
HEIGHT = PATH + "/height"
+STEP_LENGTH = PATH + "/step_length"
WEIGHT = PATH + "/weight"
UNIT = PATH + "/unit"
+SENSITIVITY = PATH + "/sensitivity"
ASPECT = PATH + "/aspect"
SECONDVIEW = PATH + "/secondview"
GRAPHVIEW = PATH + "/graphview"
class PedoIntervalCounter(Singleton):
MIN_THRESHOLD = 500
MIN_TIME_STEPS = 0.5
+ sensitivity = 100
+ mode = 0
x = []
y = []
z = []
#runnig, higher threshold to prevent fake steps
self.mode = mode
if mode == 1:
- self.MIN_THRESHOLD = 650
+ self.MIN_THRESHOLD = 650.0 * (200 - self.sensitivity) / 100
self.MIN_TIME_STEPS = 0.35
#walking
else:
- self.MIN_THRESHOLD = 500
+ self.MIN_THRESHOLD = 500.0 * (200 - self.sensitivity) / 100
self.MIN_TIME_STEPS = 0.5
+ def set_sensitivity(self, value):
+ self.sensitivity = value
+ self.set_mode(self.mode)
+
def calc_mean(self, vals):
sum = 0
for i in vals:
def get_weight(self):
return self.weight
+ def set_sensitivity(self, value):
+ self.sensitivity = value
+ self.pedometerInterval.set_sensitivity(value)
+
+ def get_sensitivity(self):
+ return self.sensitivity
+
def set_second_view(self, second_view):
self.second_view = second_view
self.load_values()
def set_callback_ui(self, func):
self.callback_update_ui = func
- def set_height(self, height_interval):
- self.height_inteval = height_interval
+ def set_height(self, height_interval, step_length=None):
+ self.height_interval = height_interval
+ if step_length is None:
+ step_length = self.STEP_LENGTH
#set height, will affect the distance
if height_interval == 0:
self.STEP_LENGTH = 0.59
self.STEP_LENGTH = 0.77
elif height_interval == 4:
self.STEP_LENGTH = 0.83
+ elif height_interval == 5:
+ self.STEP_LENGTH = step_length
#increase step length if RUNNING
if self.mode == 1:
self.STEP_LENGTH *= 1.45
weight = 70
unit = 0
aspect = 0
+ sensitivity = 100
second_view = 0
graph_view = 0
no_idle_time = False
self.mode = self.client.get_int(MODE)
self.height = self.client.get_int(HEIGHT)
+ self.step_length = self.client.get_float(STEP_LENGTH)
self.weight = self.client.get_int(WEIGHT)
self.unit = self.client.get_int(UNIT)
+ self.sensitivity = self.client.get_int(SENSITIVITY)
self.aspect = self.client.get_int(ASPECT)
self.second_view = self.client.get_int(SECONDVIEW)
self.graph_view = self.client.get_int(GRAPHVIEW)
self.logging = self.client.get_bool(LOGGING)
self.controller = PedoController()
- self.controller.set_height(self.height)
+ self.controller.set_height(self.height, self.step_length)
self.controller.set_weight(self.weight)
self.controller.set_mode(self.mode)
self.controller.set_unit(self.unit)
+ self.controller.set_sensitivity(self.sensitivity)
self.controller.set_second_view(self.second_view)
self.controller.set_callback_ui(self.update_values)
self.controller.set_no_idle_time(self.no_idle_time)
widget.client.set_int(MODE, widget.mode)
widget.controller.set_mode(widget.mode)
- def selectorH_changed(selector, data):
- widget.height = selector.get_active(0)
- widget.client.set_int(HEIGHT, widget.height)
- widget.controller.set_height(widget.height)
-
def selectorUnit_changed(selector, data):
widget.unit = selector.get_active(0)
widget.client.set_int(UNIT, widget.unit)
widget.controller.set_unit(widget.unit)
- if widget.unit == 0:
- self.heightPicker.set_active(widget.height)
- self.heightPicker.show()
- self.heightPicker_English.hide()
- else:
- self.heightPicker_English.set_active(widget.height)
- self.heightPicker_English.show()
- self.heightPicker.hide()
-
+ update_weight_button()
+ stepLengthButton_value_update()
def selectorUI_changed(selector, data):
widget.aspect = selectorUI.get_active(0)
widget.client.set_bool(NOIDLETIME, widget.no_idle_time)
widget.controller.set_no_idle_time(widget.no_idle_time)
+ def update_weight_button():
+ weightButton.set_value(str(self.controller.get_weight()) + \
+ " " + self.controller.get_str_weight_unit() )
+
def weight_dialog(button):
dialog = gtk.Dialog("Weight", self.dialog)
dialog.add_button("OK", gtk.RESPONSE_OK)
raise ValueError
self.controller.set_weight(value)
self.client.set_int(WEIGHT, value)
- weightButton.set_value(str(self.controller.get_weight()) + \
- " " + self.controller.get_str_weight_unit() )
+ update_weight_button()
break
except:
hildon.hildon_banner_show_information(self, "None", "Invalid weight")
dialog.destroy()
+ def sensitivity_dialog(button):
+ def seekbar_changed(seekbar):
+ label.set_text(str(seekbar.get_position()) + " %")
+
+ dialog = gtk.Dialog("Sensitivity", self.dialog)
+ dialog.add_button("OK", gtk.RESPONSE_OK)
+ seekbar = hildon.Seekbar()
+ seekbar.set_size_request(400, -1)
+ seekbar.set_total_time(200)
+ seekbar.set_position(self.controller.get_sensitivity())
+ seekbar.connect("value-changed", seekbar_changed)
+
+ hbox = gtk.HBox()
+ hbox.add(seekbar)
+ label = gtk.Label(str(self.controller.get_sensitivity()) + " %")
+ label.set_size_request(30, -1)
+ hbox.add(label)
+
+ dialog.vbox.add(hbox)
+ dialog.show_all()
+
+ if dialog.run() == gtk.RESPONSE_OK:
+ value = seekbar.get_position()
+ self.client.set_int(SENSITIVITY, value)
+ self.controller.set_sensitivity(value)
+ widget.sensitivity = value
+ button.set_value(str(self.controller.get_sensitivity()) + " %")
+
+ dialog.destroy()
+
+ def stepLengthButton_value_update():
+ if widget.height == 5:
+ l_unit = ["m", "ft"]
+ stepLengthButton.set_value("Custom value: %.2f %s" % (widget.step_length, l_unit[widget.unit]))
+ else:
+ h = [ ["< 1.50 m", "1.50 - 1.65 m", "1.66 - 1.80 m", "1.81 - 1.95 m", " > 1.95 m"],
+ ["< 5 ft", "5 - 5.5 ft", "5.5 - 6 ft", "6 - 6.5 ft", "> 6.5 ft"]]
+ str = "Using predefined value for height: %s" % h[widget.unit][widget.height]
+ stepLengthButton.set_value(str)
+
+ def stepLength_dialog(button):
+ def selectorH_changed(selector, data, dialog):
+ widget.height = selector.get_active(0)
+ widget.client.set_int(HEIGHT, widget.height)
+ widget.controller.set_height(widget.height)
+ stepLengthButton_value_update()
+
+ def manualButton_clicked(button, dialog):
+ dlg = gtk.Dialog()
+ dlg.set_title("Custom step length")
+ dlg.add_button("OK", gtk.RESPONSE_OK)
+
+ label = gtk.Label("Length")
+
+ entry = hildon.Entry(gtk.HILDON_SIZE_AUTO_WIDTH)
+ if widget.height == 5:
+ entry.set_text(str(widget.step_length))
+
+ labelSuffix = gtk.Label()
+ if widget.unit == 0:
+ labelSuffix.set_label("m")
+ else:
+ labelSuffix.set_label("ft")
+ hbox = gtk.HBox()
+ hbox.add(label)
+ hbox.add(entry)
+ hbox.add(labelSuffix)
+ dlg.vbox.add(hbox)
+ dlg.show_all()
+
+ while 1:
+ response = dlg.run()
+ if response != gtk.RESPONSE_OK:
+ break
+ try:
+ value = float(entry.get_text())
+ if value <= 0:
+ raise ValueError
+ self.controller.set_height(5, value)
+ self.client.set_int(HEIGHT, 5)
+ self.client.set_float(STEP_LENGTH, value)
+ widget.height = 5
+ widget.step_length = value
+ stepLengthButton_value_update()
+ break
+ except ValueError:
+ hildon.hildon_banner_show_information(self, "None", "Invalid length")
+ dlg.destroy()
+ dialog.destroy()
+
+ def heightButton_clicked(button, dialog):
+ dialog.destroy()
+
+ dialog = gtk.Dialog()
+ dialog.set_title("Step length")
+
+ manualButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+ manualButton.set_title("Enter custom value")
+ manualButton.set_alignment(0, 0.8, 1, 1)
+ manualButton.connect("clicked", manualButton_clicked, dialog)
+
+ selectorH = hildon.TouchSelector(text=True)
+ selectorH.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
+ selectorH.append_text("< 1.50 m")
+ selectorH.append_text("1.50 - 1.65 m")
+ selectorH.append_text("1.66 - 1.80 m")
+ selectorH.append_text("1.81 - 1.95 m")
+ selectorH.append_text(" > 1.95 m")
+
+ selectorH_English = hildon.TouchSelector(text=True)
+ selectorH_English.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
+ selectorH_English.append_text("< 5 ft")
+ selectorH_English.append_text("5 - 5.5 ft")
+ selectorH_English.append_text("5.5 - 6 ft")
+ selectorH_English.append_text("6 - 6.5 ft")
+ selectorH_English.append_text("> 6.5 ft")
+
+ heightPicker = hildon.PickerButton(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+ heightPicker.set_alignment(0.0, 0.5, 1.0, 1.0)
+ heightPicker.set_title("Use predefined values for height")
+
+ if widget.height < 5:
+ heightPicker.set_active(widget.height)
+
+ if widget.unit == 0:
+ heightPicker.set_selector(selectorH)
+ else:
+ heightPicker.set_selector(selectorH_English)
+
+ if widget.height < 5:
+ heightPicker.set_active(widget.height)
+ heightPicker.get_selector().connect("changed", selectorH_changed, dialog)
+ heightPicker.connect("value-changed", heightButton_clicked, dialog)
+
+ dialog.vbox.add(heightPicker)
+ dialog.vbox.add(manualButton)
+ dialog.show_all()
+
+ if dialog.run() == gtk.RESPONSE_DELETE_EVENT:
+ dialog.destroy()
+
+ def donateButton_clicked(button, dialog):
+ url = "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=BKE6E9SLK7NP4&lc=RO&item_name=Pedometer%20Widget¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"
+ command = "dbus-send --system --type=method_call --dest=\"com.nokia.osso_browser\" --print-reply /com/nokia/osso_browser/request com.nokia.osso_browser.load_url string:\"%s\"" % url
+ os.system(command)
+
dialog = gtk.Dialog()
dialog.set_title("Settings")
dialog.add_button("OK", gtk.RESPONSE_OK)
self.dialog = dialog
+ stepLengthButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+ stepLengthButton.set_title("Step length")
+ stepLengthButton.set_alignment(0, 0.8, 1, 1)
+ stepLengthButton.connect("clicked", stepLength_dialog)
+ stepLengthButton_value_update()
+
resetButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
resetButton.set_title("Reset total counter")
resetButton.set_alignment(0, 0.8, 1, 1)
modePicker.set_selector(selector)
modePicker.set_active(widget.mode)
- selectorH = hildon.TouchSelector(text=True)
- selectorH.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
- selectorH.append_text("< 1.50 m")
- selectorH.append_text("1.50 - 1.65 m")
- selectorH.append_text("1.66 - 1.80 m")
- selectorH.append_text("1.81 - 1.95 m")
- selectorH.append_text(" > 1.95 m")
- selectorH.connect("changed", selectorH_changed)
-
- selectorH_English = hildon.TouchSelector(text=True)
- selectorH_English.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
- selectorH_English.append_text("< 5 ft")
- selectorH_English.append_text("5 - 5.5 ft")
- selectorH_English.append_text("5.5 - 6 ft")
- selectorH_English.append_text("6 - 6.5 ft")
- selectorH_English.append_text("> 6.5 ft")
- selectorH_English.connect("changed", selectorH_changed)
-
- heightPicker = hildon.PickerButton(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
- heightPicker.set_alignment(0.0, 0.5, 1.0, 1.0)
- heightPicker.set_title("Height")
- heightPicker.set_selector(selectorH)
- heightPicker.set_active(widget.height)
-
- heightPicker_English = hildon.PickerButton(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
- heightPicker_English.set_alignment(0.0, 0.5, 1.0, 1.0)
- heightPicker_English.set_title("Height")
- heightPicker_English.set_selector(selectorH_English)
- heightPicker_English.set_active(widget.height)
-
- self.heightPicker = heightPicker
- self.heightPicker_English = heightPicker_English
weightButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
weightButton.set_title("Weight")
UIPicker.set_selector(selectorUI)
UIPicker.set_active(widget.aspect)
+ sensitivityButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+ sensitivityButton.set_title("Sensitivity")
+ sensitivityButton.set_alignment(0, 0.8, 1, 1)
+ sensitivityButton.set_value(str(self.controller.get_sensitivity()) + " %")
+ sensitivityButton.connect("clicked", sensitivity_dialog)
+
+ donateButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+ donateButton.set_title("Donate")
+ donateButton.set_alignment(0, 0.8, 1, 1)
+ donateButton.connect("clicked", donateButton_clicked, dialog)
+
logButton = hildon.CheckButton(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT)
logButton.set_label("Log data")
logButton.set_active(widget.logging)
vbox = gtk.VBox()
vbox.add(alarmButton)
vbox.add(modePicker)
- vbox.add(heightPicker)
- vbox.add(heightPicker_English)
+ vbox.add(stepLengthButton)
vbox.add(weightButton)
vbox.add(unitPicker)
+ vbox.add(sensitivityButton)
vbox.add(UIPicker)
vbox.add(idleButton)
vbox.add(resetButton)
+ vbox.add(donateButton)
#vbox.add(logButton)
pan_area.add_with_viewport(vbox)
dialog.vbox.add(pan_area)
dialog.show_all()
- if widget.unit == 0:
- self.heightPicker_English.hide()
- else:
- self.heightPicker.hide()
-
response = dialog.run()
- #hildon.hildon_banner_show_information(self, "None", "You have to Stop/Start the counter to apply the new settings")
dialog.destroy()
def close_requested(self, widget):