summaryrefslogtreecommitdiff
path: root/example.py
diff options
context:
space:
mode:
authorblob8108 <blob8108@gmail.com>2014-05-28 20:50:08 +0100
committerblob8108 <blob8108@gmail.com>2014-05-28 20:50:08 +0100
commitee0474c2690ef221ddadbb8b556511f92b81bd27 (patch)
treea02d64689cb284e4998a46f68f6fcada5c5b92dd /example.py
parent14df0ecb5a4e0fb67ea0ebaae52ec45a9f7ba9a0 (diff)
downloadblockext-ee0474c2690ef221ddadbb8b556511f92b81bd27.tar.gz
blockext-ee0474c2690ef221ddadbb8b556511f92b81bd27.zip
GIGA-COMMIT: Blockext 0.2 draft version
Diffstat (limited to 'example.py')
-rw-r--r--example.py131
1 files changed, 61 insertions, 70 deletions
diff --git a/example.py b/example.py
index 02c3896..0eec225 100644
--- a/example.py
+++ b/example.py
@@ -1,92 +1,83 @@
# coding=utf-8
+from __future__ import unicode_literals
-import blockext
-from blockext import *
-
+import time
+from blockext import *
-@predicate("not %b")
-def not_(value):
- return not value
-
-@command("say %s for %n secs", blocking=True)
-def say_for_secs(text="Hello", duration=5):
- import time
- print(text)
- time.sleep(duration)
-@command("play note %n")
-def play_note(note):
- print("DING {note}".format(note=note))
- time.sleep(2)
+class Example:
+ def __init__(self):
+ self.foo = 0
-menu("pizza", ["tomato", "cheese", "hawaii", "nothing",
- "spinach and cauliflower", "empty return value",
- "cheese and tomato", "fancy",
- "ü",
- "/",
- ])
+ def _problem(self):
+ if time.time() % 8 > 4:
+ return "The Scratch Sensor board is not connected. Foo."
-@reporter("colour of %m.pizza flavour pizza")
-def pizza_colour(pizza="tomato"):
- return {
- "tomato": "red",
- "cheese": "yellow",
- "cheese and tomato": "YELLOW",
- "hawaii": "orange AND BLUE",
- "spinach and cauliflower": "GREEN ü",
- "empty return value": "",
- "nothing": "",
- "/": "SLASH",
- u"ü": "unicode",
- u"fancy": "❤☀☆☂",
- }[pizza]
+ def _on_reset(self):
+ print("""
+ Reset! The red stop button has been clicked,
+ And now everything is how it was.
+ ...
+ (Poetry's not my strong point, you understand.)
+ """)
-@reporter("spaaace")
-def getSpaaace():
- return "space space space space space!"
+ @predicate("not %b")
+ def not_(self, value):
+ return not value
-@reporter("id %s")
-def id(text):
- """Tests strings can get passed from Snap! to Python and back."""
- print(text)
- return text
+ @command("say %s for %n secs", is_blocking=True)
+ def say_for_secs(self, text="Hello", duration=5):
+ print(text)
+ time.sleep(duration)
-@command("set number to %n% units")
-def percent(number=42):
- print(number)
+ @command("play note %n")
+ def play_note(self, note):
+ print("DING {note}".format(note=note))
+ time.sleep(2)
-foo = None
+ @reporter("colour of %m.pizza flavour pizza", defaults=["tomato"])
+ def pizza_colour(self, pizza):
+ return {
+ "tomato": "red",
+ "cheese": "yellow",
+ "hawaii": "orange and blue",
+ }[pizza]
-@command("set foo to %s")
-def set_foo(value=''):
- global foo
- foo = value
+ @reporter("id %s")
+ def id(self, text):
+ """Tests strings can get passed from Snap! to Python and back."""
+ print(text)
+ return text
-@reporter("foo")
-def get_foo():
- return foo
+ @command("set number to %n% units")
+ def percent(self, number=42):
+ print(number)
-@command("ü")
-def x(): pass
+ @command("set foo to %s")
+ def set_foo(self, value=''):
+ self.foo = value
-@problem
-def my_problem():
- if time.time() % 8 > 4:
- return "The Scratch Sensor board is not connected. Foo."
+ @reporter("foo")
+ def get_foo(self):
+ return self.foo
-@reset
-def my_reset():
- print("""
- Reset! The red stop button has been clicked,
- And now everything is how it was.
- ...
- (Poetry's not my strong point, you understand.)
- """)
+ @command("ü")
+ def x(self):
+ pass
+descriptor = Descriptor(
+ name = "Fancy Spaceship",
+ port = 1234,
+ blocks = get_decorated_blocks_from_class(Example),
+ menus = dict(
+ pizza = ["tomato", "cheese", "hawaii"],
+ ),
+)
+extension = Extension(Example, descriptor)
if __name__ == "__main__":
- blockext.run("Fancy Spaceship", "spaceship", 1234)
+ extension.run_forever(debug=True)