diff options
author | Marion <marion.zepf@gmail.com> | 2013-09-08 14:27:14 (GMT) |
---|---|---|
committer | Marion <marion.zepf@gmail.com> | 2013-09-08 14:27:14 (GMT) |
commit | bcba63272831cc383cc13fb4ce91651797f34eb1 (patch) | |
tree | adaff4241db9d28829371b9d8bc19b4fb5db8006 | |
parent | dfebf0be36908618c3b23839557dea93810b1198 (diff) |
make generation of color blocks a bit more generic and uniform
-rw-r--r-- | TurtleArt/tabasics.py | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py index d84b169..9522af0 100644 --- a/TurtleArt/tabasics.py +++ b/TurtleArt/tabasics.py @@ -526,18 +526,10 @@ pensize\nend\n') colors=["#00FFFF", "#00A0A0"], help_string=_('Palette of pen colors')) - self._make_constant(palette, 'red', _('red'), CONSTANTS['red']) - self._make_constant(palette, 'orange', _('orange'), - CONSTANTS['orange']) - self._make_constant(palette, 'yellow', _('yellow'), - CONSTANTS['yellow']) - self._make_constant(palette, 'green', _('green'), CONSTANTS['green']) - self._make_constant(palette, 'cyan', _('cyan'), CONSTANTS['cyan']) - self._make_constant(palette, 'blue', _('blue'), CONSTANTS['blue']) - self._make_constant(palette, 'purple', _('purple'), - CONSTANTS['purple']) - self._make_constant(palette, 'white', _('white'), CONSTANTS['white']) - self._make_constant(palette, 'black', _('black'), CONSTANTS['black']) + color_names = ('red', 'orange', 'yellow', 'green', 'cyan', 'blue', + 'purple', 'white', 'black') + for name in color_names: + self._make_constant(palette, name, _(name), name) # In order to map Turtle Art colors to the standard UCB Logo palette, # we need to define a somewhat complex set of functions. @@ -1406,21 +1398,24 @@ variable')) else: raise logoerror("#syntaxerror") - def _make_constant(self, palette, block_name, label, constant): + def _make_constant(self, palette, block_name, label, constant_key): ''' Factory for constant blocks ''' + constant = CONSTANTS[constant_key] if isinstance(constant, Color): if constant.color is not None: - value = str(constant.color) + logo_command = str(constant.color) else: # Black or White - value = '0 tasetshade %d' % (constant.shade) + logo_command = '0 tasetshade %d' % (constant.shade) + return_type = TYPE_COLOR else: - value = constant + logo_command = constant + return_type = TYPE_NUMBER palette.add_block(block_name, style='box-style', label=label, prim_name=block_name, - logo_command=value) + logo_command=logo_command) self.tw.lc.def_prim(block_name, 0, - Primitive(CONSTANTS.get, return_type=TYPE_COLOR, - arg_descs=[ConstantArg(str(constant))])) + Primitive(CONSTANTS.get, return_type=return_type, + arg_descs=[ConstantArg(constant_key)])) |