summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorblob8108 <spaaam42@gmail.com>2014-01-07 16:11:24 +0000
committerblob8108 <spaaam42@gmail.com>2014-01-07 21:17:52 +0000
commit9246d94777087ba072262771bf58c54469ee633c (patch)
treebe53baab0ad1df34aa2de588439846656cf32db8
parentc07a50a629e9d8d75d48ad09988deb54b07bab4a (diff)
downloadblockext-9246d94777087ba072262771bf58c54469ee633c.tar.gz
blockext-9246d94777087ba072262771bf58c54469ee633c.zip
Fix `problem` and `reset` built-in blocks.
-rw-r--r--blockext/__init__.py16
-rw-r--r--blockext/scratch.py12
2 files changed, 22 insertions, 6 deletions
diff --git a/blockext/__init__.py b/blockext/__init__.py
index cfa843b..62d0618 100644
--- a/blockext/__init__.py
+++ b/blockext/__init__.py
@@ -367,7 +367,10 @@ def problem(func):
@predicate("{name} is working?", help_text=func.__doc__)
def _no_problem():
"""Reports `true` if the extension is working without any problems."""
- return not func()
+ if func:
+ return not func()
+ else:
+ return True
@reporter("problem with {name}", help_text=func.__doc__)
def _problem():
@@ -378,21 +381,24 @@ def problem(func):
"""
return func()
+ if not func:
+ del Blockext.blocks["_problem"]
+
return _problem
-problem(lambda: None)
+problem(None)
def reset(func):
@command("reset {name}", help_text=func.__doc__)
- def reset_all():
+ def _reset():
"""Resets the extension to its initial state.
- Has the same effect as clicking the red stop button in Scratch 2.0.
+ Triggered by clicking the red stop button in Scratch 2.0.
"""
func()
- return reset_all
+ return _reset
def run(name="", filename="extension", port=8080):
diff --git a/blockext/scratch.py b/blockext/scratch.py
index ace80c8..a812028 100644
--- a/blockext/scratch.py
+++ b/blockext/scratch.py
@@ -33,7 +33,7 @@ def generate_s2e():
}
for name, block in Blockext.blocks.items():
if block.is_hidden: continue
- if name in ("_problem", "_no_problem", "reset_all"): continue
+ if name in ("_problem", "_no_problem", "_reset"): continue
shape = BLOCK_SHAPES[block.shape]
if block.shape == "command" and block.is_blocking:
shape = "w"
@@ -72,3 +72,13 @@ def poll(is_browser=False):
@reporter("_busy", hidden=True)
def _busy():
return " ".join(map(str, Blockext.requests))
+
+
+# The actual command is called _reset so it sorts to the top along with the
+# other built-in commands.
+
+@command("reset_all", hidden=True)
+def reset_all():
+ block = Blockext.blocks.get("_reset")
+ if block: block()
+