Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tablock.py36
-rw-r--r--taconstants.py249
-rwxr-xr-xtasprite_factory.py19
-rw-r--r--tawindow.py28
4 files changed, 200 insertions, 132 deletions
diff --git a/tablock.py b/tablock.py
index 5c9df4d..a07f348 100644
--- a/tablock.py
+++ b/tablock.py
@@ -321,6 +321,10 @@ class Block:
self._make_flow_style_boolean(svg)
elif self.name in FLOW_STYLE_ELSE:
self._make_flow_style_else(svg)
+ elif self.name in COLLAPSIBLE_TOP:
+ self._make_collapsible_style_top(svg)
+ elif self.name in COLLAPSIBLE_BOTTOM:
+ self._make_collapsible_style_bottom(svg)
elif self.name in PORTFOLIO_STYLE_2x2:
self._make_portfolio_style_2x2(svg)
elif self.name in PORTFOLIO_STYLE_2x1:
@@ -622,6 +626,22 @@ class Block:
['flow', False, self.svg.docks[4][0],
self.svg.docks[4][1], ']']]
+ def _make_collapsible_style_top(self, svg):
+ self.svg.expand(self._dx+self._ex, self._ey)
+ self._make_collapsible_top_block(svg)
+ self.docks = [['flow', True, self.svg.docks[0][0],
+ self.svg.docks[0][1]],
+ ['number', False, self.svg.docks[1][0],
+ self.svg.docks[1][1]],
+ ['flow', False, self.svg.docks[2][0],
+ self.svg.docks[2][1]]]
+
+ def _make_collapsible_style_bottom(self, svg):
+ self.svg.expand(self._dx+self._ex, self._ey)
+ self._make_collapsible_bottom_block(svg)
+ self.docks = [['flow',True,self.svg.docks[0][0],self.svg.docks[0][1]],
+ ['flow',False,self.svg.docks[1][0],self.svg.docks[1][1]]]
+
# Depreciated block styles
def _make_portfolio_style_2x2(self, svg):
self.svg.expand(30+self._dx+self._ex, 10+self._ey)
@@ -703,6 +723,22 @@ class Block:
self.svg.set_stroke_color(SELECTED_COLOR)
self.shapes.append(svg_str_to_pixbuf(self.svg.basic_block()))
+ def _make_collapsible_top_block(self, svg):
+ self.shapes.append(svg_str_to_pixbuf(self.svg.sandwich_top()))
+ self.width = self.svg.get_width()
+ self.height = self.svg.get_height()
+ self.svg.set_stroke_width(SELECTED_STROKE_WIDTH)
+ self.svg.set_stroke_color(SELECTED_COLOR)
+ self.shapes.append(svg_str_to_pixbuf(self.svg.sandwich_top()))
+
+ def _make_collapsible_bottom_block(self, svg):
+ self.shapes.append(svg_str_to_pixbuf(self.svg.sandwich_bottom()))
+ self.width = self.svg.get_width()
+ self.height = self.svg.get_height()
+ self.svg.set_stroke_width(SELECTED_STROKE_WIDTH)
+ self.svg.set_stroke_color(SELECTED_COLOR)
+ self.shapes.append(svg_str_to_pixbuf(self.svg.sandwich_bottom()))
+
def _make_basic_box(self, svg):
self.shapes.append(svg_str_to_pixbuf(self.svg.basic_box()))
self.width = self.svg.get_width()
diff --git a/taconstants.py b/taconstants.py
index a515e78..10f90b0 100644
--- a/taconstants.py
+++ b/taconstants.py
@@ -174,7 +174,7 @@ BASIC_STYLE_TAIL = ['stopstack', 'empty']
BASIC_STYLE = ['clean', 'penup', 'pendown', 'stack1', 'stack2', 'vspace',
'hideblocks', 'showblocks', 'clearheap', 'printheap', 'kbinput',
'picturelist', 'picture1x1', 'picture2x2', 'picture2x1', 'picture1x2',
- 'fullscreen', 'sandwichtop', 'sandwichbottom']
+ 'fullscreen']
BASIC_STYLE_1ARG = ['forward', 'back', 'left', 'right', 'seth', 'show',
'setscale', 'setpensize', 'setcolor', 'setshade', 'print', 'showaligned',
'settextsize', 'settextcolor', 'print', 'wait', 'storeinbox1', 'savepix',
@@ -199,6 +199,8 @@ FLOW_STYLE = ['forever', 'hspace']
FLOW_STYLE_1ARG = ['repeat']
FLOW_STYLE_BOOLEAN = ['if']
FLOW_STYLE_ELSE = ['ifelse']
+COLLAPSIBLE_TOP = ['sandwichtop']
+COLLAPSIBLE_BOTTOM = ['sandwichbottom']
# Depreciated block styles
PORTFOLIO_STYLE_2x2 = ['template2x2']
@@ -224,134 +226,129 @@ MACROS = {
[9, 'wait', 0, 0, [8, 10, None]],
[10, ['number', '1'], 0, 0, [9, None]]],
'picturelist':
- [[0, 'comment', 0, 0, [None, 1, 2]],
+ [[0, 'sandwichtop', 0, 0, [None, 1, 2]],
[1, ['string', _('bulleted list')], 0, 0, [0, None]],
- [2, 'sandwichtop', 0, 0, [0, 3]],
- [3, 'setxy', 0, 0, [2, 4, 5, 6]],
- [4, 'titlex', 0, 0, [3, None]],
- [5, 'titley', 0, 0, [3, None]],
- [6, 'show', 0, 0, [3, 7, 8]],
- [7, ['string',_('Title')], 0, 0, [6, None]],
- [8, 'setxy', 0, 0, [6, 9, 10, 11]],
- [9, 'leftx', 0, 0, [8, None]],
- [10, 'topy', 0, 0, [8, None]],
- [11, 'list', 0, 0, [8, 12, 13, 14]],
- [12, ['string','∙ '], 0, 0, [11, None]],
- [13, ['string','∙ '], 0, 0, [11, None]],
- [14, 'sandwichbottom', 0, 0, [11, None]]],
+ [2, 'setxy', 0, 0, [0, 3, 4, 5]],
+ [3, 'titlex', 0, 0, [2, None]],
+ [4, 'titley', 0, 0, [2, None]],
+ [5, 'show', 0, 0, [2, 6, 7]],
+ [6, ['string',_('Title')], 0, 0, [5, None]],
+ [7, 'setxy', 0, 0, [5, 8, 9, 10]],
+ [8, 'leftx', 0, 0, [7, None]],
+ [9, 'topy', 0, 0, [7, None]],
+ [10, 'list', 0, 0, [7, 11, 12, 13]],
+ [11, ['string','∙ '], 0, 0, [10, None]],
+ [12, ['string','∙ '], 0, 0, [10, None]],
+ [13, 'sandwichbottom', 0, 0, [10, None]]],
'picture1x1':
- [[0, 'comment', 0, 0, [None, 1, 2]],
+ [[0, 'sandwichtop', 0, 0, [None, 1, 2]],
[1, ['string', _('picture')], 0, 0, [0, None]],
- [2, 'sandwichtop', 0, 0, [0, 3]],
- [3, 'setxy', 0, 0, [2, 4, 5, 6]],
- [4, 'titlex', 0, 0, [3, None]],
- [5, 'titley', 0, 0, [3, None]],
- [6, 'show', 0, 0, [3, 7, 8]],
- [7, ['string',_('Title')], 0, 0, [6, None]],
- [8, 'setscale', 0, 0, [6, 9, 10]],
- [9, ['number', '90'], 0, 0, [8, None]],
- [10, 'setxy', 0, 0, [8, 11, 12, 13]],
- [11, 'leftx', 0, 0, [10, None]],
- [12, 'topy', 0, 0, [10, None]],
- [13, 'showaligned', 0, 0, [10, 14, 15]],
- [14, 'journal', 0, 0, [13, None]],
- [15, 'sandwichbottom', 0, 0, [13, None]]],
+ [2, 'setxy', 0, 0, [0, 3, 4, 5]],
+ [3, 'titlex', 0, 0, [2, None]],
+ [4, 'titley', 0, 0, [2, None]],
+ [5, 'show', 0, 0, [2, 6, 7]],
+ [6, ['string',_('Title')], 0, 0, [5, None]],
+ [7, 'setscale', 0, 0, [5, 8, 9]],
+ [8, ['number', '90'], 0, 0, [7, None]],
+ [9, 'setxy', 0, 0, [7, 10, 11, 12]],
+ [10, 'leftx', 0, 0, [9, None]],
+ [11, 'topy', 0, 0, [9, None]],
+ [12, 'showaligned', 0, 0, [9, 13, 14]],
+ [13, 'journal', 0, 0, [12, None]],
+ [14, 'sandwichbottom', 0, 0, [12, None]]],
'picture2x2':
- [[0, 'comment', 0, 0, [None, 1, 2]],
+ [[0, 'sandwichtop', 0, 0, [None, 1, 2]],
[1, ['string', _('2×2 pictures')], 0, 0, [0, None]],
- [2, 'sandwichtop', 0, 0, [0, 3]],
- [3, 'setxy', 0, 0, [2, 4, 5, 6]],
- [4, 'titlex', 0, 0, [3, None]],
- [5, 'titley', 0, 0, [3, None]],
- [6, 'show', 0, 0, [3, 7, 8]],
- [7, ['string',_('Title')], 0, 0, [6, None]],
- [8, 'setscale', 0, 0, [6, 9, 10]],
- [9, ['number', '45'], 0, 0, [8, None]],
- [10, 'setxy', 0, 0, [8, 11, 12, 13]],
- [11, 'leftx', 0, 0, [10, None]],
- [12, 'topy', 0, 0, [10, None]],
- [13, 'showaligned', 0, 0, [10, 14, 15]],
- [14, 'journal', 0, 0, [13, None]],
- [15, 'setxy', 0, 0, [13, 16, 17, 18]],
- [16, 'rightx', 0, 0, [15, None]],
- [17, 'topy', 0, 0, [15, None]],
- [18, 'showaligned', 0, 0, [15, 19, 20]],
- [19, 'journal', 0, 0, [18, None]],
- [20, 'setxy', 0, 0, [18, 21, 22, 23]],
- [21, 'leftx', 0, 0, [20, None]],
- [22, 'bottomy', 0, 0, [20, None]],
- [23, 'showaligned', 0, 0, [20, 24, 25]],
- [24, 'journal', 0, 0, [23, None]],
- [25, 'setxy', 0, 0, [23, 26, 27, 28]],
- [26, 'rightx', 0, 0, [25, None]],
- [27, 'bottomy', 0, 0, [25, None]],
- [28, 'showaligned', 0, 0, [25, 29, 30]],
- [29, 'journal', 0, 0, [28, None]],
- [30, 'sandwichbottom', 0, 0, [28, None]]],
+ [2, 'setxy', 0, 0, [0, 3, 4, 5]],
+ [3, 'titlex', 0, 0, [2, None]],
+ [4, 'titley', 0, 0, [2, None]],
+ [5, 'show', 0, 0, [2, 6, 7]],
+ [6, ['string',_('Title')], 0, 0, [5, None]],
+ [7, 'setscale', 0, 0, [5, 8, 9]],
+ [8, ['number', '90'], 0, 0, [7, None]],
+ [9, 'setxy', 0, 0, [7, 10, 11, 12]],
+ [10, 'leftx', 0, 0, [9, None]],
+ [11, 'topy', 0, 0, [9, None]],
+ [12, 'showaligned', 0, 0, [9, 13, 14]],
+ [13, 'journal', 0, 0, [12, None]],
+ [14, 'setxy', 0, 0, [12, 15, 16, 17]],
+ [15, 'rightx', 0, 0, [14, None]],
+ [16, 'topy', 0, 0, [14, None]],
+ [17, 'showaligned', 0, 0, [14, 18, 19]],
+ [18, 'journal', 0, 0, [17, None]],
+ [19, 'setxy', 0, 0, [17, 20, 21, 22]],
+ [20, 'leftx', 0, 0, [19, None]],
+ [21, 'bottomy', 0, 0, [19, None]],
+ [22, 'showaligned', 0, 0, [19, 23, 24]],
+ [23, 'journal', 0, 0, [22, None]],
+ [24, 'setxy', 0, 0, [22, 25, 26, 27]],
+ [25, 'rightx', 0, 0, [24, None]],
+ [26, 'bottomy', 0, 0, [24, None]],
+ [27, 'showaligned', 0, 0, [24, 28, 29]],
+ [28, 'journal', 0, 0, [27, None]],
+ [29, 'sandwichbottom', 0, 0, [27, None]]],
'picture2x1':
- [[0, 'comment', 0, 0, [None, 1, 2]],
+ [[0, 'sandwichtop', 0, 0, [None, 1, 2]],
[1, ['string', _('2×1 pictures')], 0, 0, [0, None]],
- [2, 'sandwichtop', 0, 0, [0, 3]],
- [3, 'setxy', 0, 0, [2, 4, 5, 6]],
- [4, 'titlex', 0, 0, [3, None]],
- [5, 'titley', 0, 0, [3, None]],
- [6, 'show', 0, 0, [3, 7, 8]],
- [7, ['string',_('Title')], 0, 0, [6, None]],
- [8, 'setscale', 0, 0, [6, 9, 10]],
- [9, ['number', '45'], 0, 0, [8, None]],
- [10, 'setxy', 0, 0, [8, 11, 12, 13]],
- [11, 'leftx', 0, 0, [10, None]],
- [12, 'topy', 0, 0, [10, None]],
- [13, 'showaligned', 0, 0, [10, 14, 15]],
- [14, 'journal', 0, 0, [13, None]],
- [15, 'setxy', 0, 0, [13, 16, 17, 18]],
- [16, 'rightx', 0, 0, [15, None]],
- [17, 'topy', 0, 0, [15, None]],
- [18, 'showaligned', 0, 0, [15, 19, 20]],
- [19, 'journal', 0, 0, [18, None]],
- [20, 'setxy', 0, 0, [18, 21, 22, 23]],
- [21, 'leftx', 0, 0, [20, None]],
- [22, 'bottomy', 0, 0, [20, None]],
- [23, 'showaligned', 0, 0, [20, 24, 25]],
- [24, 'description', 0, 0, [23, None]],
- [25, 'setxy', 0, 0, [23, 26, 27, 28]],
- [26, 'rightx', 0, 0, [25, None]],
- [27, 'bottomy', 0, 0, [25, None]],
- [28, 'showaligned', 0, 0, [25, 29, 30]],
- [29, 'description', 0, 0, [28, None]],
- [30, 'sandwichbottom', 0, 0, [28, None]]],
+ [2, 'setxy', 0, 0, [0, 3, 4, 5]],
+ [3, 'titlex', 0, 0, [2, None]],
+ [4, 'titley', 0, 0, [2, None]],
+ [5, 'show', 0, 0, [2, 6, 7]],
+ [6, ['string',_('Title')], 0, 0, [5, None]],
+ [7, 'setscale', 0, 0, [5, 8, 9]],
+ [8, ['number', '90'], 0, 0, [7, None]],
+ [9, 'setxy', 0, 0, [7, 10, 11, 12]],
+ [10, 'leftx', 0, 0, [9, None]],
+ [11, 'topy', 0, 0, [9, None]],
+ [12, 'showaligned', 0, 0, [9, 13, 14]],
+ [13, 'journal', 0, 0, [12, None]],
+ [14, 'setxy', 0, 0, [12, 15, 16, 17]],
+ [15, 'rightx', 0, 0, [14, None]],
+ [16, 'topy', 0, 0, [14, None]],
+ [17, 'showaligned', 0, 0, [14, 18, 19]],
+ [18, 'journal', 0, 0, [17, None]],
+ [19, 'setxy', 0, 0, [17, 20, 21, 22]],
+ [20, 'leftx', 0, 0, [19, None]],
+ [21, 'bottomy', 0, 0, [19, None]],
+ [22, 'showaligned', 0, 0, [19, 23, 24]],
+ [23, 'description', 0, 0, [22, None]],
+ [24, 'setxy', 0, 0, [22, 25, 26, 27]],
+ [25, 'rightx', 0, 0, [24, None]],
+ [26, 'bottomy', 0, 0, [24, None]],
+ [27, 'showaligned', 0, 0, [24, 28, 29]],
+ [28, 'description', 0, 0, [27, None]],
+ [29, 'sandwichbottom', 0, 0, [27, None]]],
'picture1x2':
- [[0, 'comment', 0, 0, [None, 1, 2]],
+ [[0, 'sandwichtop', 0, 0, [None, 1, 2]],
[1, ['string', _('1×2 pictures')], 0, 0, [0, None]],
- [2, 'sandwichtop', 0, 0, [0, 3]],
- [3, 'setxy', 0, 0, [2, 4, 5, 6]],
- [4, 'titlex', 0, 0, [3, None]],
- [5, 'titley', 0, 0, [3, None]],
- [6, 'show', 0, 0, [3, 7, 8]],
- [7, ['string',_('Title')], 0, 0, [6, None]],
- [8, 'setscale', 0, 0, [6, 9, 10]],
- [9, ['number', '45'], 0, 0, [8, None]],
- [10, 'setxy', 0, 0, [8, 11, 12, 13]],
- [11, 'leftx', 0, 0, [10, None]],
- [12, 'topy', 0, 0, [10, None]],
- [13, 'showaligned', 0, 0, [10, 14, 15]],
- [14, 'journal', 0, 0, [13, None]],
- [15, 'setxy', 0, 0, [13, 16, 17, 18]],
- [16, 'rightx', 0, 0, [15, None]],
- [17, 'topy', 0, 0, [15, None]],
- [18, 'showaligned', 0, 0, [15, 19, 20]],
- [19, 'description', 0, 0, [18, None]],
- [20, 'setxy', 0, 0, [18, 21, 22, 23]],
- [21, 'leftx', 0, 0, [20, None]],
- [22, 'bottomy', 0, 0, [20, None]],
- [23, 'showaligned', 0, 0, [20, 24, 25]],
- [24, 'journal', 0, 0, [23, None]],
- [25, 'setxy', 0, 0, [23, 26, 27, 28]],
- [26, 'rightx', 0, 0, [25, None]],
- [27, 'bottomy', 0, 0, [25, None]],
- [28, 'showaligned', 0, 0, [25, 29, 30]],
- [29, 'description', 0, 0, [28, None]],
- [30, 'sandwichbottom', 0, 0, [28, None]]]
+ [2, 'setxy', 0, 0, [0, 3, 4, 5]],
+ [3, 'titlex', 0, 0, [2, None]],
+ [4, 'titley', 0, 0, [2, None]],
+ [5, 'show', 0, 0, [2, 6, 7]],
+ [6, ['string',_('Title')], 0, 0, [5, None]],
+ [7, 'setscale', 0, 0, [5, 8, 9]],
+ [8, ['number', '90'], 0, 0, [7, None]],
+ [9, 'setxy', 0, 0, [7, 10, 11, 12]],
+ [10, 'leftx', 0, 0, [9, None]],
+ [11, 'topy', 0, 0, [9, None]],
+ [12, 'showaligned', 0, 0, [9, 13, 14]],
+ [13, 'journal', 0, 0, [12, None]],
+ [14, 'setxy', 0, 0, [12, 15, 16, 17]],
+ [15, 'rightx', 0, 0, [14, None]],
+ [16, 'topy', 0, 0, [14, None]],
+ [17, 'showaligned', 0, 0, [14, 18, 19]],
+ [18, 'description', 0, 0, [17, None]],
+ [19, 'setxy', 0, 0, [17, 20, 21, 22]],
+ [20, 'leftx', 0, 0, [19, None]],
+ [21, 'bottomy', 0, 0, [19, None]],
+ [22, 'showaligned', 0, 0, [19, 23, 24]],
+ [23, 'journal', 0, 0, [22, None]],
+ [24, 'setxy', 0, 0, [22, 25, 26, 27]],
+ [25, 'rightx', 0, 0, [24, None]],
+ [26, 'bottomy', 0, 0, [24, None]],
+ [27, 'showaligned', 0, 0, [24, 28, 29]],
+ [28, 'description', 0, 0, [27, None]],
+ [29, 'sandwichbottom', 0, 0, [27, None]]]
}
#
@@ -360,6 +357,11 @@ MACROS = {
EXPANDABLE = ['vspace', 'hspace', 'templatelist', 'list', 'identity2', 'myfunc']
#
+# Blocks that are 'collapsible'
+#
+COLLAPSIBLE = ['sandwichbottom']
+
+#
# Depreciated block styles that need dock adjustments
#
OLD_DOCK = ['and', 'or', 'plus', 'minus', 'division', 'product', 'remainder']
@@ -449,8 +451,8 @@ BLOCK_NAMES = {
'rightx':[_('picture right')],
'savepix':[_('save picture')],
'scale':[_('scale')],
- 'sandwichtop':[_('top of stack')],
- 'sandwichbottom':[_('bottom of stack')],
+ 'sandwichtop':['top of stack'],
+ 'sandwichbottom':[''],
'setcolor':[_('set color')],
'seth':[_('set heading')],
'setpensize':[_('set pen size')],
@@ -559,7 +561,7 @@ PRIMITIVES = {
'right':'right',
'rightpos':'rpos',
'rightx':'rightx',
- 'sandwichtop':'nop',
+ 'sandwichtop':'comment',
'sandwichbottom':'nop',
'savepix':'savepix',
'scale':'scale',
@@ -630,6 +632,7 @@ DEFAULTS = {
'random':[0, 100],
'repeat':[4, None, 'vspace'],
'right':[90],
+ 'sandwichtop':[_('label')],
'savepix':[_('picture name')],
'setcolor':[0],
'seth':[0],
diff --git a/tasprite_factory.py b/tasprite_factory.py
index ef52545..709c212 100755
--- a/tasprite_factory.py
+++ b/tasprite_factory.py
@@ -360,10 +360,21 @@ class SVG:
svg += self._corner(1, -1)
svg += self._rline_to(self._radius+self._stroke_width, 0)
svg += self._do_slot()
+ #
+ svg += self._rline_to(self._expand_x, 0)
+ xx = self._x
svg += self._corner(1, 1)
- svg += self._rline_to(-self._radius,0)
+ svg += self._do_innie()
+ svg += self._corner(-1, 1)
+ svg += self._line_to(xx, self._y)
+ svg += self._rline_to(-self._expand_x, 0)
+ #
+ # svg += self._corner(1, 1)
+ # svg += self._rline_to(-self._radius,0)
+ #
svg += self._do_tab()
svg += self._inverse_corner(-1, 1, 90, 0, 0)
+ svg += self._rline_to(0, self._expand_y)
svg += self._rline_to(-self._radius, 0)
svg += self._close_path()
self._calculate_w_h()
@@ -376,6 +387,7 @@ class SVG:
y = self._stroke_width/2.0
svg = self._new_path(x, y)
svg += self._rline_to(self._radius, 0)
+ svg += self._rline_to(0, self._expand_y)
svg += self._inverse_corner(1, 1, 90, 0, 0)
svg += self._do_slot()
svg += self._rline_to(self._radius, 0)
@@ -891,6 +903,7 @@ def generator(datapath):
svg0.set_slot(True)
svg0.set_hide(True)
svg0.set_show(True)
+ svg0.expand(0,40)
svg_str = svg0.sandwich_bottom()
f.write(svg_str)
close_file(f)
@@ -902,11 +915,12 @@ def generator(datapath):
svg0.set_slot(True)
svg0.set_hide(True)
svg0.set_show(True)
+ svg0.expand(0,40)
svg_str = svg0.sandwich_top()
f.write(svg_str)
close_file(f)
-
+ """
svg2 = SVG()
f = open_file(datapath, "box-test.svg")
svg2.set_scale(1)
@@ -927,7 +941,6 @@ def generator(datapath):
f.write(svg_str)
close_file(f)
- """
svg3 = SVG()
f = open_file(datapath, "compare-text.svg")
svg3.set_scale(1)
diff --git a/tawindow.py b/tawindow.py
index dc5e390..500da15 100644
--- a/tawindow.py
+++ b/tawindow.py
@@ -691,15 +691,17 @@ class TurtleArtWindow():
group = self._find_group(blk)
for b in group:
b.rescale(self.block_scale)
- if blk.status != 'collapsed':
- b.spr.set_layer(BLOCK_LAYER)
+ b.spr.set_layer(BLOCK_LAYER)
x,y = b.spr.get_xy()
b.spr.move((x+PALETTE_WIDTH,y+PALETTE_HEIGHT))
b.type = 'block'
for b in group:
self._adjust_dock_positions(b)
+ # If the stack had been collapsed before going into the trash,
+ # collapse it again now.
+ for b in group:
if self._collapsed(b):
- b.spr.move_relative((0, b.values[0]))
+ self._collapse_stack(self._find_sandwich_top(b))
self.trash_stack.remove(blk)
"""
@@ -1085,12 +1087,17 @@ class TurtleArtWindow():
blk = self.drag_group[0]
# Remove blocks by dragging them onto the trash palette.
- # Collapsed stacks are restored as they are moved to the trash.
if self.block_operation=='move' and self._in_the_trash(x, y):
self.trash_stack.append(blk)
for b in self.drag_group:
+ # Collapsed stacks are restored as they are moved to the trash,
if b.status == 'collapsed':
- self._restore_stack(self._find_sandwich_top(b))
+ bot = self._find_sandwich_bottom(b)
+ if self._collapsed(bot):
+ dy = bot.values[0]
+ self._restore_stack(self._find_sandwich_top(b))
+ # but we note that they were collapsed.
+ bot.values[0] = dy
b.type = 'trash'
b.rescale(self.trash_scale)
blk.spr.move((x,y))
@@ -1217,6 +1224,15 @@ class TurtleArtWindow():
b = b.connections[0]
return None
+ def _find_sandwich_bottom(self, blk):
+ # TODO: Add nesting; detect branches (e.g., if, ifelse, repeat)
+ b = blk.connections[0]
+ while b is not None:
+ if b.name == 'sandwichbottom':
+ return b
+ b = b.connections[0]
+ return None
+
def _collapse_stack(self, top):
group = self._find_group(top.connections[len(top.connections)-1])
if group[0].name in COLLAPSIBLE:
@@ -1251,7 +1267,7 @@ class TurtleArtWindow():
b.spr.move_relative((0,-dy))
def _collapsed(self, blk):
- if blk.name in COLLAPSIBLE and\
+ if blk is not None and blk.name in COLLAPSIBLE and\
len(blk.values) == 1 and blk.values[0] != 0:
return True
return False