Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt/tautils.py
diff options
context:
space:
mode:
Diffstat (limited to 'TurtleArt/tautils.py')
-rw-r--r--TurtleArt/tautils.py224
1 files changed, 0 insertions, 224 deletions
diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py
index dcbcf65..4bb4571 100644
--- a/TurtleArt/tautils.py
+++ b/TurtleArt/tautils.py
@@ -469,230 +469,6 @@ def collapse_clamp(top, transform=True):
return
-# Deprecated: Collapsible stacks live between 'sandwichtop' and
-# 'sandwichbottom' blocks
-
-
-def reset_stack_arm(top):
- ''' When we undock, retract the 'arm' that extends from 'sandwichtop'. '''
- if top is not None and top.name in ['sandwichtop', 'sandwichtop_no_label']:
- if top.ey > 0:
- top.reset_y()
- top.svg.set_hide(False)
- top.refresh()
-
-
-def grow_stack_arm(top):
- ''' When we dock, grow an 'arm' from 'sandwichtop'. '''
- if top is not None and top.name in ['sandwichtop', 'sandwichtop_no_label']:
- bot = find_sandwich_bottom(top)
- if bot is None:
- return
- if top.ey > 0:
- top.reset_y()
- ty = top.spr.get_xy()[1]
- th = top.spr.get_dimensions()[1]
- by = bot.spr.get_xy()[1]
- dy = by - (ty + th)
- if dy > 0:
- top.expand_in_y(dy / top.scale)
- top.svg.set_hide(True)
- top.refresh()
-
-
-def find_sandwich_top(blk):
- ''' Find the sandwich top above this block. '''
- # Always follow the main branch of a flow: the first connection.
- cblk = blk.connections[0]
- while cblk is not None:
- if cblk.name in COLLAPSIBLE:
- return None
- if cblk.name in ['repeat', 'if', 'ifelse', 'forever', 'while']:
- if blk != cblk.connections[len(cblk.connections) - 1]:
- return None
- if cblk.name in SANDWICHES:
- return cblk
- blk = cblk
- cblk = cblk.connections[0]
- return None
-
-
-def find_sandwich_bottom(blk):
- ''' Find the sandwich bottom below this block. '''
- # Always follow the main branch of a flow: the last connection.
- cblk = blk.connections[len(blk.connections) - 1]
- while cblk is not None:
- if cblk.name in SANDWICHES:
- return None
- if cblk.name in COLLAPSIBLE:
- return cblk
- cblk = cblk.connections[len(cblk.connections) - 1]
- return None
-
-
-def find_sandwich_top_below(blk):
- ''' Find the sandwich top below this block. '''
- if blk.name in SANDWICHES:
- return blk
- # Always follow the main branch of a flow: the last connection.
- cblk = blk.connections[len(blk.connections) - 1]
- while cblk is not None:
- if cblk.name in SANDWICHES:
- return cblk
- cblk = cblk.connections[len(cblk.connections) - 1]
- return None
-
-
-def restore_stack(top):
- ''' Restore the blocks between the sandwich top and sandwich bottom. '''
- group = find_group(top.connections[len(top.connections) - 1])
- hit_bottom = False
- bot = find_sandwich_bottom(top)
- for gblk in group:
- if not hit_bottom and gblk == bot:
- hit_bottom = True
- if len(gblk.values) == 0:
- gblk.values.append(0)
- else:
- gblk.values[0] = 0
- olddx = gblk.docks[1][2]
- olddy = gblk.docks[1][3]
- # Replace 'sandwichcollapsed' shape with 'sandwichbottom' shape
- gblk.name = 'sandwichbottom'
- gblk.spr.set_label(' ', 1)
- gblk.svg.set_show(False)
- gblk.svg.set_hide(True)
- gblk.refresh()
- # Redock to previous block in group
- you = gblk.connections[0]
- (yx, yy) = you.spr.get_xy()
- yd = you.docks[len(you.docks) - 1]
- (bx, by) = gblk.spr.get_xy()
- dx = yx + yd[2] - gblk.docks[0][2] - bx
- dy = yy + yd[3] - gblk.docks[0][3] - by
- gblk.spr.move_relative((dx, dy))
- # Since the shapes have changed, the dock positions have too.
- dx += gblk.docks[1][2] - olddx
- dy += gblk.docks[1][3] - olddy
- else:
- if not hit_bottom:
- gblk.spr.restore()
- gblk.status = None
- else:
- gblk.spr.move_relative((dx, dy))
- # Add 'sandwichtop' arm
- if top.name == 'sandwichtop_no_arm':
- top.name = 'sandwichtop'
- else:
- top.name = 'sandwichtop_no_label'
- top.spr.set_label(' ', 1)
- top.resize()
- top.refresh()
- grow_stack_arm(top)
-
-
-def uncollapse_forks(top, looping=False):
- ''' From the top, find and restore any collapsible stacks on forks. '''
- if top == None:
- return
- if looping and top.name in ['sandwichtop_no_arm',
- 'sandwichtop_no_arm_no_label']:
- restore_stack(top)
- return
- if len(top.connections) == 0:
- return
- cblk = top.connections[len(top.connections) - 1]
- while cblk is not None:
- if cblk.name in COLLAPSIBLE:
- return
- if cblk.name in ['sandwichtop_no_arm', 'sandwichtop_no_arm_no_label']:
- restore_stack(cblk)
- return
- # Follow a fork
- if cblk.name in ['repeat', 'if', 'ifelse', 'forever', 'while',
- 'until']:
- top = find_sandwich_top_below(
- cblk.connections[len(cblk.connections) - 2])
- if top is not None:
- uncollapse_forks(top, True)
- if cblk.name == 'ifelse':
- top = find_sandwich_top_below(
- cblk.connections[len(cblk.connections) - 3])
- if top is not None:
- uncollapse_forks(top, True)
- cblk = cblk.connections[len(cblk.connections) - 1]
- return
-
-
-def collapse_stack(top):
- ''' Hide all the blocks between the sandwich top and sandwich bottom. '''
- # First uncollapse any nested stacks
- if top == None or top.spr == None:
- return
-
- uncollapse_forks(top)
- hit_bottom = False
- bot = find_sandwich_bottom(top)
- group = find_group(top.connections[len(top.connections) - 1])
- for gblk in group:
- if not hit_bottom and gblk == bot:
- hit_bottom = True
- # Replace 'sandwichbottom' with invisible 'sandwichcollapsed'
- if len(gblk.values) == 0:
- gblk.values.append(1)
- else:
- gblk.values[0] = 1
- olddx = gblk.docks[1][2]
- olddy = gblk.docks[1][3]
- gblk.name = 'sandwichcollapsed'
- gblk.resize()
- you = find_sandwich_top(gblk)
- (yx, yy) = you.spr.get_xy()
- yd = you.docks[len(you.docks) - 1]
- (bx, by) = gblk.spr.get_xy()
- dx = yx + yd[2] - gblk.docks[0][2] - bx
- dy = yy + yd[3] - gblk.docks[0][3] - by
- gblk.spr.move_relative((dx, dy))
- # Since the shapes have changed, the dock positions have too.
- dx += gblk.docks[1][2] - olddx
- dy += gblk.docks[1][3] - olddy
- else:
- if not hit_bottom:
- gblk.spr.hide()
- gblk.status = 'collapsed'
- else:
- gblk.spr.move_relative((dx, dy))
- # Remove 'sandwichtop' arm
- if top.name == 'sandwichtop' or top.name == 'sandwichtop_no_arm':
- top.name = 'sandwichtop_no_arm'
- else:
- top.name = 'sandwichtop_no_arm_no_label'
- top.spr.set_label(' ')
- top.spr.set_label(' ', 1)
- top.resize()
- top.spr.set_label(_('click to open'), 1)
- top.resize()
- top.svg.set_hide(False)
- top.refresh()
-
-
-def collapsed(blk):
- ''' Is this stack collapsed? '''
- if blk is not None and blk.name in COLLAPSIBLE and\
- len(blk.values) == 1 and blk.values[0] != 0:
- return True
- return False
-
-
-def collapsible(blk):
- ''' Can this stack be collapsed? '''
- if blk is None or blk.name not in COLLAPSIBLE:
- return False
- if find_sandwich_top(blk) is None:
- return False
- return True
-
-
def hide_button_hit(spr, x, y):
''' Did the sprite's hide (contract) button get hit? '''
red, green, blue, alpha = spr.get_pixel((x, y))