From 52c1689ecef335d89c07f37b5a7387ad8f87b899 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 13 Feb 2010 15:13:53 +0000 Subject: added missing flow to forever block --- diff --git a/tablock.py b/tablock.py index e78b6ca..7d3ef3b 100644 --- a/tablock.py +++ b/tablock.py @@ -329,6 +329,8 @@ class Block: self._make_not_style(svg) elif self.name in FLOW_STYLE: self._make_flow_style(svg) + elif self.name in FLOW_STYLE_TAIL: + self._make_flow_style_tail(svg) elif self.name in FLOW_STYLE_1ARG: self._make_flow_style_1arg(svg) elif self.name in FLOW_STYLE_BOOLEAN: @@ -582,20 +584,24 @@ class Block: def _make_flow_style(self, svg): self.svg.expand(10+self.dx+self.ex, self.ey) self.svg.set_slot(True) + self.svg.set_tab(True) + self._make_basic_flow(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], '['], + ['flow', False, self.svg.docks[2][0], + self.svg.docks[2][1], ']']] + + def _make_flow_style_tail(self, svg): + self.svg.expand(10+self.dx+self.ex, self.ey) + self.svg.set_slot(True) self.svg.set_tab(False) self._make_basic_flow(svg) - # This is an ugly hack. - if self.name == 'forever': - 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], '['], - ['unavailable', False, 0, 0, ']']] - 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]]] + 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_flow_style_1arg(self, svg): self.svg.expand(self.dx+self.ex, self.ey) diff --git a/taconstants.py b/taconstants.py index a47909d..d607c37 100644 --- a/taconstants.py +++ b/taconstants.py @@ -185,7 +185,8 @@ NUMBER_STYLE_1STRARG = ['box'] COMPARE_STYLE = ['greater2', 'less2', 'equal2'] BOOLEAN_STYLE = ['and2', 'or2'] NOT_STYLE = ['not'] -FLOW_STYLE = ['forever', 'hspace'] +FLOW_STYLE = ['forever'] +FLOW_STYLE_TAIL = ['hspace'] FLOW_STYLE_1ARG = ['repeat'] FLOW_STYLE_BOOLEAN = ['if'] FLOW_STYLE_ELSE = ['ifelse'] @@ -638,6 +639,7 @@ DEFAULTS = { 'comment':[_('comment')], 'description':[None], 'fillscreen':[60, 80], + 'forever':[None, 'vspace'], 'forward':[100], 'hat':[_('action')], 'if':[None, None, 'vspace'], @@ -702,8 +704,8 @@ MEDIA_SHAPES = ['audiooff', 'audioon', 'audiosmall', OVERLAY_SHAPES = ['Cartesian', 'Cartesian_labeled', 'polar'] STATUS_SHAPES = ['status', 'info', 'nostack', 'noinput', 'emptyheap', - 'emptybox', 'nomedia', 'nocode', 'overflowerror', - 'syntaxerror', 'nofile', 'nojournal'] + 'emptybox', 'nomedia', 'nocode', 'overflowerror', 'negroot', + 'syntaxerror', 'nofile', 'nojournal', 'zerodivide'] # # Legacy names diff --git a/tawindow.py b/tawindow.py index 69ea594..3c21942 100644 --- a/tawindow.py +++ b/tawindow.py @@ -48,7 +48,7 @@ except ImportError: pass from taconstants import * -from talogo import LogoCode, stop_logo +from talogo import LogoCode, stop_logo, convert, str_to_num from tacanvas import TurtleGraphics from tablock import Blocks, Block from taturtle import Turtles, Turtle @@ -1307,13 +1307,16 @@ class TurtleArtWindow(): self._restore_stack(b) return # Follow a fork - if b.name in ['repeat', 'if', 'ifelse']: - top = self._find_sandwich_top_below(b.connections[2]) + if b.name in ['repeat', 'if', 'ifelse', 'forever']: + top = self._find_sandwich_top_below( + b.connections[len(b.connections)-2]) if top is not None: self._uncollapse_forks(top, True) if b.name == 'ifelse': - top = self._find_sandwich_top_below(b.connections[3]) - self._uncollapse_forks(top, True) + top = self._find_sandwich_top_below( + b.connections[len(b.connections)-3]) + if top is not None: + self._uncollapse_forks(top, True) b = b.connections[len(b.connections)-1] return @@ -1326,7 +1329,7 @@ class TurtleArtWindow(): while b is not None: if b.name in COLLAPSIBLE: return None - if b.name in ['repeat', 'if', 'ifelse']: + if b.name in ['repeat', 'if', 'ifelse', 'forever']: if blk != b.connections[len(b.connections)-1]: return None if b.name == 'sandwichtop': @@ -1621,16 +1624,34 @@ class TurtleArtWindow(): 'remainder2', 'string'] and\ b2.name in ['product2', 'minus2', 'sqrt', 'division2', 'random', 'remainder2', 'string']: - if b1.name == 'string' and len(b1.values[0]) != 1: - try: - float(b1.values[0]) - except ValueError: + if b1.name == 'string': + if type(convert(str_to_num(b1.values[0]),float)) is not float: return False - elif b2.name == 'string' and len(b2.values[0]) != 1: - try: - float(b2.values[0]) - except ValueError: + elif b2.name == 'string': + if type(convert(str_to_num(b2.values[0]),float)) is not float: return False + elif b1.name in ['greater2', 'less2'] and b2.name == 'string': + if d1 == 1 and b1.connections[2] is not None: + if b1.connections[2].name == 'number': + if type(convert(str_to_num(b2.values[0]),float))\ + is not float: + return False + elif d1 == 2 and b1.connections[1] is not None: + if b1.connections[1].name == 'number': + if type(convert(str_to_num(b2.values[0]),float))\ + is not float: + return False + elif b2.name in ['greater2', 'less2'] and b1.name == 'string': + if d1 == 1 and b2.connections[2] is not None: + if b2.connections[2].name == 'number': + if type(convert(str_to_num(b1.values[0]),float))\ + is not float: + return False + elif d1 == 2 and b2.connections[1] is not None: + if b2.connections[1].name == 'number': + if type(convert(str_to_num(b1.values[0]),float))\ + is not float: + return False return True """ -- cgit v0.9.1