From b374e3b2c4a62b33d6eef308dcf5018ce6168096 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Wed, 08 Sep 2010 17:36:59 +0000 Subject: added collapsible block without comment label as per #2302 --- diff --git a/TurtleArt/tablock.py b/TurtleArt/tablock.py index 3f678c7..ab90373 100644 --- a/TurtleArt/tablock.py +++ b/TurtleArt/tablock.py @@ -105,7 +105,7 @@ class Block: # If there is already a block with the same name, reuse it copy_block = None if self.name not in EXPANDABLE and \ - self.name not in ['string', 'sandwichtop']: + self.name not in ['string', 'sandwichtop', 'sandwichtop_no_label']: for b in block_list.list: if b.scale == self.scale and b.name == self.name: copy_block = b @@ -390,7 +390,11 @@ class Block: elif self.name in COLLAPSIBLE_TOP: self._make_collapsible_style_top(svg) elif self.name in COLLAPSIBLE_TOP_NO_ARM: - self._make_collapsible_style_top(svg, True) + self._make_collapsible_style_top(svg, no_arm=True) + elif self.name in COLLAPSIBLE_TOP_NO_LABEL: + self._make_collapsible_style_top(svg, label=False) + elif self.name in COLLAPSIBLE_TOP_NO_ARM_NO_LABEL: + self._make_collapsible_style_top(svg, no_arm=True, label=False) elif self.name in COLLAPSIBLE_BOTTOM: self._make_collapsible_style_bottom(svg) elif self.name in PORTFOLIO_STYLE_2x2: @@ -729,16 +733,22 @@ class Block: ['flow', False, self.svg.docks[4][0], self.svg.docks[4][1], ']']] - def _make_collapsible_style_top(self, svg, no_arm=False): + def _make_collapsible_style_top(self, svg, no_arm=False, label=True): self.svg.expand(self.dx+self.ex, self.ey) self.svg.set_no_arm(no_arm) - self._make_block_graphics(svg, self.svg.sandwich_top) - 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]]] + self._make_block_graphics(svg, self.svg.sandwich_top, label) + if label: + 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]]] + else: + 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]]] def _make_collapsible_style_bottom(self, svg): self.svg.expand(self.dx+self.ex, self.ey) @@ -819,11 +829,16 @@ class Block: ['flow', False, self.svg.docks[1][0], self.svg.docks[1][1]]] - def _make_block_graphics(self, svg, function): - self.shapes[0] = svg_str_to_pixbuf(function()) + def _make_block_graphics(self, svg, function, arg=None): + if arg is None: + self.shapes[0] = svg_str_to_pixbuf(function()) + else: + self.shapes[0] = svg_str_to_pixbuf(function(arg)) 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[1] = svg_str_to_pixbuf(function()) - + if arg is None: + self.shapes[1] = svg_str_to_pixbuf(function()) + else: + self.shapes[1] = svg_str_to_pixbuf(function(arg)) diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py index 8c7eac9..ecef0c1 100644 --- a/TurtleArt/taconstants.py +++ b/TurtleArt/taconstants.py @@ -134,7 +134,7 @@ PALETTES = [['clean', 'forward', 'back', 'show', 'left', 'right', 'storein', 'start'], ['kbinput', 'push', 'printheap', 'keyboard', 'pop', 'clearheap', 'myfunc1arg', 'userdefined', 'addturtle', 'comment', 'print', - 'cartesian', 'width', 'height', 'polar', 'sandwichtop', + 'cartesian', 'width', 'height', 'polar', 'sandwichtop_no_label', 'sandwichbottom', 'readpixel', 'see'], ['journal', 'audio', 'description', 'hideblocks', 'showblocks', 'fullscreen', 'savepix', 'savesvg', 'picturelist', @@ -217,7 +217,9 @@ FLOW_STYLE_BOOLEAN = ['if', 'while', 'until'] FLOW_STYLE_WHILE = ['while2'] FLOW_STYLE_ELSE = ['ifelse'] COLLAPSIBLE_TOP = ['sandwichtop'] -COLLAPSIBLE_TOP_NO_ARM = ['sandwichtop2'] +COLLAPSIBLE_TOP_NO_ARM = ['sandwichtop_no_arm'] +COLLAPSIBLE_TOP_NO_LABEL = ['sandwichtop_no_label'] +COLLAPSIBLE_TOP_NO_ARM_NO_LABEL = ['sandwichtop_no_arm_no_label'] COLLAPSIBLE_BOTTOM = ['sandwichbottom'] # Depreciated block styles @@ -352,7 +354,9 @@ BLOCK_NAMES = { 'sandwichbottom':[' '], 'sandwichcollapsed':[_('click to open')], 'sandwichtop':[_('top of stack')], - 'sandwichtop2':[_('top of stack')], + 'sandwichtop_no_label':[' '], + 'sandwichtop_no_arm':[_('top of stack')], + 'sandwichtop_no_arm_no_label':[' '], 'scale':[_('scale')], 'see':[_('turtle sees')], 'setcolor':[_('set color')], @@ -489,7 +493,9 @@ PRIMITIVES = { 'rightpos':'rpos', 'rightx':'rightx', 'sandwichtop':'comment', - 'sandwichtop2':'comment', + 'sandwichtop_no_arm':'comment', + 'sandwichtop_no_label':'nop', + 'sandwichtop_no_arm_no_label':'nop', 'sandwichbottom':'nop', 'sandwichcollapsed':'nop', 'savepix':'savepix', @@ -578,7 +584,7 @@ DEFAULTS = { 'repeat':[4, None, 'vspace'], 'right':[90], 'sandwichtop':[_('label')], - 'sandwichtop2':[_('label')], + 'sandwichtop_no_arm':[_('label')], 'savepix':[_('picture name')], 'savesvg':[_('picture name')], 'setcolor':[0], @@ -617,7 +623,7 @@ STRING_OR_NUMBER_ARGS = ['plus2', 'equal2', 'less2', 'greater2', 'box', 'template2x2', 'template1x1a', 'templatelist', 'nop', 'print', 'stack', 'hat', 'addturtle', 'myfunc', 'myfunc1arg', 'myfunc2arg', 'myfunc3arg', 'comment', - 'sandwichtop', 'sandwichtop2', 'userdefined', + 'sandwichtop', 'sandwichtop_no_arm', 'userdefined', 'userdefined2args', 'userdefined3args', 'storein'] CONTENT_ARGS = ['show', 'showaligned', 'push', 'storein', 'storeinbox1', @@ -656,7 +662,8 @@ OLD_NAMES = {'product':'product2', 'storeinbox':'storein', 'minus':'minus2', 'descriptionoff':'description','template3':'templatelist', 'template1':'template1x1', 'template2':'template2x1', 'template6':'template1x2', 'template7':'template2x2', - 'template4':'template1x1a', 'hres':'width', 'vres':'height' } + 'template4':'template1x1a', 'hres':'width', 'vres':'height', + 'sandwichtop2':'sandwichtop_no_arm'} # # Define the relative size and postion of media objects @@ -800,7 +807,9 @@ HELP_STRINGS = { 'sandwichbottom':_("bottom block in a collapsibe stack: click to collapse"), 'sandwichcollapsed':_("bottom block in a collapsed stack: click to open"), 'sandwichtop':_("top of a collapsible stack"), - 'sandwichtop2':_("top of a collapsed stack"), + 'sandwichtop_no_label':_("top of a collapsed stack"), + 'sandwichtop_no_arm':_("top of a collapsible stack"), + 'sandwichtop_no_arm_no_label':_("top of a collapsed stack"), 'savepix':_("saves a picture to the Sugar Journal"), 'savesvg':_("saves turtle graphics as an SVG file in the Sugar Journal"), 'scale':_("holds current scale value"), diff --git a/TurtleArt/tasprite_factory.py b/TurtleArt/tasprite_factory.py index 35424a8..7456689 100755 --- a/TurtleArt/tasprite_factory.py +++ b/TurtleArt/tasprite_factory.py @@ -411,7 +411,7 @@ class SVG: svg += self.footer() return self.header() + svg - def sandwich_top(self): + def sandwich_top(self, innie_flag=True): self.reset_min_max() x = self._stroke_width/2.0 y = self._stroke_width/2.0+self._radius @@ -426,7 +426,8 @@ class SVG: svg += self._rline_to(self._expand_x, 0) xx = self._x svg += self._corner(1, 1) - svg += self._do_innie() + if innie_flag: + svg += self._do_innie() svg += self._corner(-1, 1) svg += self.line_to(xx, self._y) svg += self._rline_to(-self._expand_x, 0) diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py index e7888ea..9b19f24 100644 --- a/TurtleArt/tautils.py +++ b/TurtleArt/tautils.py @@ -292,13 +292,13 @@ def calc_image_size(spr): def reset_stack_arm(top): """ When we undock, retract the 'arm' that extends from 'sandwichtop'. """ - if top is not None and top.name == 'sandwichtop': + if top is not None and top.name in ['sandwichtop', 'sandwichtop_no_label']: if top.ey > 0: top.reset_y() def grow_stack_arm(top): """ When we dock, grow an 'arm' from 'sandwichtop'. """ - if top is not None and top.name == 'sandwichtop': + if top is not None and top.name in ['sandwichtop', 'sandwichtop_no_label']: _bot = find_sandwich_bottom(top) if _bot is None: return @@ -322,7 +322,8 @@ def find_sandwich_top(blk): if _blk.name in ['repeat', 'if', 'ifelse', 'forever', 'while']: if blk != _blk.connections[len(_blk.connections) - 1]: return None - if _blk.name == 'sandwichtop' or _blk.name == 'sandwichtop2': + if _blk.name in ['sandwichtop', 'sandwichtop_no_label', + 'sandwichtop_no_arm', 'sandwichtop_no_arm_no_label']: return _blk blk = _blk _blk = _blk.connections[0] @@ -333,7 +334,8 @@ def find_sandwich_bottom(blk): # Always follow the main branch of a flow: the last connection. _blk = blk.connections[len(blk.connections) - 1] while _blk is not None: - if _blk.name == 'sandwichtop' or _blk.name == 'sandwichtop2': + if _blk.name in ['sandwichtop', 'sandwichtop_no_label', + 'sandwichtop_no_arm', 'sandwichtop_no_arm_no_label']: return None if _blk.name in COLLAPSIBLE: return _blk @@ -342,12 +344,14 @@ def find_sandwich_bottom(blk): def find_sandwich_top_below(blk): """ Find the sandwich top below this block. """ - if blk.name == 'sandwichtop' or blk.name == 'sandwichtop2': + if blk.name in ['sandwichtop', 'sandwichtop_no_label', 'sandwichtop_no_arm', + 'sandwichtop_no_arm_no_label']: return blk # Always follow the main branch of a flow: the last connection. _blk = blk.connections[len(blk.connections) - 1] while _blk is not None: - if _blk.name == 'sandwichtop' or _blk.name == 'sandwichtop2': + if _blk.name in ['sandwichtop', 'sandwichtop_no_label', + 'sandwichtop_no_arm', 'sandwichtop_no_arm_no_label']: return _blk _blk = _blk.connections[len(_blk.connections) - 1] return None @@ -372,7 +376,7 @@ def restore_stack(top): _blk.svg.set_show(False) _blk.svg.set_hide(True) _blk.refresh() - # Redock to previous block in group + # Redock to previous block in group _you = _blk.connections[0] (_yx, _yy) = _you.spr.get_xy() _yd = _you.docks[len(_you.docks) - 1] @@ -380,7 +384,7 @@ def restore_stack(top): _dx = _yx + _yd[2] - _blk.docks[0][2] - _bx _dy = _yy + _yd[3] - _blk.docks[0][3] - _by _blk.spr.move_relative((_dx, _dy)) - # Since the shapes have changed, the dock positions have too. + # Since the shapes have changed, the dock positions have too. _newdx = _blk.docks[1][2] _newdy = _blk.docks[1][3] _dx += _newdx - _olddx @@ -391,8 +395,11 @@ def restore_stack(top): _blk.status = None else: _blk.spr.move_relative((_dx, _dy)) - # Add 'sandwichtop' arm - top.name = 'sandwichtop' + # Add 'sandwichtop' arm + if top.name == 'sandwichtop_no_arm': + top.name = 'sandwichtop' + else: + top.name = 'sandwichtop_no_label' top.refresh() grow_stack_arm(top) @@ -400,7 +407,8 @@ 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 == 'sandwichtop' or top.name == 'sandwichtop2': + if looping and top.name in ['sandwichtop_no_arm', + 'sandwichtop_no_arm_no_label']: restore_stack(top) return if len(top.connections) == 0: @@ -409,7 +417,7 @@ def uncollapse_forks(top, looping=False): while _blk is not None: if _blk.name in COLLAPSIBLE: return - if _blk.name == 'sandwichtop' or _blk.name == 'sandwichtop2': + if _blk.name in ['sandwichtop_no_arm', 'sandwichtop_no_arm_no_label']: restore_stack(_blk) return # Follow a fork @@ -438,7 +446,7 @@ def collapse_stack(top): for _blk in _group: if not _hit_bottom and _blk == _bot: _hit_bottom = True - # Replace 'sandwichbottom' shape with 'sandwichcollapsed' shape + # Replace 'sandwichbottom' shape with 'sandwichcollapsed' shape if len(_blk.values) == 0: _blk.values.append(1) else: @@ -454,7 +462,7 @@ def collapse_stack(top): _blk.resize() _blk.spr.set_label(_('click to open')) _blk.resize() - # Redock to sandwich top in group + # Redock to sandwich top in group _you = find_sandwich_top(_blk) (_yx, _yy) = _you.spr.get_xy() _yd = _you.docks[len(_you.docks) - 1] @@ -462,7 +470,7 @@ def collapse_stack(top): _dx = _yx + _yd[2] - _blk.docks[0][2] - _bx _dy = _yy + _yd[3] - _blk.docks[0][3] - _by _blk.spr.move_relative((_dx, _dy)) - # Since the shapes have changed, the dock positions have too. + # Since the shapes have changed, the dock positions have too. _newdx = _blk.docks[1][2] _newdy = _blk.docks[1][3] _dx += _newdx - _olddx @@ -474,7 +482,10 @@ def collapse_stack(top): else: _blk.spr.move_relative((_dx, _dy)) # Remove 'sandwichtop' arm - top.name = 'sandwichtop2' + if top.name == 'sandwichtop': + top.name = 'sandwichtop_no_arm' + else: + top.name = 'sandwichtop_no_arm_no_label' top.refresh() def collapsed(blk): diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index 0e2aa76..14619f7 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -473,7 +473,7 @@ class TurtleArtWindow(): if collapsed(blk): collapse_stack(find_sandwich_top(blk)) for blk in blocks: - if blk.name == 'sandwichtop': + if blk.name in ['sandwichtop', 'sandwichtop_no_label']: grow_stack_arm(blk) # Resize the skins on some blocks: media content and Python @@ -1318,8 +1318,11 @@ class TurtleArtWindow(): # Remove turtles by dragging them onto the trash palette. if self._in_the_trash(tx, ty): + # If it is the default turtle, just recenter it. if k == self.default_turtle_name: self._move_turtle(0, 0) + self.canvas.heading = 0 + self.canvas.turn_turtle() else: self.selected_turtle.hide() self.turtles.remove_from_dict(k) @@ -1486,7 +1489,7 @@ class TurtleArtWindow(): # no longer have access to the group with the sandwich top # so check them all. for b in self.just_blocks(): - if b.name == 'sandwichtop': + if b.name in ['sandwichtop', 'sandwichtop_no_label']: if find_sandwich_bottom(b) is None: reset_stack_arm(b) gblk.refresh() -- cgit v0.9.1