diff options
| author | blob8108 <spaaam42@gmail.com> | 2014-01-07 01:25:17 +0000 |
|---|---|---|
| committer | blob8108 <spaaam42@gmail.com> | 2014-01-07 01:25:17 +0000 |
| commit | efea8b4700749b1a3d985f42e30442c5e49c7271 (patch) | |
| tree | ae250d8ce01e8a31aa33b6e2e165eea581e58b9f | |
| parent | 78195c3ebf9b2b4857fcb64952cbce14a9763aa2 (diff) | |
| download | blockext-efea8b4700749b1a3d985f42e30442c5e49c7271.tar.gz blockext-efea8b4700749b1a3d985f42e30442c5e49c7271.zip | |
Make `problem` and `reset` accessible in Snap! too
Fixes #7
| -rw-r--r-- | blockext/__init__.py | 23 | ||||
| -rw-r--r-- | blockext/scratch.py | 14 | ||||
| -rw-r--r-- | example.py | 3 |
3 files changed, 26 insertions, 14 deletions
diff --git a/blockext/__init__.py b/blockext/__init__.py index c1779a5..86b6e74 100644 --- a/blockext/__init__.py +++ b/blockext/__init__.py @@ -321,6 +321,29 @@ reporter = _shape("reporter") predicate = _shape("predicate") +# Decorators (for special-in-Scratch features) + +def problem(func): + @predicate("{name} is working?") + def _no_problem(): + return not func() + + @reporter("problem with {name}") + def _problem(): + return func() + + return _problem + +problem(lambda: None) + +def reset(func): + @command("reset {name}") + def reset_all(): + func() + + return reset_all + + def run(name="", filename="extension", port=8080): blocking_reporters = [b.text for b in Blockext.blocks.values() if b.shape != "command" and diff --git a/blockext/scratch.py b/blockext/scratch.py index 402ccb0..ace80c8 100644 --- a/blockext/scratch.py +++ b/blockext/scratch.py @@ -33,6 +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 shape = BLOCK_SHAPES[block.shape] if block.shape == "command" and block.is_blocking: shape = "w" @@ -71,16 +72,3 @@ def poll(is_browser=False): @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() - @@ -36,7 +36,8 @@ def id(text): @problem def my_problem(): - return "The Scratch Sensor board is not connected. Foo." + if time.time() % 8 > 4: + return "The Scratch Sensor board is not connected. Foo." @reset def my_reset(): |
