From 26e31f351f2b0cda8c0b24741cc93ff8ec542c7d Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Mon, 07 May 2012 12:31:22 +0000 Subject: move string_or_number whitelist to taplatte.py --- (limited to 'TurtleArt') diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py index c381f79..7d43144 100644 --- a/TurtleArt/tabasics.py +++ b/TurtleArt/tabasics.py @@ -544,6 +544,7 @@ tasetshade :shade \r') style='number-style', label='+', special_name=_('plus'), + string_or_number=True, prim_name='plus', logo_command='sum', help_string=_('adds two alphanumeric inputs')) @@ -649,6 +650,7 @@ operators')) palette.add_block('greater2', style='compare-porch-style', label='>', + string_or_number=True, special_name=_('greater than'), prim_name='greater?', logo_command='greater?', @@ -665,6 +667,7 @@ operators')) style='compare-porch-style', label='<', special_name=_('less than'), + string_or_number=True, prim_name='less?', logo_command='less?', help_string=_('logical less-than operator')) @@ -679,6 +682,7 @@ operators')) style='compare-style', label='=', special_name=_('equal'), + string_or_number=True, prim_name='equal?', logo_command='equal?', help_string=_('logical equal-to operator')) @@ -875,6 +879,7 @@ buttons')) palette.add_block('box', style='number-style-1strarg', label=_('box'), + string_or_number=True, prim_name='box', default=_('my box'), logo_command='box', @@ -885,6 +890,7 @@ buttons')) palette.add_block('storein', style='basic-style-2arg', label=[_('store in'), _('box'), _('value')], + string_or_number=True, prim_name='storeinbox', logo_command='storeinbox', default=[_('my box'), 100], @@ -898,6 +904,7 @@ variable')) style='basic-style-head-1arg', label=_('action'), prim_name='nop3', + string_or_number=True, default=_('action'), logo_command='to action', help_string=_('top of nameable action stack')) @@ -923,6 +930,7 @@ variable')) palette.add_block('stack', style='basic-style-1arg', label=_('action'), + string_or_number=True, prim_name='stack', logo_command='action', default=_('action'), diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py index 0cfb242..7a82a42 100644 --- a/TurtleArt/taconstants.py +++ b/TurtleArt/taconstants.py @@ -104,17 +104,6 @@ COLLAPSIBLE = ['sandwichbottom', 'sandwichcollapsed'] # OLD_DOCK = ['and', 'or', 'plus', 'minus', 'division', 'product', 'remainder'] -# -# Blocks that can interchange strings and numbers for their arguments -# -STRING_OR_NUMBER_ARGS = ['plus2', 'equal2', 'less2', 'greater2', 'box', - 'template1x1', 'template1x2', 'template2x1', 'list', - 'template2x2', 'template1x1a', 'templatelist', 'nop', - 'print', 'stack', 'hat', 'addturtle', 'myfunc', - 'myfunc1arg', 'myfunc2arg', 'myfunc3arg', 'comment', - 'sandwichtop', 'sandwichtop_no_arm', 'userdefined', - 'userdefined2args', 'userdefined3args', 'storein'] - CONTENT_ARGS = ['show', 'showaligned', 'push', 'storein', 'storeinbox1', 'storeinbox2'] diff --git a/TurtleArt/tapalette.py b/TurtleArt/tapalette.py index 7678f7e..ad96103 100644 --- a/TurtleArt/tapalette.py +++ b/TurtleArt/tapalette.py @@ -36,6 +36,7 @@ content_blocks = ['number', 'string', 'description', 'audio', 'video', hidden_proto_blocks = [] # proto blocks that are (at least initially) hidden value_blocks = [] # blocks whose labels are updated get added here special_block_colors = {} +string_or_number_args = [] block_styles = {'basic-style': [], 'blank-style': [], 'basic-style-head': [], @@ -164,7 +165,8 @@ class Palette(): def add_block(self, block_name, style='basic-block', label=None, special_name=None, default=None, prim_name=None, help_string=None, value_block=False, content_block=False, - logo_command=None, hidden=False, colors=None): + logo_command=None, hidden=False, colors=None, + string_or_number=False): """ Add a new block to the palette """ block = Block(block_name) block.set_style(style) @@ -199,6 +201,8 @@ class Palette(): help_string)) if colors is not None: block.set_colors(colors) + if string_or_number: + block.set_string_or_number() block.set_value_block(value_block) block.set_content_block(content_block) block.set_palette(self._name) @@ -250,6 +254,7 @@ class Block(): self._content_block = False self._colors = None self._hidden = False + self._string_or_number = False def add_block(self, position=None): if self._name is None: @@ -313,6 +318,9 @@ class Block(): if self._colors is not None: special_block_colors[self._name] = self._colors + if self._string_or_number: + string_or_number_args.append(self._name) + if self._hidden: hidden_proto_blocks.append(self._name) @@ -322,6 +330,9 @@ class Block(): def set_colors(self, colors=None): self._colors = colors + def set_string_or_number(self, flag=True): + self._string_or_number = flag + def set_value_block(self, value=True): self._value_block = value diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index 14742c8..b7523e5 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -44,7 +44,7 @@ DEGTOR = 2 * pi / 360 import locale from taconstants import HORIZONTAL_PALETTE, VERTICAL_PALETTE, BLOCK_SCALE, \ - MEDIA_SHAPES, STATUS_SHAPES, OVERLAY_SHAPES, STRING_OR_NUMBER_ARGS, \ + MEDIA_SHAPES, STATUS_SHAPES, OVERLAY_SHAPES, \ TOOLBAR_SHAPES, TAB_LAYER, RETURN, OVERLAY_LAYER, CATEGORY_LAYER, \ BLOCKS_WITH_SKIN, ICON_SIZE, PALETTE_SCALE, PALETTE_WIDTH, SKIN_PATHS, \ MACROS, TOP_LAYER, BLOCK_LAYER, OLD_NAMES, DEFAULT_TURTLE, TURTLE_LAYER, \ @@ -54,7 +54,7 @@ from taconstants import HORIZONTAL_PALETTE, VERTICAL_PALETTE, BLOCK_SCALE, \ CONSTANTS, EXPAND_SKIN, PROTO_LAYER from tapalette import palette_names, palette_blocks, expandable_blocks, \ block_names, content_blocks, default_values, special_names, block_styles, \ - help_strings, hidden_proto_blocks + help_strings, hidden_proto_blocks, string_or_number_args from talogo import LogoCode from tacanvas import TurtleGraphics from tablock import Blocks, Block @@ -3409,7 +3409,7 @@ def dock_dx_dy(block1, dock1n, block2, dock2n): block2.connections[dock2n] is not None: return (100, 100) if _d1type != _d2type: - if block1.name in STRING_OR_NUMBER_ARGS: + if block1.name in string_or_number_args: if _d2type == 'number' or _d2type == 'string': pass elif block1.name in CONTENT_ARGS: -- cgit v0.9.1