Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
diff options
context:
space:
mode:
authorSai Vineet <saivineet89@gmail.com>2013-11-20 14:47:14 (GMT)
committer Agustin Zubiaga <aguz@sugarlabs.org>2013-11-21 11:06:32 (GMT)
commitab7b5fe2906867093370c1d6756edbcc486f0a28 (patch)
treebc346ec80615bcefe6f58b88c5a67968b3f677ee /activity.py
parent2767551bf75593d88be8a46b5e62f55c496ffd43 (diff)
Filter Chart Inputs
Problem: Error when inputting value with preceding "$" causes a problem - Invalid value The value must be a number (integer or decimal) - the wording is too advanced for primary school students to understand, need to implement a filter to prevent such vales from being entered. Solution: Implement a filter to extract the most probable input the user wants. If there is not probable input, like "dscsdc", then display error message. Fixes #4588 Signed-off-by: Agustin Zubiaga <aguz@sugarlabs.org>
Diffstat (limited to 'activity.py')
-rw-r--r--activity.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/activity.py b/activity.py
index a977b24..f9d1fd0 100644
--- a/activity.py
+++ b/activity.py
@@ -24,6 +24,7 @@ from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
import os
+import re # for extracting values from invalid inputs.
try:
import json
@@ -101,6 +102,16 @@ def _invalid_number_alert(activity):
activity.add_alert(alert)
alert.show()
+def _extract_value(value):
+ decimals_found = re.findall("\d+\.\d+", str(value))
+ integers_found = re.findall("\d+", str(value))
+
+ if decimals_found != []:
+ return decimals_found[0]
+ elif integers_found != []:
+ return integers_found[0]
+ return None
+
class ChartArea(Gtk.DrawingArea):
@@ -1112,8 +1123,17 @@ class ChartData(Gtk.TreeView):
self.emit('value-changed', str(path), number)
- elif not is_number:
- _invalid_number_alert(activity)
+ else:
+ if _extract_value(number) is not None:
+ number = str(_extract_value(number))
+
+ decimals = utils.get_decimals(str(float(number)))
+ new_text = locale.format('%.' + decimals + 'f', float(number))
+ model[path][1] = str(new_text)
+
+ self.emit('value-changed', str(path), number)
+ else:
+ _invalid_number_alert(activity)
class Entry(Gtk.ToolItem):