Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2012-12-09 00:23:54 (GMT)
committer Walter Bender <walter.bender@gmail.com>2012-12-09 00:23:54 (GMT)
commitb0a9e840b309b116d01c136bbcf63e37f19cecdf (patch)
tree0becf0798e9eab1d52c7462c98e784ca9accb3ba
parent5d393dff9f0b00961da8ec5abc0b90329bcb02c0 (diff)
ignore null block definitions (#4316)
-rw-r--r--TurtleArt/tawindow.py41
1 files changed, 30 insertions, 11 deletions
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index 9c5295c..d0341ee 100644
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -1898,12 +1898,14 @@ class TurtleArtWindow():
self._extra_block_data = []
# Create the blocks (or turtle).
blocks = []
- for blk in self._process_block_data:
+ for i, blk in enumerate(self._process_block_data):
if not self._found_a_turtle(blk):
newblk = self.load_block(blk, offset)
if newblk is not None:
blocks.append(newblk)
newblk.spr.set_layer(TOP_LAYER)
+ else:
+ blocks.append(None)
# Some extra blocks may have been added by load_block
for blk in self._extra_block_data:
self._process_block_data.append(blk)
@@ -1913,10 +1915,12 @@ class TurtleArtWindow():
newblk.spr.set_layer(TOP_LAYER)
# Make the connections.
- for i in range(len(blocks)):
+ for i, blk in enumerate(blocks):
+ if blk is None:
+ continue
cons = []
# Normally, it is simply a matter of copying the connections.
- if blocks[i].connections is None:
+ if blk.connections is None:
if self._process_block_data[i][4] is not None:
for c in self._process_block_data[i][4]:
if c is None or c > (len(blocks) - 1):
@@ -1928,7 +1932,7 @@ class TurtleArtWindow():
str(self._process_block_data[i])),
self.running_sugar)
cons.append(None)
- elif blocks[i].connections == 'check':
+ elif blk.connections == 'check':
# Convert old-style boolean and arithmetic blocks
cons.append(None) # Add an extra connection.
for c in self._process_block_data[i][4]:
@@ -1937,16 +1941,16 @@ class TurtleArtWindow():
else:
cons.append(blocks[c])
# If the boolean op was connected, readjust the plumbing.
- if blocks[i].name in block_styles['boolean-style']:
+ if blk.name in block_styles['boolean-style']:
if self._process_block_data[i][4][0] is not None:
c = self._process_block_data[i][4][0]
cons[0] = blocks[self._process_block_data[c][4][0]]
c0 = self._process_block_data[c][4][0]
for j, cj in enumerate(self._process_block_data[c0][4]):
if cj == c:
- blocks[c0].connections[j] = blocks[i]
+ blocks[c0].connections[j] = blk
if c < i:
- blocks[c].connections[0] = blocks[i]
+ blocks[c].connections[0] = blk
blocks[c].connections[3] = None
else:
# Connection was to a block we haven't seen yet.
@@ -1959,9 +1963,9 @@ class TurtleArtWindow():
c0 = self._process_block_data[c][4][0]
for j, cj in enumerate(self._process_block_data[c0][4]):
if cj == c:
- blocks[c0].connections[j] = blocks[i]
+ blocks[c0].connections[j] = blk
if c < i:
- blocks[c].connections[0] = blocks[i]
+ blocks[c].connections[0] = blk
blocks[c].connections[1] = None
else:
# Connection was to a block we haven't seen yet.
@@ -1969,22 +1973,28 @@ class TurtleArtWindow():
self.running_sugar)
else:
debug_output("Warning: unknown connection state %s" % \
- (str(blocks[i].connections)),
+ (str(blk.connections)),
self.running_sugar)
- blocks[i].connections = cons[:]
+ blk.connections = cons[:]
# Block sizes and shapes may have changed.
for blk in blocks:
+ if blk is None:
+ continue
self._adjust_dock_positions(blk)
# Look for any stacks that need to be collapsed
for blk in blocks:
+ if blk is None:
+ continue
if blk.name == 'sandwichclampcollapsed':
collapse_clamp(blk, False)
# process in reverse order
for i in range(len(blocks)):
blk = blocks[-i - 1]
+ if blk is None:
+ continue
if blk.name in EXPANDABLE_FLOW:
if blk.name in block_styles['clamp-style-1arg'] or\
blk.name in block_styles['clamp-style-boolean']:
@@ -1999,6 +2009,13 @@ class TurtleArtWindow():
if blk.connections[3] is not None:
self._resize_clamp(blk, blk.connections[3], dockn=3)
+ # Eliminate None blocks from the block list
+ blocks_copy = []
+ for blk in blocks:
+ if blk is not None:
+ blocks_copy.append(blk)
+ blocks = blocks_copy[:]
+
# Resize blocks to current scale
self.resize_blocks(blocks)
@@ -3394,6 +3411,8 @@ class TurtleArtWindow():
if self.running_sugar:
from sugar.datastore import datastore
+ if b[1] == 0:
+ return None
# A block is saved as: (i, (btype, value), x, y, (c0,... cn))
# The x, y position is saved/loaded for backward compatibility
btype, value = b[1], None