Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activity.py74
-rw-r--r--readers.py13
2 files changed, 60 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:
diff --git a/readers.py b/readers.py
index 7c87fdb..2b0f269 100644
--- a/readers.py
+++ b/readers.py
@@ -47,3 +47,16 @@ class StopWatch():
chart_data.append((str(marks_count), i))
return chart_data
+
+ def times_to_chart_data(self):
+ times = [i[0][0] for i in self.data[2]]
+
+ times_count = 0
+ chart_data = []
+
+ for i in times:
+ times_count += 1
+ chart_data.append((self.get_stopwatch_name(times_count - 1),
+ round(i, 2)))
+
+ return chart_data