diff options
author | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-02-16 20:33:07 (GMT) |
---|---|---|
committer | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-02-16 20:33:07 (GMT) |
commit | 08044b689c3cbed3b18e58bb5267951024a778ee (patch) | |
tree | 1f87b73812d3f3a84f9c3dd7e572319b617b22e3 | |
parent | 8f5ff158f85d470644c0b3f04e66230b4a3ed994 (diff) |
Graph from reader in only one function
Signed-off-by: Agustin Zubiaga <aguz@sugarlabs.org>
-rw-r--r-- | activity.py | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/activity.py b/activity.py index 87d0624..c5c55a9 100644 --- a/activity.py +++ b/activity.py @@ -486,6 +486,24 @@ class SimpleGraph(activity.Activity): return matches_mime_type, file_path, metadata['title'] + def _graph_from_reader(self, reader): + self.labels_and_values.model.clear() + self.chart_data = [] + + chart_data = reader.get_chart_data() + + h, v = reader.get_labels_name() + + self.v_label.entry.set_text(h) + self.h_label.entry.set_text(v) + + # Load the data + for row in chart_data: + self._add_value(None, + label=row[0], value=float(row[1])) + + self.update_chart() + def __import_stopwatch_cb(self, widget): matches_mime_type, file_path, title = self._object_chooser( STOPWATCH_MIME_TYPE, @@ -494,23 +512,7 @@ class SimpleGraph(activity.Activity): if matches_mime_type: f = open(file_path) reader = StopWatchReader(f) - - self.labels_and_values.model.clear() - self.chart_data = [] - - chart_data = reader.get_chart_data() - - h, v = reader.get_labels_name() - - self.v_label.entry.set_text(h) - self.h_label.entry.set_text(v) - - # Load the data - for row in chart_data: - self._add_value(None, - label=row[0], value=float(row[1])) - - self.update_chart() + self._graph_from_reader(reader) f.close() @@ -522,23 +524,7 @@ class SimpleGraph(activity.Activity): if matches_mime_type: f = open(file_path) reader = MeasureReader(f) - - h, v = reader.get_labels_name() - - self.v_label.entry.set_text(h) - self.h_label.entry.set_text(v) - - 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() + self._graph_from_reader(reader) f.close() |