Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activity.py64
-rw-r--r--icons/import-stopwatch.svg157
2 files changed, 221 insertions, 0 deletions
diff --git a/activity.py b/activity.py
index 9f54f11..f297849 100644
--- a/activity.py
+++ b/activity.py
@@ -40,11 +40,13 @@ from sugar.graphics.toolbarbox import ToolbarBox
from sugar.graphics.toolbutton import ToolButton
from sugar.graphics.radiotoolbutton import RadioToolButton
from sugar.graphics.colorbutton import ColorToolButton
+from sugar.graphics.objectchooser import ObjectChooser
from sugar.graphics.icon import Icon
from sugar.graphics.alert import Alert
from sugar.datastore import datastore
from charts import Chart
+from readers import StopWatch
def rgb_to_html(color):
@@ -142,6 +144,12 @@ class SimpleGraph(activity.Activity):
activity_btn_toolbar.insert(save_as_image, -1)
save_as_image.show()
+
+ import_stopwatch = ToolButton("import-stopwatch")
+ import_stopwatch.connect("clicked", self.__import_stopwatch_cb)
+ activity_btn_toolbar.insert(import_stopwatch, -1)
+
+ import_stopwatch.show()
activity_btn_toolbar.keep.hide()
toolbarbox.toolbar.insert(activity_button, 0)
@@ -430,6 +438,62 @@ class SimpleGraph(activity.Activity):
self.chart_line_color = rgb_to_html(widget.get_color())
self._render_chart()
+ def __import_stopwatch_cb(self, widget):
+
+ chooser = ObjectChooser()
+
+ response = chooser.run()
+ if response == gtk.RESPONSE_ACCEPT:
+ object = chooser.get_selected_object()
+ metadata = object.metadata
+ file_path = object.file_path
+
+ if metadata['mime_type'] == "activity/x-stopwatch":
+ reader = StopWatch()
+
+ print "Desde StopWatch"
+ f = open(file_path)
+ reader.set_data(f)
+
+ list, count = reader.get_stopwatchs_with_marks()
+
+ if count == 1:
+ num, name = 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')
+
+ 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()
+
def _save_as_image(self, widget):
if self.current_chart:
jobject = datastore.create()
diff --git a/icons/import-stopwatch.svg b/icons/import-stopwatch.svg
new file mode 100644
index 0000000..48f7726
--- /dev/null
+++ b/icons/import-stopwatch.svg
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ version="1.1"
+ width="55"
+ height="55"
+ viewBox="0 0 55 55"
+ id="svg2"
+ xml:space="preserve"
+ inkscape:version="0.48.2 r9819"
+ sodipodi:docname="import-stopwatch.svg"><sodipodi:namedview
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1"
+ objecttolerance="10"
+ gridtolerance="10"
+ guidetolerance="10"
+ inkscape:pageopacity="0"
+ inkscape:pageshadow="2"
+ inkscape:window-width="1280"
+ inkscape:window-height="746"
+ id="namedview3088"
+ showgrid="false"
+ inkscape:zoom="4.2909091"
+ inkscape:cx="-45.520566"
+ inkscape:cy="27.5"
+ inkscape:window-x="0"
+ inkscape:window-y="26"
+ inkscape:window-maximized="1"
+ inkscape:current-layer="svg2" /><metadata
+ id="metadata25"><rdf:RDF><cc:Work
+ rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><defs
+ id="defs33">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ </defs><g
+ transform="matrix(0.55205508,0,0,0.55205508,46.588803,18.00292)"
+ id="g4382"
+ style="fill:#ffffff;stroke:#ffffff;stroke-opacity:1;fill-opacity:0"><g
+ transform="translate(-80.093659,12.220029)"
+ id="g4308"
+ style="fill:#ffffff;stroke:#ffffff;stroke-opacity:1;fill-opacity:0">
+ <g
+ id="g4310"
+ style="fill:#ffffff;stroke:#ffffff;stroke-opacity:1;fill-opacity:0">
+ <path
+ d="m 6.736,49.002 h 24.52 c 2.225,0 3.439,-1.447 3.439,-3.441 v -27.28 c 0,-1.73 -1.732,-3.441 -3.439,-3.441 h -4.389"
+ id="path4312"
+ style="fill:#ffffff;stroke:#ffffff;stroke-width:3.50000000000000000;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;fill-opacity:0"
+ inkscape:connector-curvature="0" />
+ </g>
+ </g><g
+ transform="translate(-80.093659,12.220029)"
+ id="g4314"
+ style="fill:#ffffff;stroke:#ffffff;stroke-opacity:1;fill-opacity:0">
+ <g
+ id="g4316"
+ style="fill:#ffffff;stroke:#ffffff;stroke-opacity:1;fill-opacity:0">
+ <path
+ d="m 26.867,38.592 c 0,1.836 -1.345,3.201 -3.441,4.047 L 6.736,49.002 V 14.84 l 16.69,-8.599 c 2.228,-0.394 3.441,0.84 3.441,2.834 v 29.517 z"
+ id="path4318"
+ style="fill:#ffffff;stroke:#ffffff;stroke-width:3.50000000000000000;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;fill-opacity:0"
+ inkscape:connector-curvature="0" />
+ </g>
+ </g><path
+ d="m -70.669659,54.827029 c 0,0 -1.351,-0.543 -2.702,-0.543 -1.351,0 -2.703,0.543 -2.703,0.543"
+ id="path4320"
+ style="fill:#ffffff;stroke:#ffffff;stroke-width:2.25000000000000000;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;fill-opacity:0"
+ inkscape:connector-curvature="0" /><path
+ d="m -70.669659,44.226029 c 0,0 -1.239,-0.543 -2.815,-0.543 -1.577,0 -2.59,0.543 -2.59,0.543"
+ id="path4322"
+ style="fill:#ffffff;stroke:#ffffff;stroke-width:2.25000000000000000;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;fill-opacity:0"
+ inkscape:connector-curvature="0" /><path
+ d="m -70.669659,33.898029 c 0,0 -1.125,-0.544 -2.927,-0.544 -1.802,0 -2.478,0.544 -2.478,0.544"
+ id="path4324"
+ style="fill:#ffffff;stroke:#ffffff;stroke-width:2.25000000000000000;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;fill-opacity:0"
+ inkscape:connector-curvature="0" /><line
+ style="fill:#ffffff;stroke:#ffffff;stroke-width:2.25000000000000000;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;fill-opacity:0"
+ x1="-66.884659"
+ x2="-66.884659"
+ y1="58.753029"
+ y2="23.725029"
+ id="line4326" /></g><g
+ transform="matrix(0,-1,-1,0,50.602857,87.221318)"
+ id="g4770"
+ style="fill:#ffffff;stroke:#ffffff;stroke-opacity:1;fill-opacity:0"><g
+ transform="translate(34.0803,-1006.42)"
+ id="g4772"
+ style="fill:#ffffff;stroke:#ffffff;stroke-opacity:1;fill-opacity:0"><polyline
+ transform="matrix(-0.469241,0.469241,-0.469241,-0.469241,66.2906,1019.03)"
+ style="fill:#ffffff;stroke:#ffffff;stroke-width:3.50000000000000000;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1;fill-opacity:0"
+ points="51.562,15.306 41.17,16.188 42.053,5.794"
+ id="polyline4774" /><path
+ d="m 39.363241,1033.1291 -0.05636,9.9115 -8.750608,0.067"
+ id="path4776"
+ style="fill:#ffffff;stroke:#ffffff;stroke-width:2.50000000000000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;fill-opacity:0"
+ inkscape:connector-curvature="0" /></g></g><path
+ sodipodi:type="arc"
+ style="fill:#ffffff;fill-opacity:0;stroke:#ffffff;stroke-width:3.02743053000000018;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+ id="path2186"
+ sodipodi:cx="21.976866"
+ sodipodi:cy="21.815269"
+ sodipodi:rx="19.606812"
+ sodipodi:ry="19.768406"
+ d="m 41.583677,21.815269 a 19.606812,19.768406 0 1 1 -39.2136228,0 19.606812,19.768406 0 1 1 39.2136228,0 z"
+ transform="matrix(0.54118041,0,0,0.49317835,29.589601,3.6087155)" /><path
+ inkscape:connector-curvature="0"
+ style="fill:#ffffff;fill-opacity:0;fill-rule:evenodd;stroke:#ffffff;stroke-width:1.04269183000000010;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+ d="m 33.181463,5.7669215 -1.59426,1.639302"
+ id="path2188"
+ sodipodi:nodetypes="cc" /><path
+ inkscape:connector-curvature="0"
+ style="fill:#ffffff;fill-opacity:0;fill-rule:evenodd;stroke:#ffffff;stroke-width:1.04269183000000010;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+ d="m 41.365364,14.637174 7.581821,4.694665"
+ id="path4130"
+ sodipodi:nodetypes="cc" /><path
+ inkscape:connector-curvature="0"
+ sodipodi:nodetypes="cc"
+ id="path2211"
+ d="m 50.186864,6.0595525 1.59426,1.639301"
+ style="fill:#ffffff;fill-opacity:0;fill-rule:evenodd;stroke:#ffffff;stroke-width:1.04269183000000010;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /><path
+ inkscape:connector-curvature="0"
+ style="fill:#ffffff;fill-opacity:0;fill-rule:evenodd;stroke:#ffffff;stroke-width:1.04269183000000010;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+ d="m 38.97611,3.1332525 5.416107,5.97e-4"
+ id="path2213"
+ sodipodi:nodetypes="cc" /></svg> \ No newline at end of file