Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@walter-laptop.(none)>2010-02-03 01:26:41 (GMT)
committer Walter Bender <walter@walter-laptop.(none)>2010-02-03 01:26:41 (GMT)
commit7d2fccad55a866ce977e190b120d117a8ad2c59c (patch)
treeba9ea56cabbecea2354e50154c3897caa77e274b
parent991053740e566d7544c22423864cdbdb8f43f34d (diff)
predefined macros
-rw-r--r--constants.py18
-rw-r--r--tawindow.py18
2 files changed, 34 insertions, 2 deletions
diff --git a/constants.py b/constants.py
index 06e877b..a949706 100644
--- a/constants.py
+++ b/constants.py
@@ -124,6 +124,24 @@ PORTFOLIO_STYLE_1x1 = ['template1x1']
PORTFOLIO_STYLE_2x1 = ['template2x1']
PORTFOLIO_STYLE_1x2 = ['template1x2']
+
+#
+# Macros (groups of blocks)
+#
+MACROS = {
+ 'kbinput':[[0, 'forever', 0, 0, [None, 1, None]],
+ [1, 'kbinput', 0, 0, [0, 2]],
+ [2, 'vspace', 0, 0, [1, 3]],
+ [3, 'if', 0, 0, [2, 4, 7, 8]],
+ [4, 'greater2', 0, 0, [3, 5, 6, None]],
+ [5, 'keyboard', 0, 0, [4, None]],
+ [6, ['number', '0'], 0, 0, [4, None]],
+ [7, 'stopstack', 0, 0, [3, None]],
+ [8, 'vspace', 0, 0, [3, 9]],
+ [9, 'wait', 0, 0, [8, 10, None]],
+ [10, ['number', '1'], 0, 0, [9, None]]]
+ }
+
#
# blocks that are expandable
#
diff --git a/tawindow.py b/tawindow.py
index 92e84f5..d8e954a 100644
--- a/tawindow.py
+++ b/tawindow.py
@@ -868,9 +868,11 @@ class TurtleArtWindow():
elif blk.type == 'proto':
if blk.name == 'restore':
self._restore_from_trash()
+ elif MACROS.has_key(blk.name):
+ self._new_macro(blk.name, x, y+PALETTE_HEIGHT)
else:
blk.spr.set_shape(blk.shapes[1])
- self._new_block_from_category(blk.name, x, y+PALETTE_HEIGHT)
+ self._new_block(blk.name, x, y+PALETTE_HEIGHT)
blk.spr.set_shape(blk.shapes[0])
return True
@@ -1211,7 +1213,7 @@ class TurtleArtWindow():
"""
Make a new block.
"""
- def _new_block_from_category(self, name, x, y):
+ def _new_block(self, name, x, y):
if name in CONTENT_BLOCKS:
newblk = Block(self.block_list, self.sprite_list, name,
x-20, y-20, 'block', DEFAULTS[name])
@@ -1453,6 +1455,15 @@ class TurtleArtWindow():
self.save_file_name = os.path.basename(fname)
"""
+ Create a "macro" (predefined stack of blocks)
+ """
+ def _new_macro(self, name, x, y):
+ macro = MACROS[name]
+ macro[0][2] = x
+ macro[0][3] = y
+ self.process_data(macro)
+
+ """
Process data (from a file or clipboard) into blocks
"""
def process_data(self, data):
@@ -1518,6 +1529,8 @@ class TurtleArtWindow():
btype, value = b[1], None
if type(btype) == type((1,2)):
btype, value = btype
+ elif type(btype) == type([1,2]):
+ btype, value = btype[0], btype[1]
if btype in CONTENT_BLOCKS:
if btype == 'number':
try:
@@ -1648,6 +1661,7 @@ class TurtleArtWindow():
def assemble_data_to_save(self, save_turtle=True, save_project=True):
# TODO: if save_project is False: just the current stack
data = []
+
for i, b in enumerate(self._just_blocks()):
b.id = i
for b in self._just_blocks():