Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAneesh Dogra <lionaneesh@gmail.com>2012-12-29 04:52:53 (GMT)
committer Aneesh Dogra <lionaneesh@gmail.com>2012-12-29 04:52:53 (GMT)
commit3358fbc8ef1c3e50ff92fda6f00ae668e50ef780 (patch)
treeb53ce3710e1cd02d519a60a2132df44d7e6297d8
Initial Commit.
-rw-r--r--LevelActivity.py157
-rw-r--r--activity/activity.info9
-rw-r--r--activity/level.svg71
-rwxr-xr-xsetup.py2
4 files changed, 239 insertions, 0 deletions
diff --git a/LevelActivity.py b/LevelActivity.py
new file mode 100644
index 0000000..f312ccb
--- /dev/null
+++ b/LevelActivity.py
@@ -0,0 +1,157 @@
+# LevelActivity.py
+# Copyright (C) 2012 Aneesh Dogra <lionaneesh@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+from gi.repository import Gtk
+from gi.repository import GObject
+from sugar3.activity import widgets
+from sugar3.activity.widgets import StopButton
+from sugar3.activity import activity
+
+#ACCELEROMETER_DEVICE = '/sys/devices/platform/lis3lv02d/position'
+ACCELEROMETER_DEVICE = 'a.txt'
+
+def read_accelerometer(canvas):
+ fh = open(ACCELEROMETER_DEVICE)
+ string = fh.read()
+ xyz = string.split(',')
+ print xyz
+ x = float(xyz[0])
+ y = float(xyz[1])
+ canvas.motion_cb(x, y)
+ fh.close()
+ GObject.timeout_add(100, read_accelerometer, canvas)
+
+class MyCanvas(Gtk.DrawingArea):
+ ''' Create a GTK+ widget on which we will draw using Cairo '''
+
+ def __init__(self):
+ Gtk.DrawingArea.__init__(self)
+ self._draw_ruler = False
+ self._object = None
+ self.connect('draw', self._draw_cb)
+ self._dpi = 96
+ self.cr = None
+ self.width = 0
+ self.height = 0
+ self.x = 0
+ self.y = 0
+
+ def _draw_cb(self, drawing_area, cr):
+ self.cr = cr
+ cr.set_line_width(2)
+ self.width = drawing_area.get_allocated_width()
+ self.height = drawing_area.get_allocated_height()
+
+ cr.set_source_rgb(1, 1, 1)
+ cr.rectangle(0, 0, self.width, self.height)
+ cr.fill()
+
+
+ cr.set_source_rgb(0.8, 0.8, 0.8)
+ cr.arc(self.width / 2, self.height / 2,
+ min(self.width / 2, self.height / 2), 0,
+ 2 * 3.14)
+ cr.fill()
+
+
+ cr.set_source_rgb(0, 0, 0)
+ cr.arc(self.width / 2, self.height / 2,
+ min(self.width / 2, self.height / 2) / 3, 0,
+ 2 * 3.14)
+ cr.stroke()
+
+
+ cr.set_source_rgb(0, 0, 0)
+ cr.arc(self.width / 2, self.height / 2,
+ min(self.width / 2, self.height / 2) * 2 / 3, 0,
+ 2 * 3.14)
+ cr.stroke()
+
+ cr.set_source_rgb(0, 0, 0)
+ cr.arc(self.width / 2, self.height / 2,
+ min(self.width / 2, self.height / 2), 0,
+ 2 * 3.14)
+ cr.stroke()
+
+ cr.move_to(self.width / 2 - min(self.width / 2, self.height / 2), self.height / 2)
+ cr.line_to(self.width / 2 + min(self.width / 2, self.height / 2), self.height / 2)
+ cr.stroke()
+
+ cr.move_to(self.width / 2, self.height / 2 - min(self.width / 2, self.height / 2))
+ cr.line_to(self.width / 2, self.height / 2 + min(self.width / 2, self.height / 2))
+ cr.stroke()
+
+ self.update_ball_and_text()
+
+ def update_ball_and_text(self):
+ self.cr.set_source_rgb(0, 0.453, 0)
+ self.cr.arc(self.x, self.y, 20, 0, 2 * 3.14)
+ self.cr.fill()
+
+ # Now update the text
+
+ # 1. Clear Text
+ self.cr.set_source_rgb(1, 1, 1)
+ self.cr.rectangle(self.width - 110, self.height - 110, self.width, self.height)
+ self.cr.fill()
+
+ # 2. Update Text
+
+ self.cr.set_source_rgb(0, 0, 0)
+ self.cr.move_to(self.width - 100, self.height - 80)
+ self.cr.set_font_size(20)
+ self.cr.show_text("X: %.2f" % (self.x,))
+
+ self.cr.move_to(self.width - 99, self.height - 60)
+ self.cr.set_font_size(20)
+ self.cr.show_text("Y: %.2f" % (self.y,))
+
+
+ def motion_cb(self, x, y):
+ print x, y
+ self.x = x
+ self.y = y
+ self.queue_draw()
+
+ def get_dpi(self):
+ return self._dpi
+
+ def set_dpi(self, dpi):
+ self._dpi = dpi
+
+
+class LevelActivity(activity.Activity):
+ def __init__(self, handle):
+ "The entry point to the Activity"
+ activity.Activity.__init__(self, handle)
+
+ toolbox = widgets.ActivityToolbar(self)
+ toolbox.share.props.visible = False
+
+ stop_button = StopButton(self)
+ stop_button.show()
+ toolbox.insert(stop_button, -1)
+
+ self.set_toolbar_box(toolbox)
+ toolbox.show()
+
+ # Draw the canvas
+ self._canvas = MyCanvas()
+ self.set_canvas(self._canvas)
+ self._canvas.show()
+
+ GObject.timeout_add(100, read_accelerometer, self._canvas)
diff --git a/activity/activity.info b/activity/activity.info
new file mode 100644
index 0000000..d0377a0
--- /dev/null
+++ b/activity/activity.info
@@ -0,0 +1,9 @@
+[Activity]
+name = Level
+bundle_id = net.flossmanuals.LevelActivity
+icon = level
+exec = sugar-activity LevelActivity.LevelActivity
+show_launcher = yes
+mime_types = text/plain;application/zip
+activity_version = 1
+license = GPLv2+
diff --git a/activity/level.svg b/activity/level.svg
new file mode 100644
index 0000000..5682ec8
--- /dev/null
+++ b/activity/level.svg
@@ -0,0 +1,71 @@
+<?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [
+ <!ENTITY stroke_color "#000000">
+ <!ENTITY fill_color "#FFFFFF">
+]><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"
+ width="48px"
+ height="48px"
+ id="svg116"
+ sodipodi:version="0.32"
+ inkscape:version="0.46+devel"
+ sodipodi:docname="New document 4"
+ inkscape:output_extension="org.inkscape.output.svg.inkscape">
+ <defs
+ id="defs118">
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="0 : 24 : 1"
+ inkscape:vp_y="0 : 1000 : 0"
+ inkscape:vp_z="48 : 24 : 1"
+ inkscape:persp3d-origin="24 : 16 : 1"
+ id="perspective124" />
+ </defs>
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="7"
+ inkscape:cx="24"
+ inkscape:cy="24"
+ inkscape:current-layer="layer1"
+ showgrid="true"
+ inkscape:grid-bbox="true"
+ inkscape:document-units="px"
+ inkscape:window-width="1024"
+ inkscape:window-height="698"
+ inkscape:window-x="0"
+ inkscape:window-y="25" />
+ <metadata
+ id="metadata121">
+ <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></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ id="layer1"
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer">
+ <rect
+ style="fill:&fill_color;;stroke:&stroke_color;;stroke-opacity:1"
+ id="rect904"
+ width="36.142857"
+ height="32.142857"
+ x="4.1428571"
+ y="7.1428571" />
+ </g>
+</svg>
diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000..d4b5aa0
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,2 @@
+from sugar3.activity import bundlebuilder
+bundlebuilder.start()