Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TurtleArt/tablock.py2
-rw-r--r--TurtleArt/tautils.py7
-rw-r--r--TurtleArt/tawindow.py28
3 files changed, 21 insertions, 16 deletions
diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py
index b797ada..344f2da 100644
--- a/TurtleArt/tablock.py
+++ b/TurtleArt/tablock.py
@@ -367,7 +367,7 @@ class Block:
n = len(BLOCK_NAMES[self.name])
else:
_logger.debug("WARNING: unknown block name %s" % (self.name))
- n = 0
+ n = 0
for i in range(n):
if i == 1: # top
self.spr.set_label_attributes(int(self._font_size[1] + 0.5),
diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py
index 7565c4e..025c4f4 100644
--- a/TurtleArt/tautils.py
+++ b/TurtleArt/tautils.py
@@ -121,10 +121,9 @@ def _tuplify(tup):
def get_id(connection):
""" Get a connection block ID. """
- if connection is None:
- return None
- return connection.id
-
+ if connection is not None and hasattr(connection, 'id'):
+ return connection.id
+ return None
def json_dump(data):
""" Save data using available JSON tools. """
diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py
index f620958..1bc7ab8 100644
--- a/TurtleArt/tawindow.py
+++ b/TurtleArt/tawindow.py
@@ -1067,11 +1067,15 @@ class TurtleArtWindow():
cons = []
# Normally, it is simply a matter of copying the connections.
if blocks[i].connections is None:
- for c in block_data[i][4]:
- if c is None:
- cons.append(None)
- else:
- cons.append(blocks[c])
+ if block_data[i][4] is not None:
+ for c in block_data[i][4]:
+ if c is None or c > (len(blocks) - 1):
+ cons.append(None)
+ else:
+ cons.append(blocks[c])
+ else:
+ _logger.debug("connection error %s" % (str(block_data[i])))
+ cons.append(None)
elif blocks[i].connections == 'check':
# Convert old-style boolean and arithmetic blocks
cons.append(None) # Add an extra connection.
@@ -1145,7 +1149,7 @@ class TurtleArtWindow():
if i > 0 and c is not None:
bdock = blk.docks[i]
for j in range(len(c.docks)):
- if c.connections[j] == blk:
+ if j < len(c.connections) and c.connections[j] == blk:
cdock = c.docks[j]
nx = sx + bdock[2] - cdock[2]
ny = sy + bdock[3] - cdock[3]
@@ -1651,8 +1655,9 @@ class TurtleArtWindow():
best_destination.connections[best_destination_dockn] = \
selected_block
if selected_block.connections is not None:
- selected_block.connections[best_selected_block_dockn] = \
- best_destination
+ if best_selected_block_dockn < len(selected_block.connections):
+ selected_block.connections[best_selected_block_dockn] = \
+ best_destination
if best_destination.name in BOOLEAN_STYLE:
if best_destination_dockn == 2 and \
@@ -1688,8 +1693,9 @@ class TurtleArtWindow():
if collapsed(blk):
return
blk2 = blk.connections[0]
- c = blk2.connections.index(blk)
- blk2.connections[c] = None
+ if blk in blk2.connections:
+ c = blk2.connections.index(blk)
+ blk2.connections[c] = None
if blk2.name in BOOLEAN_STYLE:
if c == 2 and blk2.ey > 0:
@@ -2312,7 +2318,7 @@ class TurtleArtWindow():
_name = (_blk.name, self.block_scale)
else:
_name = (_blk.name)
- if hasattr(_blk, 'connections'):
+ if hasattr(_blk, 'connections') and _blk.connections is not None:
connections = [get_id(_cblk) for _cblk in _blk.connections]
else:
connections = None