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 --- 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: diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py index bb38b51..4398fcc 100644 --- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py +++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py @@ -454,6 +454,7 @@ make "tmp first :taheap\rmake "taheap butfirst :taheap\routput :tmp\rend\r') label=_('comment'), prim_name='comment', default=_('comment'), + string_or_number=True, help_string=_('places a comment in your code')) self.tw.lc.def_prim('comment', 1, lambda self, x: primitive_dictionary['print'](x, True)) @@ -463,6 +464,7 @@ make "tmp first :taheap\rmake "taheap butfirst :taheap\routput :tmp\rend\r') label=_('print'), prim_name='print', logo_command='label', + string_or_number=True, help_string=_('prints value in status block at \ bottom of the screen')) self.tw.lc.def_prim('print', 1, @@ -474,6 +476,7 @@ bottom of the screen')) label=[_('Python'), 'f(x)', 'x'], prim_name='myfunction', default=['x', 100], + string_or_number=True, help_string=_('a programmable block: used to add \ advanced single-variable math equations, e.g., sin(x)')) self.tw.lc.def_prim('myfunction', 2, @@ -486,6 +489,7 @@ advanced single-variable math equations, e.g., sin(x)')) label=[_('Python'), 'f(x,y)', ' '], prim_name='myfunction2', default=['x+y', 100, 100], + string_or_number=True, help_string=_('a programmable block: used to add \ advanced multi-variable math equations, e.g., sqrt(x*x+y*y)')) self.tw.lc.def_prim('myfunction2', 3, @@ -499,6 +503,7 @@ advanced multi-variable math equations, e.g., sqrt(x*x+y*y)')) label=[_('Python'), 'f(x,y,z)', ' '], prim_name='myfunction3', default=['x+y+z', 100, 100, 100], + string_or_number=True, help_string=_('a programmable block: used to add \ advanced multi-variable math equations, e.g., sin(x+y+z)')) self.tw.lc.def_prim('myfunction3', 4, @@ -510,6 +515,7 @@ advanced multi-variable math equations, e.g., sin(x+y+z)')) style='basic-style-var-arg', label=' ', prim_name='userdefined', + string_or_number=True, special_name=_('Python block'), default=100, help_string=_('runs code found in the tamyblock.py \ @@ -525,6 +531,7 @@ module found in the Journal')) style='basic-style-var-arg', label=' ', prim_name='userdefined2', + string_or_number=True, special_name=_('Python block'), default=[100, 100], help_string=_('runs code found in the tamyblock.py \ @@ -542,6 +549,7 @@ module found in the Journal')) prim_name='userdefined3', special_name=_('Python block'), default=[100, 100, 100], + string_or_number=True, help_string=_('runs code found in the tamyblock.py \ module found in the Journal')) self.tw.lc.def_prim('userdefined3', 3, @@ -574,6 +582,7 @@ module found in the Journal')) label=_('turtle'), prim_name='turtle', default=1, + string_or_number=True, help_string=_('chooses which turtle to command')) self.tw.lc.def_prim('turtle', 1, lambda self, x: self.tw.canvas.set_turtle(x)) @@ -633,6 +642,7 @@ click to open')) style='collapsible-top', label=_('top of stack'), default=_('label'), + string_or_number=True, prim_name='comment', help_string=_('top of stack')) @@ -643,6 +653,7 @@ click to open')) label=_('top of a collapsible stack'), default=_('label'), prim_name='comment', + string_or_number=True, help_string=_('top of stack')) def _portfolio_palette(self): @@ -685,6 +696,7 @@ templates'), colors=["#0606FF", "#0606A0"], style='bullet-style', label=_('list'), + string_or_number=True, prim_name='bulletlist', default=['∙ ', '∙ '], help_string=_('presentation bulleted list')) @@ -848,6 +860,7 @@ Journal objects')) prim_name='t1x1', default=[_('Title'), 'None'], special_name=_('presentation 1x1'), + string_or_number=True, help_string=_('presentation template: select \ Journal object (with description)')) self.tw.lc.def_prim('t1x1', 2, @@ -862,6 +875,7 @@ Journal object (with description)')) prim_name='t1x1a', default=[_('Title'), 'None'], special_name=_('presentation 1x1'), + string_or_number=True, help_string=_('presentation template: select \ Journal object (no description)')) self.tw.lc.def_prim('t1x1a', 2, @@ -876,6 +890,7 @@ Journal object (no description)')) prim_name='t2x1', default=[_('Title'), 'None', 'None'], special_name=_('presentation 2x1'), + string_or_number=True, help_string=_("presentation template: select two \ Journal objects")) self.tw.lc.def_prim('t2x1', 3, @@ -890,6 +905,7 @@ Journal objects")) prim_name='t1x2', default=[_('Title'), 'None', 'None'], special_name=_('presentation 1x2'), + string_or_number=True, help_string=_("presentation template: select two \ Journal objects")) self.tw.lc.def_prim('t1x2', 3, @@ -904,6 +920,7 @@ Journal objects")) prim_name='t2x2', default=[_('Title'), 'None', 'None', 'None', 'None'], special_name=_('presentation 2x2'), + string_or_number=True, help_string=_("presentation template: select four \ Journal objects")) self.tw.lc.def_prim('t2x2', 5, @@ -918,6 +935,7 @@ Journal objects")) prim_name='bullet', default=[_('Title'), '∙ '], special_name=_('presentation bulleted list'), + string_or_number=True, help_string=_('presentation template: list of \ bullets')) self.tw.lc.def_prim('bullet', 1, self._prim_list, True) -- cgit v0.9.1