Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activity.py36
-rw-r--r--readers.py20
2 files changed, 56 insertions, 0 deletions
diff --git a/activity.py b/activity.py
index 9ceec6a..7425a0e 100644
--- a/activity.py
+++ b/activity.py
@@ -48,6 +48,7 @@ from sugar.datastore import datastore
from charts import Chart
from readers import StopWatch
+from readers import Measure
def rgb_to_html(color):
@@ -76,6 +77,7 @@ def get_user_color():
STOPWATCH_MIME_TYPE = "application/x-stopwatch-activity"
+CSV_MIME_TYPE = "text/csv"
COLOR1 = gtk.gdk.Color(get_user_color()[0])
COLOR2 = gtk.gdk.Color(get_user_color()[1])
@@ -155,6 +157,13 @@ class SimpleGraph(activity.Activity):
activity_btn_toolbar.insert(import_stopwatch, -1)
import_stopwatch.show()
+
+ import_measure = ToolButton("import-measure")
+ import_measure.connect("clicked", self.__import_measure_cb)
+ activity_btn_toolbar.insert(import_measure, -1)
+
+ import_measure.show()
+
activity_btn_toolbar.keep.hide()
toolbarbox.toolbar.insert(activity_button, 0)
@@ -516,6 +525,33 @@ class SimpleGraph(activity.Activity):
f.close()
+ def __import_measure_cb(self, widget):
+ boolean, file_path, title = self._object_chooser(CSV_MIME_TYPE,
+ 'Measure')
+
+ if boolean:
+ reader = Measure()
+ f = open(file_path)
+
+ reader.set_data(f)
+
+ self.v_label.entry.set_text('Values')
+ self.h_label.entry.set_text('Samples')
+
+ self.chart_data = []
+ self.labels_and_values.model.clear()
+
+ chart_data = reader.get_chart_data()
+
+ # Load the data
+ for row in chart_data:
+ self._add_value(None,
+ label=row[0], value=float(row[1]))
+
+ self.update_chart()
+
+ f.close()
+
def _save_as_image(self, widget):
if self.current_chart:
jobject = datastore.create()
diff --git a/readers.py b/readers.py
index 9674125..21dd34a 100644
--- a/readers.py
+++ b/readers.py
@@ -19,6 +19,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import cPickle
+import csv
class StopWatch():
@@ -60,3 +61,22 @@ class StopWatch():
round(i, 2)))
return chart_data
+
+
+class Measure():
+
+ def set_data(self, data):
+ self.reader = csv.reader(data)
+
+ def get_chart_data(self):
+ count = 0
+ chart_data = []
+
+ for row in self.reader:
+ count += 1
+
+ if count > 6:
+ label, value = row[0].split(": ")
+ chart_data.append((label, float(value)))
+
+ return chart_data