diff options
author | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-02-13 23:41:10 (GMT) |
---|---|---|
committer | Agustin Zubiaga <aguz@sugarlabs.org> | 2012-02-13 23:41:10 (GMT) |
commit | c6c7743e7c66912c61f2e9ef7df7b4f8943cbdf1 (patch) | |
tree | 534533917a69c65d4e0492a12f902e304c2aecd0 /activity.py | |
parent | d187afec8d42af8c7cc27cfd6c40f6c11babe99e (diff) |
Graph the times of the stopwatchs
Diffstat (limited to 'activity.py')
-rw-r--r-- | activity.py | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/activity.py b/activity.py index 622aeb7..ec9a757 100644 --- a/activity.py +++ b/activity.py @@ -74,6 +74,8 @@ def get_user_color(): return color.split(",") +STOPWATCH_MIME_TYPE = "application/x-stopwatch-activity" + COLOR1 = gtk.gdk.Color(get_user_color()[0]) COLOR2 = gtk.gdk.Color(get_user_color()[1]) @@ -440,9 +442,9 @@ class SimpleGraph(activity.Activity): self.chart_line_color = rgb_to_html(widget.get_color()) self._render_chart() - def __import_stopwatch_cb(self, widget): - + def _object_chooser(self, mime_type, type_name): chooser = ObjectChooser() + boolean = False response = chooser.run() if response == gtk.RESPONSE_ACCEPT: @@ -450,7 +452,34 @@ class SimpleGraph(activity.Activity): metadata = jobject.metadata file_path = jobject.file_path - if metadata['mime_type'] == "application/x-stopwatch-activity": + if metadata['mime_type'] == mime_type: + boolean = True + + else: + alert = Alert() + + alert.props.title = _('Invalid object') + alert.props.msg = \ + _('The selected object must be a %s file' % (type_name)) + + ok_icon = Icon(icon_name='dialog-ok') + alert.add_button(gtk.RESPONSE_OK, _('Ok'), ok_icon) + ok_icon.show() + + alert.connect('response', lambda a, r: self.remove_alert(a)) + + self.add_alert(alert) + + alert.show() + + return boolean, file_path, metadata['title'] + + def __import_stopwatch_cb(self, widget): + boolean, file_path, title = self._object_chooser( + STOPWATCH_MIME_TYPE, + "StopWatch") + + if boolean: reader = StopWatch() f = open(file_path) @@ -458,42 +487,33 @@ class SimpleGraph(activity.Activity): stopwatchs_list, count = reader.get_stopwatchs_with_marks() + self.labels_and_values.model.clear() + self.chart_data = [] + + self.v_label.entry.set_text("Time") + if count == 1: num, name = stopwatchs_list[0] - self.labels_and_values.model.clear() - self.chart_data = [] self.h_label.entry.set_text("Number") - self.v_label.entry.set_text("Time") self.set_title(name) chart_data = reader.marks_to_chart_data(num - 1) - # Load the data - for row in chart_data: - self._add_value(None, - label=row[0], value=float(row[1])) - - self.update_chart() - - f.close() - - else: - alert = Alert() - - alert.props.title = _('Invalid object') - alert.props.msg = \ - _('The selected object must be a StopWatch file') + elif count == 0 or count > 1: + self.set_title(title) + self.h_label.entry.set_text("Names") - ok_icon = Icon(icon_name='dialog-ok') - alert.add_button(gtk.RESPONSE_OK, _('Ok'), ok_icon) - ok_icon.show() + chart_data = reader.times_to_chart_data() - alert.connect('response', lambda a, r: self.remove_alert(a)) + # Load the data + for row in chart_data: + self._add_value(None, + label=row[0], value=float(row[1])) - self.add_alert(alert) + self.update_chart() - alert.show() + f.close() def _save_as_image(self, widget): if self.current_chart: |