From 963f3ff3810877b02eee65a9d50155cdb3ccf7ae Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Wed, 10 Feb 2010 17:57:11 +0000 Subject: cleaning up collapsible block details --- diff --git a/tablock.py b/tablock.py index a07f348..3c998e6 100644 --- a/tablock.py +++ b/tablock.py @@ -124,8 +124,9 @@ class Block: # We need to resize some blocks on the fly so that the labels fit. def resize(self): - self._dx += (self.spr.label_width()-self.spr.label_safe_width()) - if self._dx != 0: + dx = (self.spr.label_width()-self.spr.label_safe_width())/self.scale + if dx !=0: + self._dx += dx if self._dx < 0: self._dx = 0 self.refresh() diff --git a/taconstants.py b/taconstants.py index 10f90b0..1ae34df 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'] + 'fullscreen', 'sandwichcollapsed'] BASIC_STYLE_1ARG = ['forward', 'back', 'left', 'right', 'seth', 'show', 'setscale', 'setpensize', 'setcolor', 'setshade', 'print', 'showaligned', 'settextsize', 'settextcolor', 'print', 'wait', 'storeinbox1', 'savepix', @@ -359,7 +359,7 @@ EXPANDABLE = ['vspace', 'hspace', 'templatelist', 'list', 'identity2', 'myfunc'] # # Blocks that are 'collapsible' # -COLLAPSIBLE = ['sandwichbottom'] +COLLAPSIBLE = ['sandwichbottom', 'sandwichcollapsed'] # # Depreciated block styles that need dock adjustments @@ -451,8 +451,9 @@ BLOCK_NAMES = { 'rightx':[_('picture right')], 'savepix':[_('save picture')], 'scale':[_('scale')], - 'sandwichtop':['top of stack'], 'sandwichbottom':[''], + 'sandwichcollapsed':[_('click to open')], + 'sandwichtop':['top of stack'], 'setcolor':[_('set color')], 'seth':[_('set heading')], 'setpensize':[_('set pen size')], diff --git a/tasprite_factory.py b/tasprite_factory.py index 709c212..deddf83 100755 --- a/tasprite_factory.py +++ b/tasprite_factory.py @@ -356,11 +356,14 @@ class SVG: def sandwich_top(self): x = self._stroke_width/2.0 y = self._stroke_width/2.0+self._radius + self.margins[0] = int(x+self._stroke_width+0.5) + self.margins[1] = int(self._stroke_width+0.5) + self.margins[2] = 0 + self.margins[3] = 0 svg = self._new_path(x, y) 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) @@ -368,10 +371,6 @@ class SVG: 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) @@ -385,6 +384,10 @@ class SVG: def sandwich_bottom(self): x = self._stroke_width/2.0 y = self._stroke_width/2.0 + self.margins[0] = int(self._stroke_width+0.5) + self.margins[1] = int(self._stroke_width+0.5) + self.margins[2] = 0 + self.margins[3] = 0 svg = self._new_path(x, y) svg += self._rline_to(self._radius, 0) svg += self._rline_to(0, self._expand_y) diff --git a/tawindow.py b/tawindow.py index 500da15..baeb042 100644 --- a/tawindow.py +++ b/tawindow.py @@ -1163,6 +1163,8 @@ class TurtleArtWindow(): elif self._show_button_hit(blk.spr, x, y): dy = 20 blk.expand_in_y(dy) + else: + dy = 0 for b in group: if b != blk: b.spr.move_relative((0, dy*blk.scale)) @@ -1195,7 +1197,7 @@ class TurtleArtWindow(): blk.connections[n-1] = argblk else: self._run_stack(blk) - elif blk.name=='sandwichbottom': + elif blk.name in COLLAPSIBLE: if self._hide_button_hit(blk.spr, x, y): top = self._find_sandwich_top(blk) if top is not None: @@ -1228,7 +1230,7 @@ class TurtleArtWindow(): # TODO: Add nesting; detect branches (e.g., if, ifelse, repeat) b = blk.connections[0] while b is not None: - if b.name == 'sandwichbottom': + if b.name in COLLAPSIBLE: return b b = b.connections[0] return None @@ -1247,6 +1249,14 @@ class TurtleArtWindow(): b.values.append(dy) else: b.values[0] = dy + b.name = 'sandwichcollapsed' + b.svg.set_show(True) + b.svg.set_hide(False) + dx = b.docks[0][2] + b._dx = 0 + b.spr.set_label(_('click to open')) + b.resize() + b.spr.move_relative((dx-b.docks[0][2],0)) if dy == 0: b.spr.set_layer(HIDE_LAYER) b.status = 'collapsed' @@ -1260,6 +1270,20 @@ class TurtleArtWindow(): if b.name in COLLAPSIBLE: dy = b.values[0] b.values[0] = 0 + b.name = 'sandwichbottom' + b.spr.set_label(' ') + b.svg.set_show(False) + b.svg.set_hide(True) + dx = b.docks[0][2] + b.refresh() + b.spr.move_relative((dx-b.docks[0][2],0)) + ''' + #TODO: grow left edge of the sandwich along the stack + # this will connect the bottom to the top... + b.expand_in_y(-dy/self.block_scale) + b.refresh() + b.spr.move_relative((0,dy)) + ''' if dy == 0: b.spr.set_layer(BLOCK_LAYER) b.status = None @@ -1830,7 +1854,6 @@ class TurtleArtWindow(): self.canvas.setshade(shade) self.canvas.setpensize(pensize) - # TODO: handle collapsed blocks """ Restore individual blocks from saved state """ -- cgit v0.9.1