summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blockext/__init__.py1
-rw-r--r--blockext/scratch.py17
-rw-r--r--example.py15
3 files changed, 29 insertions, 4 deletions
diff --git a/blockext/__init__.py b/blockext/__init__.py
index e507915..7b2a36e 100644
--- a/blockext/__init__.py
+++ b/blockext/__init__.py
@@ -327,4 +327,5 @@ def run(name="", filename="extension", port=8080):
import blockext.scratch
+from blockext.scratch import problem, reset
import blockext.snap
diff --git a/blockext/scratch.py b/blockext/scratch.py
index 917d37a..402ccb0 100644
--- a/blockext/scratch.py
+++ b/blockext/scratch.py
@@ -68,10 +68,19 @@ def poll(is_browser=False):
)
return ("text/plain", lines)
-@reporter("_problem", hidden=True)
-def _problem():
- return "The Scratch Sensor board is not connected.\n Foo."
-
@reporter("_busy", hidden=True)
def _busy():
return " ".join(map(str, Blockext.requests))
+
+# Decorators
+
+def problem(func):
+ @reporter("_problem", hidden=True)
+ def _problem():
+ return func()
+
+def reset(func):
+ @command("reset_all", hidden=True)
+ def reset_all():
+ func()
+
diff --git a/example.py b/example.py
index 8a67c24..8eb0638 100644
--- a/example.py
+++ b/example.py
@@ -91,6 +91,21 @@ def move(steps):
}
"""
+@problem
+def my_problem():
+ return "The Scratch Sensor board is not connected. 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.)
+ """)
+
+
+
if __name__ == "__main__":
blockext.run("Fancy Spaceship", "spaceship", 1234)