diff options
author | Mike Major <jmikem@bellsouth.net> | 2009-05-29 02:18:39 (GMT) |
---|---|---|
committer | Mike Major <jmikem@bellsouth.net> | 2009-05-29 02:18:39 (GMT) |
commit | 54cb05cf88f35b8bddd81df1bcf5e56b4178dfd2 (patch) | |
tree | 87675f2ac110e2b444886d4e4fc6c04facd934e7 |
initial commit, even though at version 4
first commit of the source to the repo. this is version 4. the previous versions were made before git init.
-rw-r--r-- | activity/activity.info | 8 | ||||
-rw-r--r-- | activity/hoparound-icon.svg | 50 | ||||
-rw-r--r-- | hoparound.py | 100 | ||||
-rwxr-xr-x | setup.py | 13 |
4 files changed, 171 insertions, 0 deletions
diff --git a/activity/activity.info b/activity/activity.info new file mode 100644 index 0000000..1dcd148 --- /dev/null +++ b/activity/activity.info @@ -0,0 +1,8 @@ +[Activity] +name = Hop-A-Round +bundle_id = org.laptop.HopaRound +class = hoparound.HopaRoundActivity +icon = hoparound-icon +activity_version = 4 +host_version = 1 +show_launcher = yes diff --git a/activity/hoparound-icon.svg b/activity/hoparound-icon.svg new file mode 100644 index 0000000..fadcd9b --- /dev/null +++ b/activity/hoparound-icon.svg @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [ + <!ENTITY stroke_color "#666666"> + <!ENTITY fill_color "#FFFFFF"> +]> + +<svg + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.0" + width="55" + height="55" + id="svg2" + style="display:inline"> + <defs + id="defs4" /> + <g + id="layer2" + style="display:inline"> + <path + d="M 24.152311,30.189056 C 24.305548,34.100378 23.188459,37.357186 21.657221,37.463341 C 20.125984,37.569495 18.760446,34.484798 18.607209,30.573476 C 18.453971,26.662154 19.571062,23.405345 21.102299,23.299191 C 22.633536,23.193036 23.999074,26.277734 24.152311,30.189056 L 24.152311,30.189056 z" + id="path2454" + style="fill:&stroke_color;;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:3.00000024;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 34.210643,28.706055 C 35.536369,24.672572 37.887231,21.837215 39.46144,22.373108 C 41.03565,22.909001 41.237086,26.613211 39.91136,30.646694 C 38.585634,34.680176 36.234772,37.515533 34.660563,36.979641 C 33.086353,36.443748 32.884917,32.739538 34.210643,28.706055 L 34.210643,28.706055 z" + id="path3232" + style="fill:&stroke_color;;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;display:inline" /> + <path + d="M 13.858929,7.5280989 C 14.521249,7.1103309 15.165802,6.0931486 16.081475,5.6456742 C 16.863274,5.2636239 17.075809,5.4215793 18.052413,5.8249554 C 18.888499,6.1702916 19.293149,6.8200517 19.687873,7.4384612 C 20.085021,8.0606643 20.490871,8.6852647 20.736244,9.0967847 C 21.251976,9.961736 21.597513,10.790507 21.99429,11.606681 C 22.402473,12.446321 22.700387,13.519398 22.958792,14.071764 C 23.419899,15.057415 23.699577,15.986029 24.007163,16.85058 C 24.265917,17.577876 24.700334,19.220785 24.971665,20.032772 C 25.181339,20.660242 25.628643,22.273754 25.684557,22.632312" + id="path2394" + style="fill:none;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;display:inline" /> + <path + d="M 30.842542,21.870378 C 30.872413,20.848176 30.728346,19.785201 31.076001,18.805025 C 31.139813,17.318509 31.439717,15.858237 31.794088,14.426882 C 32.049991,12.28169 32.860037,10.309813 33.581361,8.2649018 C 34.255448,6.9628049 34.587883,6.181414 35.144177,5.1932857 C 36.128001,4.0439377 37.257535,2.9359077 38.650603,2.402853 C 39.191787,2.217898 39.842922,2.3775927 40.127705,2.9407595 C 40.270268,3.1424533 40.411628,3.3547904 40.613364,3.4943354" + id="path3167" + style="fill:none;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:2.70000005;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;display:inline" /> + <path + d="M 20.986071,23.590455 C 21.611045,22.585799 21.297944,22.934806 21.890608,22.317634 C 22.572171,21.635382 22.824293,21.469811 23.768946,20.772895 C 25.098831,19.978381 26.027287,19.555502 27.108001,19.185422 C 28.188715,18.815342 28.75559,18.634813 29.784484,18.46291 C 30.81338,18.291005 31.534667,18.209581 32.150475,18.162617 C 32.766283,18.115658 33.289267,18.144693 34.37763,18.267704 C 35.465991,18.390712 36.353959,18.777092 36.858181,19.097191 C 37.362403,19.41729 37.664947,19.584577 38.200311,20.089661 C 38.735675,20.594745 38.871289,20.761778 39.474539,21.683878 C 40.166687,22.768653 40.422801,23.473299 40.422801,23.473299" + id="path3168" + style="fill:none;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + d="M 39.208529,32.347402 C 38.592982,35.323224 38.606568,35.195948 38.017531,37.035587 C 37.339705,39.070645 37.087593,39.569326 36.144182,41.661858 C 34.813093,44.061442 33.881712,45.35081 32.795657,46.494018 C 31.709605,47.637226 31.624779,47.839022 30.455654,48.801982 C 29.418819,49.362135 29.308704,49.327113 28.158096,49.722422 C 26.698811,49.938709 26.566822,49.882617 25.465237,49.582663 C 23.966779,48.745625 23.857238,48.692923 22.945855,47.291353 C 22.431342,46.382097 22.123015,45.909062 21.574111,44.459949 C 21.025205,43.010836 20.885544,42.529337 20.261449,39.863108 C 19.544959,36.725541 19.275039,34.676735 19.275039,34.676735" + id="path3170" + style="fill:none;fill-rule:evenodd;stroke:&stroke_color;;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;display:inline" /> + <path + d="M 26.265787,48.255084 C 25.694307,48.095096 25.051803,47.688247 24.644216,47.224031 C 23.72603,46.178275 22.711153,43.728133 22.01838,40.97943 L 21.541347,38.958787 L 21.923716,38.941023 C 23.567751,38.648411 24.893334,36.808815 25.44448,33.739211 C 25.706859,32.277898 25.715423,29.529824 25.451661,27.979259 C 25.111654,25.980461 24.383902,24.006002 23.693499,23.232738 L 23.462901,22.906756 L 23.768067,22.642321 L 24.092917,22.397561 L 24.246349,23.009657 C 24.518275,23.738619 24.95413,24.110445 25.701237,24.103188 C 26.354035,24.096846 26.726595,23.832141 27.023077,23.29768 C 27.266603,22.858682 27.188403,22.505757 26.979063,21.719116 C 26.853249,21.246339 26.652509,20.980497 26.757713,20.913689 C 26.936929,20.799876 29.363365,20.017045 29.524598,20.017045 C 29.606678,20.017045 29.52671,20.534286 29.555408,21.241742 C 29.592668,22.160246 29.52773,22.380721 29.745629,22.674679 C 30.29223,23.412077 31.52525,23.203132 31.932225,22.66956 C 32.211269,21.830923 32.17747,22.367067 32.191174,21.318112 C 32.216876,19.33235 31.842762,19.60759 33.149286,19.654023 C 35.095462,19.700456 36.038468,20.182765 36.944903,20.983917 L 37.331084,21.325244 L 36.580968,21.878192 C 35.661198,22.600026 34.782699,23.766589 33.887863,25.556013 C 33.231643,26.868271 32.774638,28.200058 32.434685,29.466309 C 32.064162,30.84643 31.840084,32.157945 31.836732,33.516539 C 31.832637,35.176234 32.044063,36.064925 32.559076,37.014841 C 33.099603,38.011807 34.118318,38.600627 35.20417,38.549496 C 35.468798,38.537035 35.860656,38.314192 35.890179,38.445726 C 35.93669,38.652951 34.85603,40.973869 34.193028,42.095808 C 33.241425,43.706118 32.219792,45.001621 30.873822,46.40794 C 29.629742,47.7078 29.413134,47.712419 28.249021,48.135301 C 27.714492,48.329478 26.613518,48.440041 26.265787,48.255084 z" + id="path3193" + style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:0;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none" /> + </g> +</svg> diff --git a/hoparound.py b/hoparound.py new file mode 100644 index 0000000..199dac0 --- /dev/null +++ b/hoparound.py @@ -0,0 +1,100 @@ +import gtk, math +import random +from sugar.activity import activity + +class HopaRoundActivity(activity.Activity): + def __init__(self, handle): + activity.Activity.__init__(self, handle) + print "INFO: activity running", handle + # make the toolbox + toolbox = activity.ActivityToolbox(self) + self.set_toolbox(toolbox) + toolbox.show() + #initialize variables + print "INFO: initialize variables" + self.decades = (10,100,1000,10000,100000) + self.rounded={0:0,10:0,100:0,1000:0,10000:0,100000:0} + self.lower_bound = 1 + self.upper_bound = 500000 + random.seed() + #create view ports + print "INFO: create view ports" + self.main_view = gtk.HBox() + self.left_view = gtk.VBox() + self.right_view = gtk.VBox() + self.main_view.pack_start(self.left_view, False, False, 10) + self.main_view.pack_start(self.right_view, False, False, 10) + self.instructions = gtk.Label() + self.instructions.set_justify(gtk.JUSTIFY_LEFT) + self.instructions.set_markup("\n\n\nLet's play...") + self.answer = gtk.Entry() + self.answer.set_text("?") + self.play_btn = gtk.Button("Play") + self.play_btn.connect("clicked", self.play, None) + self.check_answer_btn = gtk.Button("Check Answer") + self.check_answer_btn.connect("clicked", self.check_answer, None) + self.output = gtk.Label() + self.output.set_justify(gtk.JUSTIFY_LEFT) + #show the widgets + print "INFO: show widgets" + self.left_view.pack_start(self.instructions, False, False, 10) + self.left_view.pack_start(self.answer, False, False, 10) + self.left_view.pack_start(self.play_btn, False, False, 10) + self.left_view.pack_start(self.check_answer_btn, False, False, 10) + self.right_view.pack_start(self.output, False, False, 10) + self.set_canvas(self.main_view) + self.show_all() + + def play(self, widget, data=None): + print "INFO: play clicked" + self.gen_random(self) + self.dec_answer = random.choice(decades) + self.guesses = 0 + self.answer.set_text("?") + message = "Round the number <b>" + message += str(self.rounded[0]) + message += "\n</b>to the nearest <b>" + message += str(self.dec_answer) + message += "</b>:" + message += "\n\nEnter your answer below" + self.instructions.set_markup(message) + self.output.set_markup("") + #self.show_random_numbers(self) + self.answer.grab_focus() + + def check_answer(self, widget, data=None): + print "INFO: check answer clicked" + try: + if int(self.answer.get_text()) == self.rounded[self.dec_answer]: + message = "\t<b>That's correct!</b>" + self.output.set_markup(message) + self.guesses = 0 + self.instructions.set_markup("\n\n\nLet's play...") + self.answer.set_text("?") + self.play_btn.grab_focus() + else: + self.guesses += 1 + message = "<span foreground=\"red\">\n\t<b>Sorry, guess " + str(self.guesses) + " wrong...</b></span>" + self.output.set_markup(message) + self.answer.grab_focus() + except: + self.guesses += 1 + message = "<span foreground=\"red\">Please enter a number guess only.\n\t<b>Sorry, guess " + str(self.guesses) + " wrong...</b></span>" + self.output.set_markup(message) + self.answer.grab_focus() + + def gen_random(self, widget, data=None): + print "INFO: generating random number" + self.rounded[0] = random.randint(self.lower_bound,self.upper_bound) + for item in self.decades: + self.rounded[item] = int(round(self.rounded[0]/(item*1.0), 0) * item) + + def show_random_numbers(self, widget, data=None): + print "INFO: showing random number" + message = "Lower Bound: \t\t\t<b>" + str(self.lower_bound) + "</b>" + message += "\n\nUpper Bound: \t\t\t<b>" + str(self.upper_bound) + "</b>" + message += "\n\nNumber Generated: \t<b>" + str(self.rounded[0]) + "</b>" + message += "\n" + for item in self.decades: + message += "\n\nRounded to 10<sup>" + str(int(math.log10(item))) + "</sup>: \t\t<b>" + str(self.rounded[item]) + "</b>" + self.output.set_markup(message) diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..ce8f77c --- /dev/null +++ b/setup.py @@ -0,0 +1,13 @@ +#!/usr/bin/python +try: + from sugar.activity import bundlebuilder + bundlebuilder.start() +except ImportError: + import os + os.system("find ./ | sed 's,^./,HelloWorldActivity.activity/,g' > MANIFEST") + os.system('rm HelloWorldActivity.xo') + os.chdir('..') + os.system('zip -r HelloWorldActivity.xo HelloWorldActivity.activity') + os.system('mv HelloWorldActivity.xo ./HelloWorldActivity.activity') + os.chdir('HelloWorldActivity.activity') + |